Skip to content

Commit baf186f

Browse files
committed
Address review comments
1 parent 2f8b04b commit baf186f

File tree

4 files changed

+74
-19
lines changed

4 files changed

+74
-19
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll

+45-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
/**
22
* Defines extensible predicates for contributing library models from data extensions.
3+
*
4+
* The extensible relations have the following columns:
5+
*
6+
* - Sources:
7+
* `crate; path; output; kind; provenance`
8+
* - Sinks:
9+
* `crate; path; input; kind; provenance`
10+
* - Summaries:
11+
* `crate; path; input; output; kind; provenance`
12+
*
13+
* The interpretation of a row is similar to API-graphs with a left-to-right
14+
* reading.
15+
*
16+
* 1. The `crate` column selects a crate.
17+
* 2. The `path` column selects a function with the given canonical path within
18+
* the crate.
19+
* 3. The `input` column specifies how data enters the element selected by the
20+
* first 2 columns, and the `output` column specifies how data leaves the
21+
* element selected by the first 2 columns. Both `input` and `output` are
22+
* `.`-separated lists of "access path tokens" to resolve, starting at the
23+
* selected function.
24+
*
25+
* The following tokens are supported:
26+
* - `Argument[n]`: the `n`-th argument to a call. May be a range of form `x..y` (inclusive)
27+
* and/or a comma-separated list.
28+
* - `Parameter[n]`: the `n`-th parameter of a callback. May be a range of form `x..y` (inclusive)
29+
* and/or a comma-separated list.
30+
* - `ReturnValue`: the value returned by a function call.
31+
* - `ArrayElement`: an element of an array.
32+
* - `Variant[v::f]`: field `f` of the variant with canonical path `v`, for example
33+
* `Variant[crate::ihex::Record::Data::value]`.
34+
* - `Variant[v(i)]`: position `i` inside the variant with canonical path `v`, for example
35+
* `Variant[crate::option::Option::Some(0)]`.
36+
* - `Struct[s::f]`: field `f` of the struct with canonical path `v`, for example
37+
* `Struct[crate::process::Child::stdin]`.
38+
* - `Tuple[i]`: the `i`th element of a tuple.
39+
* 4. The `kind` column is a tag that can be referenced from QL to determine to
40+
* which classes the interpreted elements should be added. For example, for
41+
* sources `"remote"` indicates a default remote flow source, and for summaries
42+
* `"taint"` indicates a default additional taint step and `"value"` indicates a
43+
* globally applicable value-preserving step.
44+
* 5. The `provenance` column is mainly used internally, and should be set to `"manual"` for
45+
* all custom models.
346
*/
447

