-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question - Variable initialization #7827
Comments
Thanks for your question. If I understand correctly you are trying to find where the pointer-values used as the second argument of |
Thanks for the reply! Yup I am currently using global taint tracking to catch the above code as To solve this, I am trying to catch the The current flow of the bug:
|
Hi @QWERTYz12, It sounds like you want flow from the value that’s pointed to by This isn't something our global taint tracking libraries support super well. The issue is that we see a "write" to One hack that you could do is to supply your taint configuration with an additional taint step that transfers taint between pointers which we know will have the same value at runtime. This can be done using the /**
* @kind path-problem
*/
import semmle.code.cpp.dataflow.TaintTracking
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
import DataFlow::PathGraph
class Conf extends TaintTracking::Configuration {
Conf() { this = "Conf" }
override predicate isSource(DataFlow::Node source) {
// The source is a value that's coming out of `recvfrom`'s second argument.
source.asDefiningArgument() =
any(Call call | call.getTarget().hasName("recvfrom")).getArgument(1)
}
override predicate isSink(DataFlow::Node sink) {
// The sink is a value that goes into `memcpy`'s third argument.
sink.asExpr() = any(Call call | call.getTarget().hasName("memcpy")).getArgument(2)
}
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
// Transfer flow from any value that's coming out of a function call, and into expressions
// which we know will have the same value at that point in the execution.
globalValueNumber(node1.asDefiningArgument()).getAnExpr() = node2.asExpr()
}
}
from Conf conf, DataFlow::PathNode source, DataFlow::PathNode sink
where conf.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "" This solution might not be very efficient on all projects, and it does potentially provide some false flow. But at least it gets the flow you want in this case! In the future, I hope we'll have a better solution to this issue so that you don't need to specify this additional taint step. I hope this helps :) |
Hi @MathiasVP, Thanks for the explanation and query! Appreciate it :) Yup I want to find the path flow from the value pointed to by I tried to run your query on my codebase but wasn't able to catch the bug. I realised that both Flow of the bug:
|
Hi, any updates on this question? |
Hi @QWERTYz12, Sorry. I missed your update on the issue. The query I created above does find the flow from char* mempool_alloc();
int recvfrom(int, char* buf, int len);
void* memcpy(void*, const void*, unsigned long);
typedef struct {
char* elem;
char elem2;
char elem3;
char elem4;
} S;
void test(int df, S* s) {
char* ptr = mempool_alloc();
s->elem = ptr;
recvfrom(df, s->elem, 10);
s->elem2 = *ptr; ptr++;
s->elem3 = *ptr; ptr++;
s->elem4 = *ptr; ptr += 2;
ptr += 16;
char id = *ptr; ptr++;
int len = *ptr - 2;
memcpy(s->elem, ptr, len);
} Can you show a complete example (that compiles) where we don't find the flow. |
Hi @MathiasVP, Sure no problem. The project that I'm working on is Thanks for the help! |
Hi! Any updates on this question? |
Hi @QWERTYz12, I'm trying to figure out why we're not finding the flow. It's a bit more complicated than I first anticipated based on the snippet with the flow of the bug :) I hope I'll have an update on it soon. Part of the issue is that |
Hey @MathiasVP! Are there any updates on this issue? |
No update yet. I'll be sure to post an update in here once I have something :) |
Sure, thanks alot @MathiasVP! |
Variable initialization (cpp)
Hi, I'm having problems trying to catch the first assignment of a variable in a function's argument.
For instance, catching the
struct->elem
variable fromrecvfrom
arg 2, and finding its first assignment whereby it is equated toptr
. Ultimately, I want to catch allptr
variables that are used in therecvfrom
function.Thanks for any help!
The text was updated successfully, but these errors were encountered: