Skip to content

Commit 5694f02

Browse files
committed
Misc. cleanup
1 parent c80588c commit 5694f02

File tree

3 files changed

+53
-314
lines changed

3 files changed

+53
-314
lines changed
Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
private import codeql.cryptography.Model
22
import semmle.code.cpp.ir.IR
33
import semmle.code.cpp.security.FlowSources as FlowSources
4+
import semmle.code.cpp.dataflow.new.DataFlow
45
private import cpp as Lang
56

67
module CryptoInput implements InputSig<Lang::Location> {
@@ -15,10 +16,44 @@ module CryptoInput implements InputSig<Lang::Location> {
1516
result = node.asParameter() or
1617
result = node.asVariable()
1718
}
19+
20+
string locationToFileBaseNameAndLineNumberString(Location location) {
21+
result = location.getFile().getBaseName() + ":" + location.getStartLine()
22+
}
23+
24+
predicate artifactOutputFlowsToGenericInput(
25+
DataFlow::Node artifactOutput, DataFlow::Node otherInput
26+
) {
27+
ArtifactFlow::flow(artifactOutput, otherInput)
28+
}
1829
}
1930

2031
module Crypto = CryptographyBase<Lang::Location, CryptoInput>;
2132

33+
module ArtifactFlowConfig implements DataFlow::ConfigSig {
34+
predicate isSource(DataFlow::Node source) {
35+
source = any(Crypto::ArtifactInstance artifact).getOutputNode()
36+
}
37+
38+
predicate isSink(DataFlow::Node sink) {
39+
sink = any(Crypto::FlowAwareElement other).getInputNode()
40+
}
41+
42+
predicate isBarrierOut(DataFlow::Node node) {
43+
node = any(Crypto::FlowAwareElement element).getInputNode()
44+
}
45+
46+
predicate isBarrierIn(DataFlow::Node node) {
47+
node = any(Crypto::FlowAwareElement element).getOutputNode()
48+
}
49+
50+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
51+
node1.(AdditionalFlowInputStep).getOutput() = node2
52+
}
53+
}
54+
55+
module ArtifactFlow = DataFlow::Global<ArtifactFlowConfig>;
56+
2257
/**
2358
* Artifact output to node input configuration
2459
*/
@@ -31,9 +66,9 @@ abstract class AdditionalFlowInputStep extends DataFlow::Node {
3166
/**
3267
* Generic data source to node input configuration
3368
*/
34-
module GenericDataSourceUniversalFlowConfig implements DataFlow::ConfigSig {
69+
module GenericDataSourceFlowConfig implements DataFlow::ConfigSig {
3570
predicate isSource(DataFlow::Node source) {
36-
source = any(Crypto::GenericDataSourceInstance i).getOutputNode()
71+
source = any(Crypto::GenericSourceInstance i).getOutputNode()
3772
}
3873

3974
predicate isSink(DataFlow::Node sink) {
@@ -53,41 +88,6 @@ module GenericDataSourceUniversalFlowConfig implements DataFlow::ConfigSig {
5388
}
5489
}
5590

56-
// // // TODO: I think this will be inefficient, no?
57-
// // class ConstantDataSource extends Crypto::GenericConstantOrAllocationSource instanceof Literal {
58-
// // override DataFlow::Node getOutputNode() {
59-
// // result.asExpr() = this
60-
// // }
61-
// // override predicate flowsTo(Crypto::FlowAwareElement other) {
62-
// // // TODO: separate config to avoid blowing up data-flow analysis
63-
// // GenericDataSourceUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
64-
// // }
65-
// // override string getAdditionalDescription() { result = this.toString() }
66-
// // }
67-
// /**
68-
// * Definitions of various generic data sources
69-
// */
70-
// // final class DefaultFlowSource = SourceNode;
71-
// // final class DefaultRemoteFlowSource = RemoteFlowSource;
72-
// // class GenericLocalDataSource extends Crypto::GenericLocalDataSource {
73-
// // GenericLocalDataSource() {
74-
// // any(DefaultFlowSource src | not src instanceof DefaultRemoteFlowSource).asExpr() = this
75-
// // }
76-
// // override DataFlow::Node getOutputNode() { result.asExpr() = this }
77-
// // override predicate flowsTo(Crypto::FlowAwareElement other) {
78-
// // GenericDataSourceUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
79-
// // }
80-
// // override string getAdditionalDescription() { result = this.toString() }
81-
// // }
82-
// // class GenericRemoteDataSource extends Crypto::GenericRemoteDataSource {
83-
// // GenericRemoteDataSource() { any(DefaultRemoteFlowSource src).asExpr() = this }
84-
// // override DataFlow::Node getOutputNode() { result.asExpr() = this }
85-
// // override predicate flowsTo(Crypto::FlowAwareElement other) {
86-
// // GenericDataSourceUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
87-
// // }
88-
// // override string getAdditionalDescription() { result = this.toString() }
89-
// // }
90-
// module GenericDataSourceUniversalFlow = DataFlow::Global<GenericDataSourceUniversalFlowConfig>;
9191
module ArtifactUniversalFlowConfig implements DataFlow::ConfigSig {
9292
predicate isSource(DataFlow::Node source) {
9393
source = any(Crypto::ArtifactInstance artifact).getOutputNode()
@@ -112,10 +112,12 @@ module ArtifactUniversalFlowConfig implements DataFlow::ConfigSig {
112112

113113
module ArtifactUniversalFlow = DataFlow::Global<ArtifactUniversalFlowConfig>;
114114

115-
abstract class CipherOutputArtifact extends Crypto::KeyOperationOutputArtifactInstance {
116-
override predicate flowsTo(Crypto::FlowAwareElement other) {
117-
ArtifactUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
118-
}
119-
}
120-
115+
// abstract class CipherOutputArtifact extends Crypto::KeyOperationOutputArtifactInstance {
116+
// override predicate flowsTo(Crypto::FlowAwareElement other) {
117+
// ArtifactUniversalFlow::flow(this.getOutputNode(), other.getInputNode())
118+
// }
119+
// }
120+
// // final override predicate flowsTo(FlowAwareElement other) {
121+
// // Input::artifactOutputFlowsToGenericInput(this.getOutputNode(), other.getInputNode())
122+
// // }
121123
import OpenSSL.OpenSSL

cpp/ql/lib/experimental/Quantum/OpenSSL/CtxFlow.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
//TODO: model as data on open APIs should be able to get common flows, and obviate some of this
2+
// e.g., copy/dup calls, need to ingest those models for openSSL and refactor.
13
/**
24
* In OpenSSL, flow between 'context' parameters is often used to
35
* store state/config of how an operation will eventually be performed.
46
* Tracing algorithms and configurations to operations therefore
5-
* requires tracing context parameters for many OpenSSL apis.
6-
*
7+
* requires tracing context parameters for many OpenSSL apis.
8+
*
79
* This library provides a dataflow analysis to track context parameters
810
* between any two functions accepting openssl context parameters.
911
* The dataflow takes into consideration flowing through duplication and copy calls
@@ -88,7 +90,7 @@ module OpenSSLCTXArgumentFlowConfig implements DataFlow::ConfigSig {
8890

8991
module OpenSSLCTXArgumentFlow = DataFlow::Global<OpenSSLCTXArgumentFlowConfig>;
9092

91-
predicate ctxFlowsTo(CTXPointerArgument source, CTXPointerArgument sink) {
93+
predicate ctxArgFlowsToCtxArg(CTXPointerArgument source, CTXPointerArgument sink) {
9294
exists(DataFlow::Node a, DataFlow::Node b |
9395
OpenSSLCTXArgumentFlow::flow(a, b) and
9496
a.asExpr() = source and

0 commit comments

Comments
 (0)