Skip to content

Commit 5a4cd1c

Browse files
authored
Merge pull request #17661 from asgerf/shared/js-useuse-ssa-changes
SSA: Add BarrierGuardWithState
2 parents 9bfd461 + 1ce0ba5 commit 5a4cd1c

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

shared/ssa/codeql/ssa/Ssa.qll

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
private import codeql.util.Location
7+
private import codeql.util.Unit
78

89
/** Provides the input specification of the SSA implementation. */
910
signature module InputSig<LocationSig Location> {
@@ -1631,23 +1632,62 @@ module Make<LocationSig Location, InputSig<Location> Input> {
16311632
)
16321633
}
16331634

1635+
bindingset[this]
1636+
signature class StateSig;
1637+
1638+
private module WithState<StateSig State> {
1639+
/**
1640+
* Holds if the guard `g` validates the expression `e` upon evaluating to `branch`, blocking
1641+
* flow in the given `state`.
1642+
*
1643+
* The expression `e` is expected to be a syntactic part of the guard `g`.
1644+
* For example, the guard `g` might be a call `isSafe(x)` and the expression `e`
1645+
* the argument `x`.
1646+
*/
1647+
signature predicate guardChecksSig(
1648+
DfInput::Guard g, DfInput::Expr e, boolean branch, State state
1649+
);
1650+
}
1651+
16341652
/**
16351653
* Provides a set of barrier nodes for a guard that validates an expression.
16361654
*
16371655
* This is expected to be used in `isBarrier`/`isSanitizer` definitions
16381656
* in data flow and taint tracking.
16391657
*/
16401658
module BarrierGuard<guardChecksSig/3 guardChecks> {
1659+
private predicate guardChecksWithState(
1660+
DfInput::Guard g, DfInput::Expr e, boolean branch, Unit state
1661+
) {
1662+
guardChecks(g, e, branch) and exists(state)
1663+
}
1664+
1665+
private module StatefulBarrier = BarrierGuardWithState<Unit, guardChecksWithState/4>;
1666+
1667+
/** Gets a node that is safely guarded by the given guard check. */
1668+
pragma[nomagic]
1669+
Node getABarrierNode() { result = StatefulBarrier::getABarrierNode(_) }
1670+
}
1671+
1672+
/**
1673+
* Provides a set of barrier nodes for a guard that validates an expression.
1674+
*
1675+
* This is expected to be used in `isBarrier`/`isSanitizer` definitions
1676+
* in data flow and taint tracking.
1677+
*/
1678+
module BarrierGuardWithState<StateSig State, WithState<State>::guardChecksSig/4 guardChecks> {
16411679
pragma[nomagic]
1642-
private predicate guardChecksSsaDef(DfInput::Guard g, Definition def, boolean branch) {
1643-
guardChecks(g, DfInput::getARead(def), branch)
1680+
private predicate guardChecksSsaDef(
1681+
DfInput::Guard g, Definition def, boolean branch, State state
1682+
) {
1683+
guardChecks(g, DfInput::getARead(def), branch, state)
16441684
}
16451685

16461686
/** Gets a node that is safely guarded by the given guard check. */
16471687
pragma[nomagic]
1648-
Node getABarrierNode() {
1688+
Node getABarrierNode(State state) {
16491689
exists(DfInput::Guard g, boolean branch, Definition def, BasicBlock bb |
1650-
guardChecksSsaDef(g, def, branch)
1690+
guardChecksSsaDef(g, def, branch, state)
16511691
|
16521692
// guard controls a read
16531693
exists(DfInput::Expr e |

0 commit comments

Comments
 (0)