Skip to content

Commit b0a9ade

Browse files
committed
Data flow: Experiment
1 parent a756f86 commit b0a9ade

File tree

1 file changed

+92
-8
lines changed

1 file changed

+92
-8
lines changed

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,12 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
10191019
callEdgeReturn(call, c, _, _, _, _, _)
10201020
}
10211021

1022+
bindingset[node1, node2]
1023+
predicate storeReachesRead(NodeEx node1, NodeEx node2) {
1024+
exists(node1) and
1025+
exists(node2)
1026+
}
1027+
10221028
additional predicate stats(
10231029
boolean fwd, int nodes, int fields, int conscand, int states, int tuples, int calledges
10241030
) {
@@ -1314,6 +1320,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
13141320
predicate relevantCallEdgeIn(DataFlowCall call, DataFlowCallable c);
13151321

13161322
predicate relevantCallEdgeOut(DataFlowCall call, DataFlowCallable c);
1323+
1324+
bindingset[node1, node2]
1325+
predicate storeReachesRead(NodeEx node1, NodeEx node2);
13171326
}
13181327

13191328
private module MkStage<StageSig PrevStage> {
@@ -1512,9 +1521,10 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
15121521
)
15131522
or
15141523
// read
1515-
exists(Typ t0, Ap ap0, Content c |
1524+
exists(Typ t0, Ap ap0, Content c, NodeEx storeSource |
15161525
fwdFlowRead(t0, ap0, c, _, node, state, cc, summaryCtx, argT, argAp) and
1517-
fwdFlowConsCand(t0, ap0, c, t, ap) and
1526+
fwdFlowConsCand(storeSource, t0, ap0, c, t, ap) and
1527+
PrevStage::storeReachesRead(storeSource, node) and
15181528
apa = getApprox(ap)
15191529
)
15201530
or
@@ -1583,16 +1593,18 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
15831593
/**
15841594
* Holds if forward flow with access path `tail` and type `t1` reaches a
15851595
* store of `c` on a container of type `t2` resulting in access path
1586-
* `cons`.
1596+
* `cons`. `storeSource` is a node that may be stored into `c`.
15871597
*/
15881598
pragma[nomagic]
1589-
private predicate fwdFlowConsCand(Typ t2, Ap cons, Content c, Typ t1, Ap tail) {
1590-
fwdFlowStore(_, t1, tail, c, t2, _, _, _, _, _, _) and
1599+
private predicate fwdFlowConsCand(
1600+
NodeEx storeSource, Typ t2, Ap cons, Content c, Typ t1, Ap tail
1601+
) {
1602+
fwdFlowStore(storeSource, t1, tail, c, t2, _, _, _, _, _, _) and
15911603
cons = apCons(c, t1, tail)
15921604
or
15931605
exists(Typ t0 |
15941606
typeStrengthen(t0, cons, t2) and
1595-
fwdFlowConsCand(t0, cons, c, t1, tail)
1607+
fwdFlowConsCand(storeSource, t0, cons, c, t1, tail)
15961608
)
15971609
}
15981610

@@ -2041,9 +2053,10 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
20412053

20422054
pragma[nomagic]
20432055
private predicate readStepFwd(NodeEx n1, Ap ap1, Content c, NodeEx n2, Ap ap2) {
2044-
exists(Typ t1 |
2056+
exists(Typ t1, NodeEx storeSource |
20452057
fwdFlowRead(t1, ap1, c, n1, n2, _, _, _, _, _) and
2046-
fwdFlowConsCand(t1, ap1, c, _, ap2)
2058+
fwdFlowConsCand(storeSource, t1, ap1, c, _, ap2) and
2059+
PrevStage::storeReachesRead(storeSource, n2)
20472060
)
20482061
}
20492062

@@ -2487,6 +2500,77 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
24872500
callEdgeReturn(call, c, _, _, _, _, _)
24882501
}
24892502

2503+
private signature predicate storeReachesReadSig(NodeEx node1, NodeEx node2);
2504+
2505+
private newtype TNodeAndAp = MkNodeAndAp(TNodeEx node, Ap ap) { revFlow(node, _, _, _, ap) }
2506+
2507+
private module StoreReachesRead<storeReachesReadSig/2 storeReachesReadIn> {
2508+
pragma[nomagic]
2509+
private predicate step(TNodeAndAp n1, TNodeAndAp n2) {
2510+
exists(NodeEx node1, NodeEx node2, Ap ap, FlowState state1, FlowState state2 |
2511+
revFlow(node1, state1) and
2512+
revFlow(node2, state2) and
2513+
n1 = MkNodeAndAp(node1, pragma[only_bind_into](ap)) and
2514+
n2 = MkNodeAndAp(node2, pragma[only_bind_into](ap))
2515+
|
2516+
localStep(node1, state1, node2, state2, true, _, _)
2517+
or
2518+
jumpStepEx(node1, node2)
2519+
or
2520+
callEdgeArgParam(_, _, node1, node2, _, _)
2521+
or
2522+
callEdgeReturn(_, _, node1, _, node2, _, _)
2523+
or
2524+
storeReachesReadIn(node1, node2)
2525+
)
2526+
}
2527+
2528+
private predicate isStoreTarget(TNodeAndAp n) {
2529+
exists(NodeEx node, Ap ap |
2530+
n = MkNodeAndAp(node, ap) and
2531+
storeStepCand(_, _, _, node, _, _)
2532+
)
2533+
}
2534+
2535+
private predicate isReadSource(TNodeAndAp n) {
2536+
exists(NodeEx node, Ap ap |
2537+
n = MkNodeAndAp(node, ap) and
2538+
readStepCand(node, _, _)
2539+
)
2540+
}
2541+
2542+
private predicate storeReachesReadTc(TNodeAndAp node1, TNodeAndAp node2) =
2543+
doublyBoundedFastTC(step/2, isStoreTarget/1, isReadSource/1)(node1, node2)
2544+
2545+
pragma[nomagic]
2546+
predicate storeReachesReadOut(NodeEx node1, NodeEx node2) {
2547+
exists(Content c, NodeEx storeTarget, NodeEx readSource |
2548+
storeReachesReadTc(MkNodeAndAp(storeTarget, _), MkNodeAndAp(readSource, _)) and
2549+
storeStepCand(node1, _, c, storeTarget, _, _) and
2550+
readStepCand(readSource, c, node2)
2551+
)
2552+
}
2553+
}
2554+
2555+
private predicate storeReachesRead0(NodeEx node1, NodeEx node2) { none() }
2556+
2557+
private predicate storeReachesRead1 =
2558+
StoreReachesRead<storeReachesRead0/2>::storeReachesReadOut/2;
2559+
2560+
private predicate storeReachesRead2 =
2561+
StoreReachesRead<storeReachesRead1/2>::storeReachesReadOut/2;
2562+
2563+
private predicate storeReachesRead3 =
2564+
StoreReachesRead<storeReachesRead2/2>::storeReachesReadOut/2;
2565+
2566+
private predicate storeReachesRead4 =
2567+
StoreReachesRead<storeReachesRead3/2>::storeReachesReadOut/2;
2568+
2569+
private predicate storeReachesRead5 =
2570+
StoreReachesRead<storeReachesRead4/2>::storeReachesReadOut/2;
2571+
2572+
predicate storeReachesRead = storeReachesRead5/2;
2573+
24902574
additional predicate stats(
24912575
boolean fwd, int nodes, int fields, int conscand, int states, int tuples, int calledges,
24922576
int tfnodes, int tftuples

0 commit comments

Comments
 (0)