Skip to content

Commit 5d29240

Browse files
committed
Crypto: OperationStep overhaul to account for errors and missing interproc flow.
1 parent b7ceeb3 commit 5d29240

18 files changed

+205
-185
lines changed

cpp/ql/lib/experimental/quantum/Language.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ module CryptoInput implements InputSig<Language::Location> {
1414
result = node.asExpr() or
1515
result = node.asParameter() or
1616
result = node.asVariable() or
17-
result = node.asDefiningArgument()
18-
// TODO: do we need asIndirectExpr()?
17+
result = node.asDefiningArgument() or
18+
result = node.asIndirectExpr()
1919
}
2020

2121
string locationToFileBaseNameAndLineNumberString(Location location) {
@@ -93,7 +93,10 @@ module GenericDataSourceFlow = TaintTracking::Global<GenericDataSourceFlowConfig
9393

9494
private class ConstantDataSource extends Crypto::GenericConstantSourceInstance instanceof OpenSslGenericSourceCandidateLiteral
9595
{
96-
override DataFlow::Node getOutputNode() { result.asExpr() = this }
96+
override DataFlow::Node getOutputNode() {
97+
// A literal can be a string or an int, so handling both indirect and direct cases
98+
[result.asIndirectExpr(), result.asExpr()] = this
99+
}
97100

98101
override predicate flowsTo(Crypto::FlowAwareElement other) {
99102
// TODO: separate config to avoid blowing up data-flow analysis

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/CipherAlgorithmValueConsumer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class EvpCipherAlgorithmValueConsumer extends CipherAlgorithmValueConsumer {
1212
DataFlow::Node resultNode;
1313

1414
EvpCipherAlgorithmValueConsumer() {
15-
resultNode.asExpr() = this and
15+
resultNode.asIndirectExpr() = this and
1616
(
1717
this.(Call).getTarget().getName() in [
1818
"EVP_get_cipherbyname", "EVP_get_cipherbyobj", "EVP_get_cipherbynid"

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/DirectAlgorithmValueConsumer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DirectAlgorithmValueConsumer extends OpenSslAlgorithmValueConsumer instanc
2323
*/
2424
override DataFlow::Node getResultNode() {
2525
this instanceof OpenSslDirectAlgorithmFetchCall and
26-
result.asExpr() = this
26+
result.asIndirectExpr() = this
2727
// NOTE: if instanceof OpenSslDirectAlgorithmOperationCall then there is no algorithm generated
2828
// the algorithm is directly used
2929
}

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/EllipticCurveAlgorithmValueConsumer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class EvpEllipticCurveAlgorithmConsumer extends EllipticCurveValueConsumer {
1212
DataFlow::Node resultNode;
1313

1414
EvpEllipticCurveAlgorithmConsumer() {
15-
resultNode.asExpr() = this.(Call) and // in all cases the result is the return
15+
resultNode.asIndirectExpr() = this.(Call) and // in all cases the result is the return
1616
(
1717
this.(Call).getTarget().getName() in ["EVP_EC_gen", "EC_KEY_new_by_curve_name"] and
1818
valueArgNode.asExpr() = this.(Call).getArgument(0)

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/HashAlgorithmValueConsumer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class EvpDigestAlgorithmValueConsumer extends HashAlgorithmValueConsumer {
6464
DataFlow::Node resultNode;
6565

6666
EvpDigestAlgorithmValueConsumer() {
67-
resultNode.asExpr() = this and
67+
resultNode.asIndirectExpr() = this and
6868
(
6969
this.(Call).getTarget().getName() in [
7070
"EVP_get_digestbyname", "EVP_get_digestbynid", "EVP_get_digestbyobj"

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/KEMAlgorithmValueConsumer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class EvpKemAlgorithmValueConsumer extends KemAlgorithmValueConsumer {
1111
DataFlow::Node resultNode;
1212

1313
EvpKemAlgorithmValueConsumer() {
14-
resultNode.asExpr() = this and
14+
resultNode.asIndirectExpr() = this and
1515
(
1616
this.(Call).getTarget().getName() = "EVP_KEM_fetch" and
1717
valueArgNode.asExpr() = this.(Call).getArgument(1)

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/KeyExchangeAlgorithmValueConsumer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class EvpKeyExchangeAlgorithmValueConsumer extends KeyExchangeAlgorithmValueCons
1111
DataFlow::Node resultNode;
1212

1313
EvpKeyExchangeAlgorithmValueConsumer() {
14-
resultNode.asExpr() = this and
14+
resultNode.asIndirectExpr() = this and
1515
(
1616
this.(Call).getTarget().getName() = "EVP_KEYEXCH_fetch" and
1717
valueArgNode.asExpr() = this.(Call).getArgument(1)

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/PKeyAlgorithmValueConsumer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class EvpPKeyAlgorithmConsumer extends PKeyValueConsumer {
1111
DataFlow::Node resultNode;
1212

1313
EvpPKeyAlgorithmConsumer() {
14-
resultNode.asExpr() = this.(Call) and // in all cases the result is the return
14+
resultNode.asIndirectExpr() = this.(Call) and // in all cases the result is the return
1515
(
1616
// NOTE: some of these consumers are themselves key gen operations,
1717
// in these cases, the operation will be created separately for the same function.

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/PaddingAlgorithmValueConsumer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Evp_PKey_Ctx_set_rsa_padding_AlgorithmValueConsumer extends PaddingAlgorit
1414
DataFlow::Node resultNode;
1515

1616
Evp_PKey_Ctx_set_rsa_padding_AlgorithmValueConsumer() {
17-
resultNode.asExpr() = this.(Call).getArgument(0) and
17+
resultNode.asDefiningArgument() = this.(Call).getArgument(0) and
1818
this.(Call).getTarget().getName() = "EVP_PKEY_CTX_set_rsa_padding" and
1919
valueArgNode.asExpr() = this.(Call).getArgument(1)
2020
}

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/SignatureAlgorithmValueConsumer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class EvpSignatureAlgorithmValueConsumer extends SignatureAlgorithmValueConsumer
1212
DataFlow::Node resultNode;
1313

1414
EvpSignatureAlgorithmValueConsumer() {
15-
resultNode.asExpr() = this and
15+
resultNode.asIndirectExpr() = this and
1616
(
1717
// EVP_SIGNATURE
1818
this.(Call).getTarget().getName() = "EVP_SIGNATURE_fetch" and

0 commit comments

Comments
 (0)