Skip to content

Commit 7458674

Browse files
authored
Merge pull request #21584 from owen-mc/shared/update-mad-comments
Shared: update code comments explaining models-as-data format to include barriers and barrier guards
2 parents 0724c22 + 37aac05 commit 7458674

File tree

23 files changed

+206
-134
lines changed

23 files changed

+206
-134
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
*
77
* The extensible relations have the following columns:
88
* - Sources:
9-
* `namespace; type; subtypes; name; signature; ext; output; kind`
9+
* `namespace; type; subtypes; name; signature; ext; output; kind; provenance`
1010
* - Sinks:
11-
* `namespace; type; subtypes; name; signature; ext; input; kind`
11+
* `namespace; type; subtypes; name; signature; ext; input; kind; provenance`
1212
* - Summaries:
13-
* `namespace; type; subtypes; name; signature; ext; input; output; kind`
13+
* `namespace; type; subtypes; name; signature; ext; input; output; kind; provenance`
14+
* - Barriers:
15+
* `namespace; type; subtypes; name; signature; ext; output; kind; provenance`
16+
* - BarrierGuards:
17+
* `namespace; type; subtypes; name; signature; ext; input; acceptingValue; kind; provenance`
1418
*
1519
* The interpretation of a row is similar to API-graphs with a left-to-right
1620
* reading.
@@ -87,11 +91,23 @@
8791
* value, and
8892
* - flow from the _second_ indirection of the 0th argument to the first
8993
* indirection of the return value, etc.
90-
* 8. The `kind` column is a tag that can be referenced from QL to determine to
94+
* 8. The `acceptingValue` column of barrier guard models specifies the condition
95+
* under which the guard blocks flow. It can be one of "true" or "false". In
96+
* the future "no-exception", "not-zero", "null", "not-null" may be supported.
97+
* 9. The `kind` column is a tag that can be referenced from QL to determine to
9198
* which classes the interpreted elements should be added. For example, for
9299
* sources "remote" indicates a default remote flow source, and for summaries
93100
* "taint" indicates a default additional taint step and "value" indicates a
94101
* globally applicable value-preserving step.
102+
* 10. The `provenance` column is a tag to indicate the origin and verification of a model.
103+
* The format is {origin}-{verification} or just "manual" where the origin describes
104+
* the origin of the model and verification describes how the model has been verified.
105+
* Some examples are:
106+
* - "df-generated": The model has been generated by the model generator tool.
107+
* - "df-manual": The model has been generated by the model generator and verified by a human.
108+
* - "manual": The model has been written by hand.
109+
* This information is used in a heuristic for dataflow analysis to determine, if a
110+
* model or source code should be used for determining flow.
95111
*/
96112

97113
import cpp
@@ -931,13 +947,13 @@ private module Cached {
931947

932948
private predicate barrierGuardChecks(IRGuardCondition g, Expr e, boolean gv, TKindModelPair kmp) {
933949
exists(
934-
SourceSinkInterpretationInput::InterpretNode n, Public::AcceptingValue acceptingvalue,
950+
SourceSinkInterpretationInput::InterpretNode n, Public::AcceptingValue acceptingValue,
935951
string kind, string model
936952
|
937-
isBarrierGuardNode(n, acceptingvalue, kind, model) and
953+
isBarrierGuardNode(n, acceptingValue, kind, model) and
938954
n.asNode().asExpr() = e and
939955
kmp = TMkPair(kind, model) and
940-
gv = convertAcceptingValue(acceptingvalue).asBooleanValue() and
956+
gv = convertAcceptingValue(acceptingValue).asBooleanValue() and
941957
n.asNode().(Private::ArgumentNode).getCall().asCallInstruction() = g
942958
)
943959
}
@@ -954,14 +970,14 @@ private module Cached {
954970
) {
955971
exists(
956972
SourceSinkInterpretationInput::InterpretNode interpretNode,
957-
Public::AcceptingValue acceptingvalue, string kind, string model, int indirectionIndex,
973+
Public::AcceptingValue acceptingValue, string kind, string model, int indirectionIndex,
958974
Private::ArgumentNode arg
959975
|
960-
isBarrierGuardNode(interpretNode, acceptingvalue, kind, model) and
976+
isBarrierGuardNode(interpretNode, acceptingValue, kind, model) and
961977
arg = interpretNode.asNode() and
962978
arg.asIndirectExpr(indirectionIndex) = e and
963979
kmp = MkKindModelPairIntPair(TMkPair(kind, model), indirectionIndex) and
964-
gv = convertAcceptingValue(acceptingvalue).asBooleanValue() and
980+
gv = convertAcceptingValue(acceptingValue).asBooleanValue() and
965981
arg.getCall().asCallInstruction() = g
966982
)
967983
}

cpp/ql/lib/semmle/code/cpp/dataflow/internal/ExternalFlowExtensions.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extensible predicate barrierModel(
3333
*/
3434
extensible predicate barrierGuardModel(
3535
string namespace, string type, boolean subtypes, string name, string signature, string ext,
36-
string input, string acceptingvalue, string kind, string provenance, QlBuiltins::ExtensionId madId
36+
string input, string acceptingValue, string kind, string provenance, QlBuiltins::ExtensionId madId
3737
);
3838

3939
/**

cpp/ql/lib/semmle/code/cpp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ module SourceSinkInterpretationInput implements
162162
}
163163

164164
predicate barrierGuardElement(
165-
Element e, string input, Public::AcceptingValue acceptingvalue, string kind,
165+
Element e, string input, Public::AcceptingValue acceptingValue, string kind,
166166
Public::Provenance provenance, string model
167167
) {
168168
exists(
169169
string package, string type, boolean subtypes, string name, string signature, string ext
170170
|
171-
barrierGuardModel(package, type, subtypes, name, signature, ext, input, acceptingvalue, kind,
171+
barrierGuardModel(package, type, subtypes, name, signature, ext, input, acceptingValue, kind,
172172
provenance, model) and
173173
e = interpretElement(package, type, subtypes, name, signature, ext)
174174
)

csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlow.qll

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
* Provides classes and predicates for dealing with MaD flow models specified
55
* in data extensions and CSV format.
66
*
7-
* The CSV specification has the following columns:
7+
* The extensible relations have the following columns:
88
* - Sources:
99
* `namespace; type; subtypes; name; signature; ext; output; kind; provenance`
1010
* - Sinks:
1111
* `namespace; type; subtypes; name; signature; ext; input; kind; provenance`
1212
* - Summaries:
1313
* `namespace; type; subtypes; name; signature; ext; input; output; kind; provenance`
14+
* - Barriers:
15+
* `namespace; type; subtypes; name; signature; ext; output; kind; provenance`
16+
* - BarrierGuards:
17+
* `namespace; type; subtypes; name; signature; ext; input; acceptingValue; kind; provenance`
1418
* - Neutrals:
1519
* `namespace; type; name; signature; kind; provenance`
1620
* A neutral is used to indicate that a callable is neutral with respect to flow (no summary), source (is not a source) or sink (is not a sink).
@@ -69,14 +73,17 @@
6973
* - "Field[f]": Selects the contents of field `f`.
7074
* - "Property[p]": Selects the contents of property `p`.
7175
*
72-
* 8. The `kind` column is a tag that can be referenced from QL to determine to
76+
* 8. The `acceptingValue` column of barrier guard models specifies the condition
77+
* under which the guard blocks flow. It can be one of "true" or "false". In
78+
* the future "no-exception", "not-zero", "null", "not-null" may be supported.
79+
* 9. The `kind` column is a tag that can be referenced from QL to determine to
7380
* which classes the interpreted elements should be added. For example, for
7481
* sources "remote" indicates a default remote flow source, and for summaries
7582
* "taint" indicates a default additional taint step and "value" indicates a
7683
* globally applicable value-preserving step. For neutrals the kind can be `summary`,
7784
* `source` or `sink` to indicate that the neutral is neutral with respect to
7885
* flow (no summary), source (is not a source) or sink (is not a sink).
79-
* 9. The `provenance` column is a tag to indicate the origin and verification of a model.
86+
* 10. The `provenance` column is a tag to indicate the origin and verification of a model.
8087
* The format is {origin}-{verification} or just "manual" where the origin describes
8188
* the origin of the model and verification describes how the model has been verified.
8289
* Some examples are:
@@ -230,11 +237,11 @@ module ModelValidation {
230237
result = "Unrecognized provenance description \"" + provenance + "\" in " + pred + " model."
231238
)
232239
or
233-
exists(string acceptingvalue |
234-
barrierGuardModel(_, _, _, _, _, _, _, acceptingvalue, _, _, _) and
235-
invalidAcceptingValue(acceptingvalue) and
240+
exists(string acceptingValue |
241+
barrierGuardModel(_, _, _, _, _, _, _, acceptingValue, _, _, _) and
242+
invalidAcceptingValue(acceptingValue) and
236243
result =
237-
"Unrecognized accepting value description \"" + acceptingvalue +
244+
"Unrecognized accepting value description \"" + acceptingValue +
238245
"\" in barrier guard model."
239246
)
240247
}
@@ -482,13 +489,13 @@ private module Cached {
482489

483490
private predicate barrierGuardChecks(Guard g, Expr e, GuardValue gv, TKindModelPair kmp) {
484491
exists(
485-
SourceSinkInterpretationInput::InterpretNode n, AcceptingValue acceptingvalue, string kind,
492+
SourceSinkInterpretationInput::InterpretNode n, AcceptingValue acceptingValue, string kind,
486493
string model
487494
|
488-
isBarrierGuardNode(n, acceptingvalue, kind, model) and
495+
isBarrierGuardNode(n, acceptingValue, kind, model) and
489496
n.asNode().asExpr() = e and
490497
kmp = TMkPair(kind, model) and
491-
gv = convertAcceptingValue(acceptingvalue)
498+
gv = convertAcceptingValue(acceptingValue)
492499
|
493500
g.(Call).getAnArgument() = e or g.(QualifiableExpr).getQualifier() = e
494501
)

csharp/ql/lib/semmle/code/csharp/dataflow/internal/ExternalFlowExtensions.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extensible predicate barrierModel(
3333
*/
3434
extensible predicate barrierGuardModel(
3535
string namespace, string type, boolean subtypes, string name, string signature, string ext,
36-
string input, string acceptingvalue, string kind, string provenance, QlBuiltins::ExtensionId madId
36+
string input, string acceptingValue, string kind, string provenance, QlBuiltins::ExtensionId madId
3737
);
3838

3939
/**

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,13 @@ module SourceSinkInterpretationInput implements
253253
}
254254

255255
predicate barrierGuardElement(
256-
Element e, string input, Public::AcceptingValue acceptingvalue, string kind,
256+
Element e, string input, Public::AcceptingValue acceptingValue, string kind,
257257
Public::Provenance provenance, string model
258258
) {
259259
exists(
260260
string namespace, string type, boolean subtypes, string name, string signature, string ext
261261
|
262-
barrierGuardModel(namespace, type, subtypes, name, signature, ext, input, acceptingvalue,
262+
barrierGuardModel(namespace, type, subtypes, name, signature, ext, input, acceptingValue,
263263
kind, provenance, model) and
264264
e = interpretElement(namespace, type, subtypes, name, signature, ext, _)
265265
)

go/ql/lib/semmle/go/dataflow/ExternalFlow.qll

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
* Provides classes and predicates for dealing with flow models specified
55
* in data extensions and CSV format.
66
*
7-
* The CSV specification has the following columns:
7+
* The extensible relations have the following columns:
88
* - Sources:
99
* `package; type; subtypes; name; signature; ext; output; kind; provenance`
1010
* - Sinks:
1111
* `package; type; subtypes; name; signature; ext; input; kind; provenance`
1212
* - Summaries:
1313
* `package; type; subtypes; name; signature; ext; input; output; kind; provenance`
14+
* - Barriers:
15+
* `package; type; subtypes; name; signature; ext; output; kind; provenance`
16+
* - BarrierGuards:
17+
* `package; type; subtypes; name; signature; ext; input; acceptingValue; kind; provenance`
1418
* - Neutrals:
1519
* `package; type; name; signature; kind; provenance`
1620
* A neutral is used to indicate that a callable is neutral with respect to flow (no summary), source (is not a source) or sink (is not a sink).
@@ -78,11 +82,23 @@
7882
* - "MapValue": Selects a value in a map.
7983
* - "Dereference": Selects the value referenced by a pointer.
8084
*
81-
* 8. The `kind` column is a tag that can be referenced from QL to determine to
85+
* 8. The `acceptingValue` column of barrier guard models specifies the condition
86+
* under which the guard blocks flow. It can be one of "true" or "false". In
87+
* the future "no-exception", "not-zero", "null", "not-null" may be supported.
88+
* 9. The `kind` column is a tag that can be referenced from QL to determine to
8289
* which classes the interpreted elements should be added. For example, for
8390
* sources "remote" indicates a default remote flow source, and for summaries
8491
* "taint" indicates a default additional taint step and "value" indicates a
8592
* globally applicable value-preserving step.
93+
* 10. The `provenance` column is a tag to indicate the origin and verification of a model.
94+
* The format is {origin}-{verification} or just "manual" where the origin describes
95+
* the origin of the model and verification describes how the model has been verified.
96+
* Some examples are:
97+
* - "df-generated": The model has been generated by the model generator tool.
98+
* - "df-manual": The model has been generated by the model generator and verified by a human.
99+
* - "manual": The model has been written by hand.
100+
* This information is used in a heuristic for dataflow analysis to determine, if a
101+
* model or source code should be used for determining flow.
86102
*/
87103
overlay[local?]
88104
module;
@@ -250,11 +266,11 @@ module ModelValidation {
250266
result = "Unrecognized provenance description \"" + provenance + "\" in " + pred + " model."
251267
)
252268
or
253-
exists(string acceptingvalue |
254-
barrierGuardModel(_, _, _, _, _, _, _, acceptingvalue, _, _, _) and
255-
invalidAcceptingValue(acceptingvalue) and
269+
exists(string acceptingValue |
270+
barrierGuardModel(_, _, _, _, _, _, _, acceptingValue, _, _, _) and
271+
invalidAcceptingValue(acceptingValue) and
256272
result =
257-
"Unrecognized accepting value description \"" + acceptingvalue +
273+
"Unrecognized accepting value description \"" + acceptingValue +
258274
"\" in barrier guard model."
259275
)
260276
}
@@ -462,13 +478,13 @@ private module Cached {
462478

463479
private predicate barrierGuardChecks(DataFlow::Node g, Expr e, boolean gv, TKindModelPair kmp) {
464480
exists(
465-
SourceSinkInterpretationInput::InterpretNode n, Public::AcceptingValue acceptingvalue,
481+
SourceSinkInterpretationInput::InterpretNode n, Public::AcceptingValue acceptingValue,
466482
string kind, string model
467483
|
468-
isBarrierGuardNode(n, acceptingvalue, kind, model) and
484+
isBarrierGuardNode(n, acceptingValue, kind, model) and
469485
n.asNode().asExpr() = e and
470486
kmp = TMkPair(kind, model) and
471-
gv = convertAcceptingValue(acceptingvalue)
487+
gv = convertAcceptingValue(acceptingValue)
472488
|
473489
g.asExpr().(CallExpr).getAnArgument() = e // TODO: qualifier?
474490
)

go/ql/lib/semmle/go/dataflow/internal/ExternalFlowExtensions.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extensible predicate barrierModel(
3535
*/
3636
extensible predicate barrierGuardModel(
3737
string package, string type, boolean subtypes, string name, string signature, string ext,
38-
string input, string acceptingvalue, string kind, string provenance, QlBuiltins::ExtensionId madId
38+
string input, string acceptingValue, string kind, string provenance, QlBuiltins::ExtensionId madId
3939
);
4040

4141
/**

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ module SourceSinkInterpretationInput implements
174174
}
175175

176176
predicate barrierGuardElement(
177-
Element e, string input, Public::AcceptingValue acceptingvalue, string kind,
177+
Element e, string input, Public::AcceptingValue acceptingValue, string kind,
178178
Public::Provenance provenance, string model
179179
) {
180180
exists(
181181
string package, string type, boolean subtypes, string name, string signature, string ext
182182
|
183-
barrierGuardModel(package, type, subtypes, name, signature, ext, input, acceptingvalue, kind,
183+
barrierGuardModel(package, type, subtypes, name, signature, ext, input, acceptingValue, kind,
184184
provenance, model) and
185185
e = interpretElement(package, type, subtypes, name, signature, ext)
186186
)

java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
* Provides classes and predicates for dealing with flow models specified
55
* in data extensions and CSV format.
66
*
7-
* The CSV specification has the following columns:
7+
* The extensible relations have the following columns:
88
* - Sources:
99
* `package; type; subtypes; name; signature; ext; output; kind; provenance`
1010
* - Sinks:
1111
* `package; type; subtypes; name; signature; ext; input; kind; provenance`
1212
* - Summaries:
1313
* `package; type; subtypes; name; signature; ext; input; output; kind; provenance`
14+
* - Barriers:
15+
* `package; type; subtypes; name; signature; ext; output; kind; provenance`
16+
* - BarrierGuards:
17+
* `package; type; subtypes; name; signature; ext; input; acceptingValue; kind; provenance`
1418
* - Neutrals:
1519
* `package; type; name; signature; kind; provenance`
1620
* A neutral is used to indicate that a callable is neutral with respect to flow (no summary), source (is not a source) or sink (is not a sink).
@@ -69,14 +73,17 @@
6973
* in the given range. The range is inclusive at both ends.
7074
* - "ReturnValue": Selects the return value of a call to the selected element.
7175
* - "Element": Selects the collection elements of the selected element.
72-
* 8. The `kind` column is a tag that can be referenced from QL to determine to
76+
* 8. The `acceptingValue` column of barrier guard models specifies the condition
77+
* under which the guard blocks flow. It can be one of "true" or "false". In
78+
* the future "no-exception", "not-zero", "null", "not-null" may be supported.
79+
* 9. The `kind` column is a tag that can be referenced from QL to determine to
7380
* which classes the interpreted elements should be added. For example, for
7481
* sources "remote" indicates a default remote flow source, and for summaries
7582
* "taint" indicates a default additional taint step and "value" indicates a
7683
* globally applicable value-preserving step. For neutrals the kind can be `summary`,
7784
* `source` or `sink` to indicate that the neutral is neutral with respect to
7885
* flow (no summary), source (is not a source) or sink (is not a sink).
79-
* 9. The `provenance` column is a tag to indicate the origin and verification of a model.
86+
* 10. The `provenance` column is a tag to indicate the origin and verification of a model.
8087
* The format is {origin}-{verification} or just "manual" where the origin describes
8188
* the origin of the model and verification describes how the model has been verified.
8289
* Some examples are:
@@ -358,11 +365,11 @@ module ModelValidation {
358365
result = "Unrecognized provenance description \"" + provenance + "\" in " + pred + " model."
359366
)
360367
or
361-
exists(string acceptingvalue |
362-
barrierGuardModel(_, _, _, _, _, _, _, acceptingvalue, _, _, _) and
363-
invalidAcceptingValue(acceptingvalue) and
368+
exists(string acceptingValue |
369+
barrierGuardModel(_, _, _, _, _, _, _, acceptingValue, _, _, _) and
370+
invalidAcceptingValue(acceptingValue) and
364371
result =
365-
"Unrecognized accepting value description \"" + acceptingvalue +
372+
"Unrecognized accepting value description \"" + acceptingValue +
366373
"\" in barrier guard model."
367374
)
368375
}
@@ -583,13 +590,13 @@ private module Cached {
583590

584591
private predicate barrierGuardChecks(Guard g, Expr e, GuardValue gv, TKindModelPair kmp) {
585592
exists(
586-
SourceSinkInterpretationInput::InterpretNode n, AcceptingValue acceptingvalue, string kind,
593+
SourceSinkInterpretationInput::InterpretNode n, AcceptingValue acceptingValue, string kind,
587594
string model
588595
|
589-
isBarrierGuardNode(n, acceptingvalue, kind, model) and
596+
isBarrierGuardNode(n, acceptingValue, kind, model) and
590597
n.asNode().asExpr() = e and
591598
kmp = TMkPair(kind, model) and
592-
gv = convertAcceptingValue(acceptingvalue)
599+
gv = convertAcceptingValue(acceptingValue)
593600
|
594601
g.(Call).getAnArgument() = e or g.(MethodCall).getQualifier() = e
595602
)

0 commit comments

Comments
 (0)