548
private import rust
@@ -12,9 +55,8 @@ private import codeql.rust.dataflow.FlowSummary
1255
*
1356
* `output = "ReturnValue"` simply means the result of the call itself.
1457
*
15-
* The following kinds are supported:
16-
*
17-
* - `remote`: a general remote flow source.
58+
* For more information on the `kind` parameter, see
59+
* https://github.com/github/codeql/blob/main/docs/codeql/reusables/threat-model-description.rst.
1860
*/
1961
extensible predicate sourceModel(
2062
string crate, string path, string output, string kind, string provenance,

rust/ql/test/library-tests/dataflow/models/models.expected

+14-15
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ models
55
| 4 | Summary: repo::test; crate::get_tuple_element; Argument[0].Tuple[0]; ReturnValue; value |
66
| 5 | Summary: repo::test; crate::get_var_field; Argument[0].Variant[crate::MyFieldEnum::C::field_c]; ReturnValue; value |
77
| 6 | Summary: repo::test; crate::get_var_pos; Argument[0].Variant[crate::MyPosEnum::A(0)]; ReturnValue; value |
8-
| 7 | Summary: repo::test; crate::identity; Argument[0]; ReturnValue; value |
9-
| 8 | Summary: repo::test; crate::set_array_element; Argument[0]; ReturnValue.ArrayElement; value |
10-
| 9 | Summary: repo::test; crate::set_tuple_element; Argument[0]; ReturnValue.Tuple[1]; value |
11-
| 10 | Summary: repo::test; crate::set_var_field; Argument[0]; ReturnValue.Variant[crate::MyFieldEnum::D::field_d]; value |
12-
| 11 | Summary: repo::test; crate::set_var_pos; Argument[0]; ReturnValue.Variant[crate::MyPosEnum::B(0)]; value |
8+
| 7 | Summary: repo::test; crate::set_array_element; Argument[0]; ReturnValue.ArrayElement; value |
9+
| 8 | Summary: repo::test; crate::set_tuple_element; Argument[0]; ReturnValue.Tuple[1]; value |
10+
| 9 | Summary: repo::test; crate::set_var_field; Argument[0]; ReturnValue.Variant[crate::MyFieldEnum::D::field_d]; value |
11+
| 10 | Summary: repo::test; crate::set_var_pos; Argument[0]; ReturnValue.Variant[crate::MyPosEnum::B(0)]; value |
1312
edges
1413
| main.rs:15:13:15:21 | source(...) | main.rs:16:19:16:19 | s | provenance | |
1514
| main.rs:15:13:15:21 | source(...) | main.rs:16:19:16:19 | s | provenance | |
16-
| main.rs:16:19:16:19 | s | main.rs:16:10:16:20 | identity(...) | provenance | MaD:7 |
17-
| main.rs:16:19:16:19 | s | main.rs:16:10:16:20 | identity(...) | provenance | MaD:7 |
15+
| main.rs:16:19:16:19 | s | main.rs:16:10:16:20 | identity(...) | provenance | QL |
16+
| main.rs:16:19:16:19 | s | main.rs:16:10:16:20 | identity(...) | provenance | QL |
1817
| main.rs:25:13:25:22 | source(...) | main.rs:26:17:26:17 | s | provenance | |
1918
| main.rs:26:17:26:17 | s | main.rs:26:10:26:18 | coerce(...) | provenance | MaD:1 |
2019
| main.rs:40:13:40:21 | source(...) | main.rs:41:27:41:27 | s | provenance | |
@@ -29,8 +28,8 @@ edges
2928
| main.rs:53:13:53:21 | source(...) | main.rs:54:26:54:26 | s | provenance | |
3029
| main.rs:54:14:54:27 | set_var_pos(...) [B] | main.rs:57:9:57:23 | ...::B(...) [B] | provenance | |
3130
| main.rs:54:14:54:27 | set_var_pos(...) [B] | main.rs:57:9:57:23 | ...::B(...) [B] | provenance | |
32-
| main.rs:54:26:54:26 | s | main.rs:54:14:54:27 | set_var_pos(...) [B] | provenance | MaD:11 |
33-
| main.rs:54:26:54:26 | s | main.rs:54:14:54:27 | set_var_pos(...) [B] | provenance | MaD:11 |
31+
| main.rs:54:26:54:26 | s | main.rs:54:14:54:27 | set_var_pos(...) [B] | provenance | MaD:10 |
32+
| main.rs:54:26:54:26 | s | main.rs:54:14:54:27 | set_var_pos(...) [B] | provenance | MaD:10 |
3433
| main.rs:57:9:57:23 | ...::B(...) [B] | main.rs:57:22:57:22 | i | provenance | |
3534
| main.rs:57:9:57:23 | ...::B(...) [B] | main.rs:57:22:57:22 | i | provenance | |
3635
| main.rs:57:22:57:22 | i | main.rs:57:33:57:33 | i | provenance | |
@@ -47,8 +46,8 @@ edges
4746
| main.rs:85:13:85:21 | source(...) | main.rs:86:28:86:28 | s | provenance | |
4847
| main.rs:86:14:86:29 | set_var_field(...) [D] | main.rs:89:9:89:37 | ...::D {...} [D] | provenance | |
4948
| main.rs:86:14:86:29 | set_var_field(...) [D] | main.rs:89:9:89:37 | ...::D {...} [D] | provenance | |
50-
| main.rs:86:28:86:28 | s | main.rs:86:14:86:29 | set_var_field(...) [D] | provenance | MaD:10 |
51-
| main.rs:86:28:86:28 | s | main.rs:86:14:86:29 | set_var_field(...) [D] | provenance | MaD:10 |
49+
| main.rs:86:28:86:28 | s | main.rs:86:14:86:29 | set_var_field(...) [D] | provenance | MaD:9 |
50+
| main.rs:86:28:86:28 | s | main.rs:86:14:86:29 | set_var_field(...) [D] | provenance | MaD:9 |
5251
| main.rs:89:9:89:37 | ...::D {...} [D] | main.rs:89:35:89:35 | i | provenance | |
5352
| main.rs:89:9:89:37 | ...::D {...} [D] | main.rs:89:35:89:35 | i | provenance | |
5453
| main.rs:89:35:89:35 | i | main.rs:89:47:89:47 | i | provenance | |
@@ -71,8 +70,8 @@ edges
7170
| main.rs:148:13:148:21 | source(...) | main.rs:149:33:149:33 | s | provenance | |
7271
| main.rs:149:15:149:34 | set_array_element(...) [array[]] | main.rs:150:10:150:12 | arr [array[]] | provenance | |
7372
| main.rs:149:15:149:34 | set_array_element(...) [array[]] | main.rs:150:10:150:12 | arr [array[]] | provenance | |
74-
| main.rs:149:33:149:33 | s | main.rs:149:15:149:34 | set_array_element(...) [array[]] | provenance | MaD:8 |
75-
| main.rs:149:33:149:33 | s | main.rs:149:15:149:34 | set_array_element(...) [array[]] | provenance | MaD:8 |
73+
| main.rs:149:33:149:33 | s | main.rs:149:15:149:34 | set_array_element(...) [array[]] | provenance | MaD:7 |
74+
| main.rs:149:33:149:33 | s | main.rs:149:15:149:34 | set_array_element(...) [array[]] | provenance | MaD:7 |
7675
| main.rs:150:10:150:12 | arr [array[]] | main.rs:150:10:150:15 | arr[0] | provenance | |
7776
| main.rs:150:10:150:12 | arr [array[]] | main.rs:150:10:150:15 | arr[0] | provenance | |
7877
| main.rs:159:13:159:22 | source(...) | main.rs:160:14:160:14 | s | provenance | |
@@ -87,8 +86,8 @@ edges
8786
| main.rs:172:13:172:22 | source(...) | main.rs:173:31:173:31 | s | provenance | |
8887
| main.rs:173:13:173:32 | set_tuple_element(...) [tuple.1] | main.rs:175:10:175:10 | t [tuple.1] | provenance | |
8988
| main.rs:173:13:173:32 | set_tuple_element(...) [tuple.1] | main.rs:175:10:175:10 | t [tuple.1] | provenance | |
90-
| main.rs:173:31:173:31 | s | main.rs:173:13:173:32 | set_tuple_element(...) [tuple.1] | provenance | MaD:9 |
91-
| main.rs:173:31:173:31 | s | main.rs:173:13:173:32 | set_tuple_element(...) [tuple.1] | provenance | MaD:9 |
89+
| main.rs:173:31:173:31 | s | main.rs:173:13:173:32 | set_tuple_element(...) [tuple.1] | provenance | MaD:8 |
90+
| main.rs:173:31:173:31 | s | main.rs:173:13:173:32 | set_tuple_element(...) [tuple.1] | provenance | MaD:8 |
9291
| main.rs:175:10:175:10 | t [tuple.1] | main.rs:175:10:175:12 | t.1 | provenance | |
9392
| main.rs:175:10:175:10 | t [tuple.1] | main.rs:175:10:175:12 | t.1 | provenance | |
9493
nodes

rust/ql/test/library-tests/dataflow/models/models.ext.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ extensions:
33
pack: codeql/rust-all
44
extensible: summaryModel
55
data:
6-
- ["repo::test", "crate::identity", "Argument[0]", "ReturnValue", "value", "manual"]
76
- ["repo::test", "crate::coerce", "Argument[0]", "ReturnValue", "taint", "manual"]
87
- ["repo::test", "crate::get_var_pos", "Argument[0].Variant[crate::MyPosEnum::A(0)]", "ReturnValue", "value", "manual"]
98
- ["repo::test", "crate::set_var_pos", "Argument[0]", "ReturnValue.Variant[crate::MyPosEnum::B(0)]", "value", "manual"]

rust/ql/test/library-tests/dataflow/models/models.ql

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ query predicate invalidSpecComponent(SummarizedCallable sc, string s, string c)
1515
Private::External::invalidSpecComponent(s, c)
1616
}
1717

18+
// not defined in `models.ext.yml`, in order to test that we can also define
19+
// models directly in QL
20+
private class SummarizedCallableIdentity extends SummarizedCallable::Range {
21+
SummarizedCallableIdentity() { this = "repo::test::_::crate::identity" }
22+
23+
override predicate propagatesFlow(
24+
string input, string output, boolean preservesValue, string provenance
25+
) {
26+
input = "Argument[0]" and
27+
output = "ReturnValue" and
28+
preservesValue = true and
29+
provenance = "QL"
30+
}
31+
}
32+
1833
module CustomConfig implements DataFlow::ConfigSig {
1934
predicate isSource(DataFlow::Node source) { DefaultFlowConfig::isSource(source) }
2035

0 commit comments

Comments
 (0)