diff --git a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.qll b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.qll index 9626339b2900..70dfbd753723 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.qll @@ -1256,7 +1256,7 @@ module BarrierGuardWithIntParam::guardChecksNodeSig/ Node getABarrierNode(int indirectionIndex, P p) { fromDfNode(result) = - DataFlowIntegrationImpl::BarrierGuardDefWithState::MkPair, guardChecksWithWrappers/4>::getABarrierNode(ParamIntPair

::MkPair(p, + DataFlowIntegrationImpl::SsaBarrierGuardWithState::MkPair, guardChecksWithWrappers/4>::getABarrierNode(ParamIntPair

::MkPair(p, indirectionIndex)) } } diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll index f7bb0f809057..ce14d388e453 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll @@ -932,7 +932,7 @@ private module Cached { private Node getABarrierNodeImpl() { result = - DataFlowIntegrationImpl::BarrierGuardDefWithState::getABarrierNode(_) + DataFlowIntegrationImpl::SsaBarrierGuardWithState::getABarrierNode(_) } predicate getABarrierNode = getABarrierNodeImpl/0; @@ -962,7 +962,7 @@ private module Cached { private Node getABarrierNodeImpl(P param) { result = - DataFlowIntegrationImpl::BarrierGuardDefWithState::getABarrierNode(param) + DataFlowIntegrationImpl::SsaBarrierGuardWithState::getABarrierNode(param) } predicate getABarrierNode = getABarrierNodeImpl/1; diff --git a/java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll b/java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll index 3f5aa4ad5e96..c69d6ed5f812 100644 --- a/java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll +++ b/java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll @@ -538,7 +538,7 @@ private module Cached { private Node getABarrierNodeImpl() { result = - DataFlowIntegrationImpl::BarrierGuardDefWithState::getABarrierNode(_) + DataFlowIntegrationImpl::SsaBarrierGuardWithState::getABarrierNode(_) } predicate getABarrierNode = getABarrierNodeImpl/0; @@ -568,7 +568,7 @@ private module Cached { private Node getABarrierNodeImpl(P param) { result = - DataFlowIntegrationImpl::BarrierGuardDefWithState::getABarrierNode(param) + DataFlowIntegrationImpl::SsaBarrierGuardWithState::getABarrierNode(param) } predicate getABarrierNode = getABarrierNodeImpl/1; diff --git a/javascript/ql/lib/semmle/javascript/dataflow/internal/BarrierGuards.qll b/javascript/ql/lib/semmle/javascript/dataflow/internal/BarrierGuards.qll index 699cfd94fbbc..7ea5383b7ebf 100644 --- a/javascript/ql/lib/semmle/javascript/dataflow/internal/BarrierGuards.qll +++ b/javascript/ql/lib/semmle/javascript/dataflow/internal/BarrierGuards.qll @@ -332,16 +332,15 @@ module MakeStateBarrierGuard< } private predicate ssa2GuardChecks( - Ssa2::SsaDataflowInput::Guard guard, Ssa2::SsaDataflowInput::Expr test, Boolean branch, - FlowState state + Ssa2::SsaDataflowInput::Guard guard, Ssa2::Definition def, Boolean branch, FlowState state ) { exists(BarrierGuard g | g.asExpr() = guard and - g.blocksExpr(branch, test, state) + g.blocksExpr(branch, Ssa2::getARead(def), state) ) } - private module Ssa2Barrier = Ssa2::BarrierGuardWithState; + private module Ssa2Barrier = Ssa2::SsaBarrierGuardWithState; private predicate ssa2BlocksNode(DataFlow::Node node, FlowState state) { node = DataFlowPrivate::getNodeFromSsa2(Ssa2Barrier::getABarrierNode(state)) diff --git a/javascript/ql/lib/semmle/javascript/dataflow/internal/TaintTrackingPrivate.qll b/javascript/ql/lib/semmle/javascript/dataflow/internal/TaintTrackingPrivate.qll index 61678d6fbdab..15f7d44bc52c 100644 --- a/javascript/ql/lib/semmle/javascript/dataflow/internal/TaintTrackingPrivate.qll +++ b/javascript/ql/lib/semmle/javascript/dataflow/internal/TaintTrackingPrivate.qll @@ -37,13 +37,12 @@ predicate defaultAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2, } private predicate guardChecksFalsy( - Ssa2::SsaDataflowInput::Guard g, Ssa2::SsaDataflowInput::Expr e, Boolean outcome + Ssa2::SsaDataflowInput::Guard g, Ssa2::Definition def, Boolean outcome ) { exists(ConditionGuardNode guard | guard.getTest() = g and guard.getOutcome() = outcome and - e = g and - e instanceof VarAccess and + g = Ssa2::getARead(def) and outcome = false ) } @@ -68,7 +67,7 @@ private predicate guardChecksFalsy( * ``` */ private predicate varAccessBarrier(DataFlow::Node node) { - getNodeFromSsa2(Ssa2::BarrierGuard::getABarrierNode()) = node + getNodeFromSsa2(Ssa2::SsaBarrierGuard::getABarrierNode()) = node } /** diff --git a/javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib/Ssa.qll b/javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib/Ssa.qll index 1c31de4293f2..ebeec96673ab 100644 --- a/javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib/Ssa.qll +++ b/javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib/Ssa.qll @@ -44,6 +44,15 @@ module SsaConfig implements InputSig { import Make +pragma[nomagic] +js::ControlFlowNode getARead(Definition def) { + exists(SsaConfig::SourceVariable v, js::Cfg::BasicBlock bb, int i | + ssaDefReachesRead(v, def, bb, i) and + SsaConfig::variableRead(bb, i, v, true) and + bb.getNode(i) = result + ) +} + module SsaDataflowInput implements DataFlowIntegrationInputSig { private import codeql.util.Boolean diff --git a/ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll b/ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll index 67763a2bf78c..e866d5b70b23 100644 --- a/ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll +++ b/ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll @@ -329,14 +329,14 @@ private module Cached { cached // nothing is actually cached module BarrierGuard { private predicate guardChecksAdjTypes( - DataFlowIntegrationInput::Guard g, DataFlowIntegrationInput::Expr e, + DataFlowIntegrationInput::Guard g, Definition def, DataFlowIntegrationInput::GuardValue branch ) { - guardChecks(g, e, branch) + guardChecks(g, Cached::getARead(def), branch) } private Node getABarrierNodeImpl() { - result = DataFlowIntegrationImpl::BarrierGuard::getABarrierNode() + result = DataFlowIntegrationImpl::SsaBarrierGuard::getABarrierNode() } predicate getABarrierNode = getABarrierNodeImpl/0; @@ -355,15 +355,15 @@ private module Cached { cached // nothing is actually cached module ParameterizedBarrierGuard::guardChecksSig/4 guardChecks> { private predicate guardChecksAdjTypes( - DataFlowIntegrationInput::Guard g, DataFlowIntegrationInput::Expr e, + DataFlowIntegrationInput::Guard g, Definition def, DataFlowIntegrationInput::GuardValue branch, P param ) { - guardChecks(g, e, branch, param) + guardChecks(g, Cached::getARead(def), branch, param) } private Node getABarrierNodeImpl(P param) { result = - DataFlowIntegrationImpl::BarrierGuardWithState::getABarrierNode(param) + DataFlowIntegrationImpl::SsaBarrierGuardWithState::getABarrierNode(param) } predicate getABarrierNode = getABarrierNodeImpl/1; diff --git a/rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll b/rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll index ef2583ab9e9d..1845e87b26c9 100644 --- a/rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll +++ b/rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll @@ -285,14 +285,14 @@ private module Cached { cached // nothing is actually cached module BarrierGuard { private predicate guardChecksAdjTypes( - DataFlowIntegrationInput::Guard g, DataFlowIntegrationInput::Expr e, + DataFlowIntegrationInput::Guard g, Definition def, DataFlowIntegrationInput::GuardValue branch ) { - guardChecks(g, e, branch) + guardChecks(g, Cached::getARead(def), branch) } private Node getABarrierNodeImpl() { - result = DataFlowIntegrationImpl::BarrierGuard::getABarrierNode() + result = DataFlowIntegrationImpl::SsaBarrierGuard::getABarrierNode() } predicate getABarrierNode = getABarrierNodeImpl/0; @@ -309,15 +309,15 @@ private module Cached { cached // nothing is actually cached module ParameterizedBarrierGuard::guardChecksSig/4 guardChecks> { private predicate guardChecksAdjTypes( - DataFlowIntegrationInput::Guard g, DataFlowIntegrationInput::Expr e, + DataFlowIntegrationInput::Guard g, Definition def, DataFlowIntegrationInput::GuardValue branch, P param ) { - guardChecks(g, e, branch, param) + guardChecks(g, Cached::getARead(def), branch, param) } private Node getABarrierNodeImpl(P param) { result = - DataFlowIntegrationImpl::BarrierGuardWithState::getABarrierNode(param) + DataFlowIntegrationImpl::SsaBarrierGuardWithState::getABarrierNode(param) } predicate getABarrierNode = getABarrierNodeImpl/1; diff --git a/shared/ssa/codeql/ssa/Ssa.qll b/shared/ssa/codeql/ssa/Ssa.qll index 8943cedf9d54..9670655856d3 100644 --- a/shared/ssa/codeql/ssa/Ssa.qll +++ b/shared/ssa/codeql/ssa/Ssa.qll @@ -2146,13 +2146,10 @@ module Make< } /** - * Holds if the guard `g` validates the expression `e` upon evaluating to `val`. - * - * The expression `e` is expected to be a syntactic part of the guard `g`. - * For example, the guard `g` might be a call `isSafe(x)` and the expression `e` - * the argument `x`. + * Holds if the guard `g` validates the SSA definition `def` upon + * evaluating to `val`. */ - signature predicate guardChecksSig(DfInput::Guard g, DfInput::Expr e, DfInput::GuardValue val); + signature predicate guardChecksSig(DfInput::Guard g, Definition def, DfInput::GuardValue val); pragma[nomagic] private Definition getAPhiInputDef(SsaInputNodeImpl n) { @@ -2166,41 +2163,29 @@ module Make< signature class StateSig; private module WithState { - /** - * Holds if the guard `g` validates the expression `e` upon evaluating to `val`, blocking - * flow in the given `state`. - * - * The expression `e` is expected to be a syntactic part of the guard `g`. - * For example, the guard `g` might be a call `isSafe(x)` and the expression `e` - * the argument `x`. - */ - signature predicate guardChecksSig( - DfInput::Guard g, DfInput::Expr e, DfInput::GuardValue val, State state - ); - /** * Holds if the guard `g` validates the SSA definition `def` upon * evaluating to `val`, blocking flow in the given `state`. */ - signature predicate guardChecksDefSig( + signature predicate guardChecksSig( DfInput::Guard g, Definition def, DfInput::GuardValue val, State state ); } /** - * Provides a set of barrier nodes for a guard that validates an expression. + * Provides a set of barrier nodes for a guard that validates an SSA definition. * * This is expected to be used in `isBarrier`/`isSanitizer` definitions * in data flow and taint tracking. */ - module BarrierGuard { + module SsaBarrierGuard { private predicate guardChecksWithState( - DfInput::Guard g, DfInput::Expr e, DfInput::GuardValue val, Unit state + DfInput::Guard g, Definition def, DfInput::GuardValue val, Unit state ) { - guardChecks(g, e, val) and exists(state) + guardChecks(g, def, val) and exists(state) } - private module StatefulBarrier = BarrierGuardWithState; + private module StatefulBarrier = SsaBarrierGuardWithState; /** Gets a node that is safely guarded by the given guard check. */ pragma[nomagic] @@ -2208,38 +2193,17 @@ module Make< } /** - * Provides a set of barrier nodes for a guard that validates an expression. - * - * This is expected to be used in `isBarrier`/`isSanitizer` definitions - * in data flow and taint tracking. - */ - module BarrierGuardWithState::guardChecksSig/4 guardChecks> { - pragma[nomagic] - private predicate guardChecksSsaDef( - DfInput::Guard g, Definition def, DfInput::GuardValue val, State state - ) { - guardChecks(g, getARead(def), val, state) - } - - private module Barrier = BarrierGuardDefWithState; - - predicate getABarrierNode = Barrier::getABarrierNode/1; - } - - /** - * Provides a set of barrier nodes for a guard that validates an expression. + * Provides a set of barrier nodes for a guard that validates an SSA definition. * * This is expected to be used in `isBarrier`/`isSanitizer` definitions * in data flow and taint tracking. */ - module BarrierGuardDefWithState< - StateSig State, WithState::guardChecksDefSig/4 guardChecksSsaDef> - { + module SsaBarrierGuardWithState::guardChecksSig/4 guardChecks> { /** Gets a node that is safely guarded by the given guard check. */ pragma[nomagic] Node getABarrierNode(State state) { exists(DfInput::Guard g, DfInput::GuardValue val, Definition def, BasicBlock bb | - guardChecksSsaDef(g, def, val, state) + guardChecks(g, def, val, state) | // guard controls a read exists(DfInput::Expr e |