-
Hello, I'm trying to expand the taint analysis module to also track control flow tainting. What this means is that if there are tainted values in the condition of an if/switch/loop statement, then any variables that change value in the body also become tainted.
I've written the query and I can see that such variables become tainted within the body, but it looks like the taint is not propagated outside of the body. This is a minimal example:
and
Create the db with: and execute the query with: In this example, we would expect Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @marpom, Thanks for your question. Looking at your imports, it seems that you already briefly explored the IR. The IR would indeed provided the easiest solution here, by looking at the /**
* @id cpp/test
* @kind path-problem
* @problem.severity warning
*/
import cpp
import semmle.code.cpp.dataflow.new.TaintTracking
import semmle.code.cpp.ir.IR
import SampleFlow::PathGraph
module SampleConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
exists(Function f | f.getName().matches("HandleWrite%") |
source.asParameter() = f.getParameter(0)
)
}
predicate isSink(DataFlow::Node sink) {
exists(FunctionCall c | c.getTarget().getName() = "outside_fun" |
c.getArgument(0) = sink.asExpr()
)
}
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
exists(Loop loopStmt |
loopStmt.getCondition().getAChild*() = nodeFrom.asExpr() and
nodeTo.asInstruction() instanceof StoreInstruction and
nodeTo.asInstruction().getAst().getEnclosingElement*() = loopStmt.getStmt()
)
}
}
module SampleFlow = TaintTracking::Global<SampleConfig>;
from SampleFlow::PathNode source, SampleFlow::PathNode sink
where SampleFlow::flowPath(source, sink)
select sink.getNode(), source, sink, "<message>" |
Beta Was this translation helpful? Give feedback.
Hi @marpom,
Thanks for your question.
Looking at your imports, it seems that you already briefly explored the IR. The IR would indeed provided the easiest solution here, by looking at the
StoreInstruction
s that happen in the body, and which will derive from the expressions in the body. Limiting myself to loop statements, slightly generalising the sources (for my own testing pusposes), and making the sink more specific. I would do something like the following: