Skip to content

Rust: Cache defaultAdditionalTaintStep #18220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1101,9 +1101,11 @@ import MakeImpl<Location, RustDataFlow>
/** A collection of cached types and predicates to be evaluated in the same stage. */
cached
private module Cached {
private import codeql.rust.internal.CachedStages

cached
newtype TNode =
TExprNode(ExprCfgNode n) or
TExprNode(ExprCfgNode n) { Stages::DataFlowStage::ref() } or
TSourceParameterNode(ParamBaseCfgNode p) or
TPatNode(PatCfgNode p) or
TExprPostUpdateNode(ExprCfgNode e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ private import codeql.rust.controlflow.CfgNodes
private import codeql.rust.dataflow.FlowSummary
private import DataFlowImpl
private import FlowSummaryImpl as FlowSummaryImpl
private import codeql.rust.internal.CachedStages

module RustTaintTracking implements InputSig<Location, RustDataFlow> {
predicate defaultTaintSanitizer(Node::Node node) { none() }
Expand All @@ -12,7 +13,9 @@ module RustTaintTracking implements InputSig<Location, RustDataFlow> {
* Holds if the additional step from `pred` to `succ` should be included in all
* global taint flow configurations.
*/
cached
predicate defaultAdditionalTaintStep(Node::Node pred, Node::Node succ, string model) {
Stages::DataFlowStage::ref() and
model = "" and
(
exists(BinaryExprCfgNode binary |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Impl {
* ```
*/
class ArrayExpr extends Generated::ArrayExpr {
cached
pragma[nomagic]
private Raw::ArrayExprInternal getUnderlyingEntity() {
this = Synth::TArrayListExpr(result) or this = Synth::TArrayRepeatExpr(result)
}
Expand Down
34 changes: 30 additions & 4 deletions rust/ql/lib/codeql/rust/internal/CachedStages.qll
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ module Stages {
*/
cached
module AstStage {
private import codeql.rust.controlflow.internal.Splitting
private import codeql.rust.controlflow.internal.SuccessorType
private import codeql.rust.controlflow.internal.ControlFlowGraphImpl

/**
* Always holds.
* Ensures that a predicate is evaluated as part of the AST stage.
Expand Down Expand Up @@ -98,4 +94,34 @@ module Stages {
exists(CallExprCfgNode n | exists(n.getFunction()))
}
}

/**
* The data flow stage.
*/
cached
module DataFlowStage {
private import codeql.rust.dataflow.internal.DataFlowImpl
private import codeql.rust.dataflow.internal.TaintTrackingImpl

/**
* Always holds.
* Ensures that a predicate is evaluated as part of the data flow stage.
*/
cached
predicate ref() { 1 = 1 }

/**
* DO NOT USE!
*
* Contains references to each predicate that use the above `ref` predicate.
*/
cached
predicate backref() {
1 = 1
or
exists(Node n)
or
RustTaintTracking::defaultAdditionalTaintStep(_, _, _)
}
}
}
Loading