-
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
[C++] [Question] How to detect taint on elements in a collection #18098
Comments
I'm guessing you might have edited your code snippet leaving out some information (the However, trying out this example, it would indeed seem we don't currently track taint through vectors. I will ask my colleagues if it's really the case. In the meantime, this seems to cover your simple example, by defining additional flow steps: import cpp
import semmle.code.cpp.dataflow.new.TaintTracking
module TaintConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source.asExpr().(VariableAccess).getTarget().getName() = "sensitive_data"
}
predicate isAdditionalFlowStep(DataFlow::Node lhs, DataFlow::Node rhs) {
exists(ConstructorCall c | c.getTarget().getName() = ["vector", "initializer_list"]
and c = rhs.asExpr() and c.getAnArgument() = lhs.asExpr())
}
predicate isSink(DataFlow::Node sink) {
exists(Call c | c.getTarget().getName() = "potential_leak" and
c.getArgument(0) = sink.asExpr())
}
}
module Flow = TaintTracking::Global<TaintConfig>;
from DataFlow::Node src, DataFlow::Node sink
where Flow::flow(src, sink)
select src, "flow to $@", sink, sink.toString() notice however that modelling all ways in which an element can be inserted into a vector might be tricky ( |
|
Hi @redsun82, Thank you very much for looking into this. I did know that you modeled collections but I didn't realize they overtainted to the container itself. Nice. Sorry for the buggy code, I was trying to fix the indentation after copying it and I deleted too much by accident. So it seems I just ran into one of the unsupported methods 😅. Anyway your workaround appears to work, thanks a lot. Since I have you I have two related questions:
|
Hi @JustusAdam
No worries!
Well, not really: everything that models do can be done with explicit and careful coding of the About
Well, again, you could do that with additional taint steps. For example this (untested) snippet: import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
// anything that generates a store step into a vector type is now also an additional flow step that taints the whole vector
storeStep(node1, _, node2) and
node2.getType().hasQualifiedName("std", "", "vector")
} but in general we wouldn't recommend it.
How did Just for clarification, the fact that As for |
I am trying to detect the flow into
potential_leak
in the following, simplified code. This is just the minimal example, the vector can be constructed any way, e.g. with a series ifpush_back
or via iterator etc and I’m trying to find a way to reliably detect taint on any elements at the sink location. Also assume that I do not have access to the source code ofpotential_leak
and thus could detect the taint when the elements are accessed.My simplified query is
However this does not detect the flow. Is there some way to select the elements inside of
v
as sinks for this query?CodeQL version: 2.19.3
The text was updated successfully, but these errors were encountered: