Skip to content

Commit 5f8c457

Browse files
authored
Merge pull request #20081 from d10c/d10c/diff-informed-phase-3-rust
Rust: Diff-informed queries: phase 3 (non-trivial locations)
2 parents 91ced7e + 83fe9e0 commit 5f8c457

File tree

8 files changed

+38
-9
lines changed

8 files changed

+38
-9
lines changed

rust/ql/src/queries/security/CWE-020/RegexInjection.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ module RegexInjectionConfig implements DataFlow::ConfigSig {
3434
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
3535
any(AdditionalFlowStep s).step(nodeFrom, nodeTo)
3636
}
37+
38+
predicate observeDiffInformedIncrementalMode() { any() }
3739
}
3840

3941
/**

rust/ql/src/queries/security/CWE-022/TaintedPath.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ module TaintedPathConfig implements DataFlow::StateConfigSig {
7979
stateFrom instanceof NotNormalized and
8080
stateTo instanceof NormalizedUnchecked
8181
}
82+
83+
predicate observeDiffInformedIncrementalMode() { any() }
8284
}
8385

8486
module TaintedPathFlow = TaintTracking::GlobalWithState<TaintedPathConfig>;

rust/ql/src/queries/security/CWE-089/SqlInjection.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ module SqlInjectionConfig implements DataFlow::ConfigSig {
2626
predicate isSink(DataFlow::Node node) { node instanceof Sink }
2727

2828
predicate isBarrier(DataFlow::Node barrier) { barrier instanceof Barrier }
29+
30+
predicate observeDiffInformedIncrementalMode() { any() }
2931
}
3032

3133
module SqlInjectionFlow = TaintTracking::Global<SqlInjectionConfig>;

rust/ql/src/queries/security/CWE-311/CleartextTransmission.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ module CleartextTransmissionConfig implements DataFlow::ConfigSig {
3737
// make sources barriers so that we only report the closest instance
3838
isSource(node)
3939
}
40+
41+
predicate observeDiffInformedIncrementalMode() { any() }
4042
}
4143

4244
module CleartextTransmissionFlow = TaintTracking::Global<CleartextTransmissionConfig>;

rust/ql/src/queries/security/CWE-312/CleartextLogging.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ module CleartextLoggingConfig implements DataFlow::ConfigSig {
4545
isSink(node) and
4646
c.getAReadContent() instanceof DataFlow::TuplePositionContent
4747
}
48+
49+
predicate observeDiffInformedIncrementalMode() { any() }
4850
}
4951

5052
module CleartextLoggingFlow = TaintTracking::Global<CleartextLoggingConfig>;

rust/ql/src/queries/security/CWE-770/UncontrolledAllocationSize.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ module UncontrolledAllocationConfig implements DataFlow::ConfigSig {
3232
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
3333

3434
predicate isBarrier(DataFlow::Node barrier) { barrier instanceof Barrier }
35+
36+
predicate observeDiffInformedIncrementalMode() { any() }
3537
}
3638

3739
module UncontrolledAllocationFlow = TaintTracking::Global<UncontrolledAllocationConfig>;

rust/ql/src/queries/security/CWE-825/AccessAfterLifetime.ql

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,40 @@ module AccessAfterLifetimeConfig implements DataFlow::ConfigSig {
2828
predicate isSink(DataFlow::Node node) { node instanceof AccessAfterLifetime::Sink }
2929

3030
predicate isBarrier(DataFlow::Node barrier) { barrier instanceof AccessAfterLifetime::Barrier }
31+
32+
predicate observeDiffInformedIncrementalMode() { any() }
33+
34+
Location getASelectedSourceLocation(DataFlow::Node source) {
35+
exists(Variable target, DataFlow::Node sink | result = target.getLocation() |
36+
isSink(sink) and
37+
narrowDereferenceAfterLifetime(source, sink, target)
38+
)
39+
}
3140
}
3241

3342
module AccessAfterLifetimeFlow = TaintTracking::Global<AccessAfterLifetimeConfig>;
3443

44+
pragma[inline]
45+
predicate narrowDereferenceAfterLifetime(DataFlow::Node source, DataFlow::Node sink, Variable target) {
46+
// check that the dereference is outside the lifetime of the target
47+
AccessAfterLifetime::dereferenceAfterLifetime(source, sink, target) and
48+
// include only results inside `unsafe` blocks, as other results tend to be false positives
49+
(
50+
sink.asExpr().getExpr().getEnclosingBlock*().isUnsafe() or
51+
sink.asExpr().getExpr().getEnclosingCallable().(Function).isUnsafe()
52+
) and
53+
// exclude cases with sources / sinks in macros, since these results are difficult to interpret
54+
not source.asExpr().getExpr().isFromMacroExpansion() and
55+
not sink.asExpr().getExpr().isFromMacroExpansion()
56+
}
57+
3558
from
3659
AccessAfterLifetimeFlow::PathNode sourceNode, AccessAfterLifetimeFlow::PathNode sinkNode,
3760
Variable target
3861
where
3962
// flow from a pointer or reference to the dereference
4063
AccessAfterLifetimeFlow::flowPath(sourceNode, sinkNode) and
4164
// check that the dereference is outside the lifetime of the target
42-
AccessAfterLifetime::dereferenceAfterLifetime(sourceNode.getNode(), sinkNode.getNode(), target) and
43-
// include only results inside `unsafe` blocks, as other results tend to be false positives
44-
(
45-
sinkNode.getNode().asExpr().getExpr().getEnclosingBlock*().isUnsafe() or
46-
sinkNode.getNode().asExpr().getExpr().getEnclosingCallable().(Function).isUnsafe()
47-
) and
48-
// exclude cases with sources / sinks in macros, since these results are difficult to interpret
49-
not sourceNode.getNode().asExpr().getExpr().isFromMacroExpansion() and
50-
not sinkNode.getNode().asExpr().getExpr().isFromMacroExpansion()
65+
narrowDereferenceAfterLifetime(sourceNode.getNode(), sinkNode.getNode(), target)
5166
select sinkNode.getNode(), sourceNode, sinkNode,
5267
"Access of a pointer to $@ after its lifetime has ended.", target, target.toString()

rust/ql/src/queries/security/CWE-825/AccessInvalidPointer.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ module AccessInvalidPointerConfig implements DataFlow::ConfigSig {
3232
// make sinks barriers so that we only report the closest instance
3333
isSink(node)
3434
}
35+
36+
predicate observeDiffInformedIncrementalMode() { any() }
3537
}
3638

3739
module AccessInvalidPointerFlow = TaintTracking::Global<AccessInvalidPointerConfig>;

0 commit comments

Comments
 (0)