Skip to content
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 @@ -1256,7 +1256,7 @@ module BarrierGuardWithIntParam<ParamSig P, IntWithParam<P>::guardChecksNodeSig/

Node getABarrierNode(int indirectionIndex, P p) {
fromDfNode(result) =
DataFlowIntegrationImpl::BarrierGuardDefWithState<ParamIntPair<P>::MkPair, guardChecksWithWrappers/4>::getABarrierNode(ParamIntPair<P>::MkPair(p,
DataFlowIntegrationImpl::SsaBarrierGuardWithState<ParamIntPair<P>::MkPair, guardChecksWithWrappers/4>::getABarrierNode(ParamIntPair<P>::MkPair(p,
indirectionIndex))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ private module Cached {

private Node getABarrierNodeImpl() {
result =
DataFlowIntegrationImpl::BarrierGuardDefWithState<Unit, guardChecksWithWrappers/4>::getABarrierNode(_)
DataFlowIntegrationImpl::SsaBarrierGuardWithState<Unit, guardChecksWithWrappers/4>::getABarrierNode(_)
}

predicate getABarrierNode = getABarrierNodeImpl/0;
Expand Down Expand Up @@ -962,7 +962,7 @@ private module Cached {

private Node getABarrierNodeImpl(P param) {
result =
DataFlowIntegrationImpl::BarrierGuardDefWithState<P, guardChecksWithWrappers/4>::getABarrierNode(param)
DataFlowIntegrationImpl::SsaBarrierGuardWithState<P, guardChecksWithWrappers/4>::getABarrierNode(param)
}

predicate getABarrierNode = getABarrierNodeImpl/1;
Expand Down
4 changes: 2 additions & 2 deletions java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ private module Cached {

private Node getABarrierNodeImpl() {
result =
DataFlowIntegrationImpl::BarrierGuardDefWithState<Unit, guardChecksWithWrappers/4>::getABarrierNode(_)
DataFlowIntegrationImpl::SsaBarrierGuardWithState<Unit, guardChecksWithWrappers/4>::getABarrierNode(_)
}

predicate getABarrierNode = getABarrierNodeImpl/0;
Expand Down Expand Up @@ -568,7 +568,7 @@ private module Cached {

private Node getABarrierNodeImpl(P param) {
result =
DataFlowIntegrationImpl::BarrierGuardDefWithState<P, guardChecksWithWrappers/4>::getABarrierNode(param)
DataFlowIntegrationImpl::SsaBarrierGuardWithState<P, guardChecksWithWrappers/4>::getABarrierNode(param)
}

predicate getABarrierNode = getABarrierNodeImpl/1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlowState, ssa2GuardChecks/4>;
private module Ssa2Barrier = Ssa2::SsaBarrierGuardWithState<FlowState, ssa2GuardChecks/4>;

private predicate ssa2BlocksNode(DataFlow::Node node, FlowState state) {
node = DataFlowPrivate::getNodeFromSsa2(Ssa2Barrier::getABarrierNode(state))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand All @@ -68,7 +67,7 @@ private predicate guardChecksFalsy(
* ```
*/
private predicate varAccessBarrier(DataFlow::Node node) {
getNodeFromSsa2(Ssa2::BarrierGuard<guardChecksFalsy/3>::getABarrierNode()) = node
getNodeFromSsa2(Ssa2::SsaBarrierGuard<guardChecksFalsy/3>::getABarrierNode()) = node
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ module SsaConfig implements InputSig<js::Location, js::Cfg::BasicBlock> {

import Make<js::Location, js::Cfg, SsaConfig>

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

Expand Down
12 changes: 6 additions & 6 deletions ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ private module Cached {
cached // nothing is actually cached
module BarrierGuard<guardChecksSig/3 guardChecks> {
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<guardChecksAdjTypes/3>::getABarrierNode()
result = DataFlowIntegrationImpl::SsaBarrierGuard<guardChecksAdjTypes/3>::getABarrierNode()
}

predicate getABarrierNode = getABarrierNodeImpl/0;
Expand All @@ -355,15 +355,15 @@ private module Cached {
cached // nothing is actually cached
module ParameterizedBarrierGuard<ParamSig P, WithParam<P>::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<P, guardChecksAdjTypes/4>::getABarrierNode(param)
DataFlowIntegrationImpl::SsaBarrierGuardWithState<P, guardChecksAdjTypes/4>::getABarrierNode(param)
}

predicate getABarrierNode = getABarrierNodeImpl/1;
Expand Down
12 changes: 6 additions & 6 deletions rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ private module Cached {
cached // nothing is actually cached
module BarrierGuard<guardChecksSig/3 guardChecks> {
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<guardChecksAdjTypes/3>::getABarrierNode()
result = DataFlowIntegrationImpl::SsaBarrierGuard<guardChecksAdjTypes/3>::getABarrierNode()
}

predicate getABarrierNode = getABarrierNodeImpl/0;
Expand All @@ -309,15 +309,15 @@ private module Cached {
cached // nothing is actually cached
module ParameterizedBarrierGuard<ParamSig P, WithParam<P>::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<P, guardChecksAdjTypes/4>::getABarrierNode(param)
DataFlowIntegrationImpl::SsaBarrierGuardWithState<P, guardChecksAdjTypes/4>::getABarrierNode(param)
}

predicate getABarrierNode = getABarrierNodeImpl/1;
Expand Down
60 changes: 12 additions & 48 deletions shared/ssa/codeql/ssa/Ssa.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment thread
aschackmull marked this conversation as resolved.
Resolved

pragma[nomagic]
private Definition getAPhiInputDef(SsaInputNodeImpl n) {
Expand All @@ -2166,80 +2163,47 @@ module Make<
signature class StateSig;

private module WithState<StateSig State> {
/**
* 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<guardChecksSig/3 guardChecks> {
module SsaBarrierGuard<guardChecksSig/3 guardChecks> {
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<Unit, guardChecksWithState/4>;
private module StatefulBarrier = SsaBarrierGuardWithState<Unit, guardChecksWithState/4>;

/** Gets a node that is safely guarded by the given guard check. */
pragma[nomagic]
Node getABarrierNode() { result = StatefulBarrier::getABarrierNode(_) }
}

/**
* 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<StateSig State, WithState<State>::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<State, guardChecksSsaDef/4>;

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<State>::guardChecksDefSig/4 guardChecksSsaDef>
{
module SsaBarrierGuardWithState<StateSig State, WithState<State>::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 |
Expand Down
Loading