Help: How to propagate tainting to the origin of a reference in C #15204
Replies: 3 comments
-
After some experimentation and trial and error, I figured that adding the following
This might be overly complicated as I am still to understand it fully, but my analysis is the following. For the sample code I provided, when tainting gets successfully propagated, Now, my interpretation of why these values, and please take in mind that it might be utterly wrong as I don't know what is going on, is that codeql at some point asks itself if the access of the Thus, my In other words: take an additional taint step if the variable access has been involved with the results of the function call I'd still like to know more on the why of this behaviour, and if my assessment is correct tho :) |
Beta Was this translation helpful? Give feedback.
-
Hi @thatjiaozi, I've asked internally how to best deal with this. It might be a while before I get an answer, because people are still on holiday after New Year's. |
Beta Was this translation helpful? Give feedback.
-
Hi @thatjiaozi, What you want is in fact not supported. |
Beta Was this translation helpful? Give feedback.
-
I currently have the following query, its purpose is to find all places where an unsigned integer gets assigned to a signed variable and then, using TaintTracking check if that signed value ends up in a call to
malloc
:(apologies in advance if I am doing something sub-optimal, this is the first time I use codeql)
The query works mostly fine, except for one corner case, consider the following dummy program:
in the code above, we can see that the pointer
child_struct
is a reference to the nested struct ininstance
.child_struct
is also where the assignment ofu32
to anint
takes place.The first
malloc
call is successfully detected by the query above, however, the second call, the one insideallocate_buffer
is not detected.IIUC this is all because
child_struct
gets tainted with theread_input
call's results, but notinstance->nested_struct.len
.My question is: what is the correct way to instruct codeql to propagate the tainting so that the second malloc call gets detected?
Scouting the documentation it seems that isAdditionalTaintStep function might do the trick, but I wanted to make sure this was the right path before going down the rabbit hole.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions