Skip to content

Commit 1dbcaa0

Browse files
authored
Merge pull request github#18202 from paldepind/rust-taint
Rust: Add default taint flow steps
2 parents 4bf63fe + 5b6ce3e commit 1dbcaa0

File tree

18 files changed

+329
-59
lines changed

18 files changed

+329
-59
lines changed

rust/ql/.generated.list

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
private import rust
22
private import codeql.dataflow.TaintTracking
3+
private import codeql.rust.controlflow.CfgNodes
4+
private import DataFlowImpl
5+
private import codeql.rust.dataflow.FlowSummary
6+
private import FlowSummaryImpl as FlowSummaryImpl
37
private import DataFlowImpl
48

59
module RustTaintTracking implements InputSig<Location, RustDataFlow> {
610
predicate defaultTaintSanitizer(Node::Node node) { none() }
711

812
/**
9-
* Holds if the additional step from `src` to `sink` should be included in all
13+
* Holds if the additional step from `pred` to `succ` should be included in all
1014
* global taint flow configurations.
1115
*/
12-
predicate defaultAdditionalTaintStep(Node::Node src, Node::Node sink, string model) { none() }
16+
predicate defaultAdditionalTaintStep(Node::Node pred, Node::Node succ, string model) {
17+
model = "" and
18+
(
19+
exists(BinaryExprCfgNode binary |
20+
binary.getOperatorName() = ["+", "-", "*", "/", "%", "&", "|", "^", "<<", ">>"] and
21+
pred.asExpr() = [binary.getLhs(), binary.getRhs()] and
22+
succ.asExpr() = binary
23+
)
24+
or
25+
exists(PrefixExprCfgNode prefix |
26+
prefix.getOperatorName() = ["-", "!"] and
27+
pred.asExpr() = prefix.getExpr() and
28+
succ.asExpr() = prefix
29+
)
30+
or
31+
pred.asExpr() = succ.asExpr().(CastExprCfgNode).getExpr()
32+
or
33+
exists(IndexExprCfgNode index |
34+
index.getIndex() instanceof RangeExprCfgNode and
35+
pred.asExpr() = index.getBase() and
36+
succ.asExpr() = index
37+
)
38+
)
39+
or
40+
FlowSummaryImpl::Private::Steps::summaryLocalStep(pred.(Node::FlowSummaryNode).getSummaryNode(),
41+
succ.(Node::FlowSummaryNode).getSummaryNode(), false, model)
42+
}
1343

1444
/**
1545
* Holds if taint flow configurations should allow implicit reads of `c` at sinks

rust/ql/lib/codeql/rust/elements/CastExpr.qll

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/internal/CastExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private import codeql.rust.elements.internal.generated.CastExpr
1313
module Impl {
1414
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1515
/**
16-
* A cast expression. For example:
16+
* A type cast expression. For example:
1717
* ```rust
1818
* value as u64;
1919
* ```

rust/ql/lib/codeql/rust/elements/internal/generated/CastExpr.qll

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/test/extractor-tests/generated/.generated_tests.list

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/test/extractor-tests/generated/CastExpr/gen_cast_expr.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ fn test_identify() {
1616
sink(identity(s)); // $ hasValueFlow=1
1717
}
1818

19+
// has a flow model
20+
fn coerce(_i: i64) -> i64 {
21+
0
22+
}
23+
24+
fn test_coerce() {
25+
let s = source(14);
26+
sink(coerce(s)); // $ hasTaintFlow=14
27+
}
28+
1929
enum MyPosEnum {
2030
A(i64),
2131
B(i64),

0 commit comments

Comments
 (0)