|
| 1 | +/** |
| 2 | + * Provides an implementation of global (interprocedural) data flow. This file |
| 3 | + * re-exports the local (intraprocedural) data flow analysis from |
| 4 | + * `DataFlowImplSpecific::Public` and adds a global analysis, mainly exposed |
| 5 | + * through the `Make` and `MakeWithState` modules. |
| 6 | + */ |
| 7 | + |
| 8 | +private import DataFlowImplCommon |
| 9 | +private import DataFlowImplSpecific::Private |
| 10 | +import DataFlowImplSpecific::Public |
| 11 | +import DataFlowImplCommonPublic |
| 12 | +private import DataFlowImpl |
| 13 | + |
| 14 | +/** An input configuration for data flow. */ |
| 15 | +signature module ConfigSig { |
| 16 | + /** |
| 17 | + * Holds if `source` is a relevant data flow source. |
| 18 | + */ |
| 19 | + predicate isSource(Node source); |
| 20 | + |
| 21 | + /** |
| 22 | + * Holds if `sink` is a relevant data flow sink. |
| 23 | + */ |
| 24 | + predicate isSink(Node sink); |
| 25 | + |
| 26 | + /** |
| 27 | + * Holds if data flow through `node` is prohibited. This completely removes |
| 28 | + * `node` from the data flow graph. |
| 29 | + */ |
| 30 | + default predicate isBarrier(Node node) { none() } |
| 31 | + |
| 32 | + /** Holds if data flow into `node` is prohibited. */ |
| 33 | + default predicate isBarrierIn(Node node) { none() } |
| 34 | + |
| 35 | + /** Holds if data flow out of `node` is prohibited. */ |
| 36 | + default predicate isBarrierOut(Node node) { none() } |
| 37 | + |
| 38 | + /** |
| 39 | + * Holds if data may flow from `node1` to `node2` in addition to the normal data-flow steps. |
| 40 | + */ |
| 41 | + default predicate isAdditionalFlowStep(Node node1, Node node2) { none() } |
| 42 | + |
| 43 | + /** |
| 44 | + * Holds if an arbitrary number of implicit read steps of content `c` may be |
| 45 | + * taken at `node`. |
| 46 | + */ |
| 47 | + default predicate allowImplicitRead(Node node, ContentSet c) { none() } |
| 48 | + |
| 49 | + /** |
| 50 | + * Gets the virtual dispatch branching limit when calculating field flow. |
| 51 | + * This can be overridden to a smaller value to improve performance (a |
| 52 | + * value of 0 disables field flow), or a larger value to get more results. |
| 53 | + */ |
| 54 | + default int fieldFlowBranchLimit() { result = 2 } |
| 55 | + |
| 56 | + /** |
| 57 | + * Gets a data flow configuration feature to add restrictions to the set of |
| 58 | + * valid flow paths. |
| 59 | + * |
| 60 | + * - `FeatureHasSourceCallContext`: |
| 61 | + * Assume that sources have some existing call context to disallow |
| 62 | + * conflicting return-flow directly following the source. |
| 63 | + * - `FeatureHasSinkCallContext`: |
| 64 | + * Assume that sinks have some existing call context to disallow |
| 65 | + * conflicting argument-to-parameter flow directly preceding the sink. |
| 66 | + * - `FeatureEqualSourceSinkCallContext`: |
| 67 | + * Implies both of the above and additionally ensures that the entire flow |
| 68 | + * path preserves the call context. |
| 69 | + * |
| 70 | + * These features are generally not relevant for typical end-to-end data flow |
| 71 | + * queries, but should only be used for constructing paths that need to |
| 72 | + * somehow be pluggable in another path context. |
| 73 | + */ |
| 74 | + default FlowFeature getAFeature() { none() } |
| 75 | + |
| 76 | + /** Holds if sources should be grouped in the result of `hasFlowPath`. */ |
| 77 | + default predicate sourceGrouping(Node source, string sourceGroup) { none() } |
| 78 | + |
| 79 | + /** Holds if sinks should be grouped in the result of `hasFlowPath`. */ |
| 80 | + default predicate sinkGrouping(Node sink, string sinkGroup) { none() } |
| 81 | + |
| 82 | + /** |
| 83 | + * Holds if hidden nodes should be included in the data flow graph. |
| 84 | + * |
| 85 | + * This feature should only be used for debugging or when the data flow graph |
| 86 | + * is not visualized (as it is in a `path-problem` query). |
| 87 | + */ |
| 88 | + default predicate includeHiddenNodes() { none() } |
| 89 | +} |
| 90 | + |
| 91 | +/** An input configuration for data flow using flow state. */ |
| 92 | +signature module StateConfigSig { |
| 93 | + bindingset[this] |
| 94 | + class FlowState; |
| 95 | + |
| 96 | + /** |
| 97 | + * Holds if `source` is a relevant data flow source with the given initial |
| 98 | + * `state`. |
| 99 | + */ |
| 100 | + predicate isSource(Node source, FlowState state); |
| 101 | + |
| 102 | + /** |
| 103 | + * Holds if `sink` is a relevant data flow sink accepting `state`. |
| 104 | + */ |
| 105 | + predicate isSink(Node sink, FlowState state); |
| 106 | + |
| 107 | + /** |
| 108 | + * Holds if data flow through `node` is prohibited. This completely removes |
| 109 | + * `node` from the data flow graph. |
| 110 | + */ |
| 111 | + default predicate isBarrier(Node node) { none() } |
| 112 | + |
| 113 | + /** |
| 114 | + * Holds if data flow through `node` is prohibited when the flow state is |
| 115 | + * `state`. |
| 116 | + */ |
| 117 | + predicate isBarrier(Node node, FlowState state); |
| 118 | + |
| 119 | + /** Holds if data flow into `node` is prohibited. */ |
| 120 | + default predicate isBarrierIn(Node node) { none() } |
| 121 | + |
| 122 | + /** Holds if data flow out of `node` is prohibited. */ |
| 123 | + default predicate isBarrierOut(Node node) { none() } |
| 124 | + |
| 125 | + /** |
| 126 | + * Holds if data may flow from `node1` to `node2` in addition to the normal data-flow steps. |
| 127 | + */ |
| 128 | + default predicate isAdditionalFlowStep(Node node1, Node node2) { none() } |
| 129 | + |
| 130 | + /** |
| 131 | + * Holds if data may flow from `node1` to `node2` in addition to the normal data-flow steps. |
| 132 | + * This step is only applicable in `state1` and updates the flow state to `state2`. |
| 133 | + */ |
| 134 | + predicate isAdditionalFlowStep(Node node1, FlowState state1, Node node2, FlowState state2); |
| 135 | + |
| 136 | + /** |
| 137 | + * Holds if an arbitrary number of implicit read steps of content `c` may be |
| 138 | + * taken at `node`. |
| 139 | + */ |
| 140 | + default predicate allowImplicitRead(Node node, ContentSet c) { none() } |
| 141 | + |
| 142 | + /** |
| 143 | + * Gets the virtual dispatch branching limit when calculating field flow. |
| 144 | + * This can be overridden to a smaller value to improve performance (a |
| 145 | + * value of 0 disables field flow), or a larger value to get more results. |
| 146 | + */ |
| 147 | + default int fieldFlowBranchLimit() { result = 2 } |
| 148 | + |
| 149 | + /** |
| 150 | + * Gets a data flow configuration feature to add restrictions to the set of |
| 151 | + * valid flow paths. |
| 152 | + * |
| 153 | + * - `FeatureHasSourceCallContext`: |
| 154 | + * Assume that sources have some existing call context to disallow |
| 155 | + * conflicting return-flow directly following the source. |
| 156 | + * - `FeatureHasSinkCallContext`: |
| 157 | + * Assume that sinks have some existing call context to disallow |
| 158 | + * conflicting argument-to-parameter flow directly preceding the sink. |
| 159 | + * - `FeatureEqualSourceSinkCallContext`: |
| 160 | + * Implies both of the above and additionally ensures that the entire flow |
| 161 | + * path preserves the call context. |
| 162 | + * |
| 163 | + * These features are generally not relevant for typical end-to-end data flow |
| 164 | + * queries, but should only be used for constructing paths that need to |
| 165 | + * somehow be pluggable in another path context. |
| 166 | + */ |
| 167 | + default FlowFeature getAFeature() { none() } |
| 168 | + |
| 169 | + /** Holds if sources should be grouped in the result of `hasFlowPath`. */ |
| 170 | + default predicate sourceGrouping(Node source, string sourceGroup) { none() } |
| 171 | + |
| 172 | + /** Holds if sinks should be grouped in the result of `hasFlowPath`. */ |
| 173 | + default predicate sinkGrouping(Node sink, string sinkGroup) { none() } |
| 174 | + |
| 175 | + /** |
| 176 | + * Holds if hidden nodes should be included in the data flow graph. |
| 177 | + * |
| 178 | + * This feature should only be used for debugging or when the data flow graph |
| 179 | + * is not visualized (as it is in a `path-problem` query). |
| 180 | + */ |
| 181 | + default predicate includeHiddenNodes() { none() } |
| 182 | +} |
| 183 | + |
| 184 | +/** |
| 185 | + * Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev` |
| 186 | + * measured in approximate number of interprocedural steps. |
| 187 | + */ |
| 188 | +signature int explorationLimitSig(); |
| 189 | + |
| 190 | +/** |
| 191 | + * The output of a data flow computation. |
| 192 | + */ |
| 193 | +signature module DataFlowSig { |
| 194 | + /** |
| 195 | + * A `Node` augmented with a call context (except for sinks) and an access path. |
| 196 | + * Only those `PathNode`s that are reachable from a source, and which can reach a sink, are generated. |
| 197 | + */ |
| 198 | + class PathNode; |
| 199 | + |
| 200 | + /** |
| 201 | + * Holds if data can flow from `source` to `sink`. |
| 202 | + * |
| 203 | + * The corresponding paths are generated from the end-points and the graph |
| 204 | + * included in the module `PathGraph`. |
| 205 | + */ |
| 206 | + predicate hasFlowPath(PathNode source, PathNode sink); |
| 207 | + |
| 208 | + /** |
| 209 | + * Holds if data can flow from `source` to `sink`. |
| 210 | + */ |
| 211 | + predicate hasFlow(Node source, Node sink); |
| 212 | + |
| 213 | + /** |
| 214 | + * Holds if data can flow from some source to `sink`. |
| 215 | + */ |
| 216 | + predicate hasFlowTo(Node sink); |
| 217 | + |
| 218 | + /** |
| 219 | + * Holds if data can flow from some source to `sink`. |
| 220 | + */ |
| 221 | + predicate hasFlowToExpr(DataFlowExpr sink); |
| 222 | +} |
| 223 | + |
| 224 | +/** |
| 225 | + * Constructs a standard data flow computation. |
| 226 | + */ |
| 227 | +module Make<ConfigSig Config> implements DataFlowSig { |
| 228 | + private module C implements FullStateConfigSig { |
| 229 | + import DefaultState<Config> |
| 230 | + import Config |
| 231 | + } |
| 232 | + |
| 233 | + import Impl<C> |
| 234 | +} |
| 235 | + |
| 236 | +/** |
| 237 | + * Constructs a data flow computation using flow state. |
| 238 | + */ |
| 239 | +module MakeWithState<StateConfigSig Config> implements DataFlowSig { |
| 240 | + private module C implements FullStateConfigSig { |
| 241 | + import Config |
| 242 | + } |
| 243 | + |
| 244 | + import Impl<C> |
| 245 | +} |
0 commit comments