Skip to content

Commit 9409cd6

Browse files
committed
Rust: Prototype query.
1 parent ae555f2 commit 9409cd6

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Provides classes and predicates for reasoning about uncontrolled allocation
3+
* size vulnerabilities.
4+
*/
5+
6+
import rust
7+
private import codeql.rust.Concepts
8+
private import codeql.rust.dataflow.DataFlow
9+
private import codeql.rust.dataflow.FlowSink
10+
11+
/**
12+
* Provides default sources, sinks and barriers for detecting uncontrolled
13+
* allocation size vulnerabilities, as well as extension points for adding your own.
14+
*/
15+
module UncontrolledAllocationSize {
16+
/**
17+
* A data flow sink for uncontrolled allocation size vulnerabilities.
18+
*/
19+
abstract class Sink extends QuerySink::Range {
20+
override string getSinkType() { result = "UncontrolledAllocationSize" }
21+
}
22+
23+
/**
24+
* A barrier for uncontrolled allocation size vulnerabilities.
25+
*/
26+
abstract class Barrier extends DataFlow::Node { }
27+
28+
/**
29+
* sink for uncontrolled allocation size from model data.
30+
*/
31+
private class ModelsAsDataSink extends Sink {
32+
ModelsAsDataSink() { sinkNode(this, ["alloc-size", "alloc-layout"]) }
33+
}
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @name Uncontrolled allocation size
3+
* @description Allocating memory with a size controlled by an external user can result in
4+
* arbitrary amounts of memory being allocated.
5+
* @kind path-problem
6+
* @problem.severity recommendation
7+
* @security-severity 7.5
8+
* @precision high
9+
* @id rust/uncontrolled-allocation-size
10+
* @tags reliability
11+
* security
12+
* external/cwe/cwe-770
13+
* external/cwe/cwe-789
14+
*/
15+
16+
import rust
17+
import codeql.rust.Concepts
18+
import codeql.rust.dataflow.DataFlow
19+
import codeql.rust.dataflow.TaintTracking
20+
import codeql.rust.dataflow.internal.DataFlowImpl
21+
import codeql.rust.security.UncontrolledAllocationSizeExtensions
22+
23+
/**
24+
* A taint-tracking configuration for uncontrolled allocation size vulnerabilities.
25+
*/
26+
module UncontrolledAllocationConfig implements DataFlow::ConfigSig {
27+
import UncontrolledAllocationSize
28+
29+
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
30+
31+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
32+
33+
predicate isBarrier(DataFlow::Node barrier) { barrier instanceof Barrier }
34+
}
35+
36+
module UncontrolledAllocationFlow = TaintTracking::Global<UncontrolledAllocationConfig>;
37+
38+
import UncontrolledAllocationFlow::PathGraph
39+
40+
from UncontrolledAllocationFlow::PathNode source, UncontrolledAllocationFlow::PathNode sink
41+
where UncontrolledAllocationFlow::flowPath(source, sink)
42+
select sink.getNode(), source, sink,
43+
"This allocation size is derived from a $@ and could allocate arbitrary amounts of memory.",
44+
source.getNode(), "user-provided value"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#select
2+
edges
3+
nodes
4+
subpaths

0 commit comments

Comments
 (0)