[C/C++] Is it possible to set the left-hand side of an assignment operation as the sink node in CodeQL's data flow analysis? #16046
-
Example: struct Foo {
int x;
int y;
char z[];
};
void func_bar() {
int len;
struct Foo* sink;
len = source; // just assume it is source. XD [1]
sink = some_malloc(len); // sink is affected by the argument `len` [2]
sink->y = 1; // some field of sink is modified. [3]
} The dataflow goes from Given this example, if source is fully controllable, then sink->y itself could be a potential overflow access because source could be 0. There are many such examples in the Linux kernel. A value is assigned to a field in a function, and this field is not used again before returning to user space, resulting in no corresponding data flow record. So I wonder if there is a way to track the dataflow to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi Roarcannotprogramming, So you're successfully tracking flow from Indeed, the problem is that we don't allow flow from predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
exists(FieldAccess fa, Field f |
fa.getTarget() = f and
f.hasName("y") and
f.getDeclaringType().hasName("Foo") and
node1.asIndirectExpr() = fa.getQualifier() and
node2.asExpr() = fa
)
} Does that help? |
Beta Was this translation helpful? Give feedback.
Hi Roarcannotprogramming,
So you're successfully tracking flow from
source
into the argument ofsome_malloc
, but then you want to track where the return value ofsome_malloc
flows to. And you would like to track this all the way to the left-hand side of the assignment. Is that correct?Indeed, the problem is that we don't allow flow from
sink
tosink->y
without having previously seen a write toy
. You can add such a taint-step yourself by doing something like: