Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
Rust, shared: Support Parameter in source MaD models#20452
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
cd8075305a5832014c27e265e8b37d6e206a4c61f64244a6545b84ff1183e50File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| category: feature | ||
| --- | ||
| * The models-as-data format for sources now supports access paths of the form | ||
| `Argument[i].Parameter[j]`. This denotes that the source passes tainted data to | ||
| the `j`th parameter of its `i`th argument (which must be a function or a | ||
| closure). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,7 +6,10 @@ private import rust | ||
| private import codeql.dataflow.internal.FlowSummaryImpl | ||
| private import codeql.dataflow.internal.AccessPathSyntax as AccessPath | ||
| private import codeql.rust.dataflow.internal.DataFlowImpl | ||
| private import codeql.rust.internal.PathResolution | ||
| private import codeql.rust.dataflow.FlowSummary | ||
| private import codeql.rust.dataflow.Ssa | ||
| private import codeql.rust.controlflow.CfgNodes | ||
| private import Content | ||
| module Input implements InputSig<Location, RustDataFlow> { | ||
| @@ -133,16 +136,44 @@ private module StepsInput implements Impl::Private::StepsInputSig { | ||
| result.asCallCfgNode().getCall().getStaticTarget() = sc | ||
| } | ||
| RustDataFlow::Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponent sc) { | ||
| sc = Impl::Private::SummaryComponent::return(_) and | ||
| /** Gets the argument of `source` described by `sc`, if any. */ | ||
| private Expr getSourceNodeArgument(Input::SourceBase source, Impl::Private::SummaryComponent sc) { | ||
| exists(ArgumentPosition pos | | ||
| sc = Impl::Private::SummaryComponent::argument(pos) and | ||
| result = pos.getArgument(source.getCall()) | ||
| ) | ||
| } | ||
| /** Get the callable that `expr` refers to. */ | ||
| private Callable getCallable(Expr expr) { | ||
| result = resolvePath(expr.(PathExpr).getPath()).(Function) | ||
| or | ||
| result = expr.(ClosureExpr) | ||
| or | ||
| // The expression is an SSA read of an assignment of a closure | ||
| exists(Ssa::Definition def, ExprCfgNode value | | ||
| def.getARead().getAstNode() = expr and | ||
| def.getAnUltimateDefinition().(Ssa::WriteDefinition).assigns(value) and | ||
| result = value.getExpr().(ClosureExpr) | ||
| ) | ||
| } | ||
| RustDataFlow::DataFlowCallable getSourceNodeEnclosingCallable(Input::SourceBase source) { | ||
| result.asCfgScope() = source.getEnclosingCfgScope() | ||
| } | ||
| RustDataFlow::Node getSourceNode(Input::SourceBase source, Impl::Private::SummaryComponentStack s) { | ||
| s.head() = Impl::Private::SummaryComponent::return(_) and | ||
| result.asExpr().getExpr() = source.getCall() | ||
| or | ||
| exists(CallExprBase call, Expr arg, ArgumentPosition pos | | ||
| result.(RustDataFlow::PostUpdateNode).getPreUpdateNode().asExpr().getExpr() = arg and | ||
| sc = Impl::Private::SummaryComponent::argument(pos) and | ||
| call = source.getCall() and | ||
| arg = pos.getArgument(call) | ||
| exists(ArgumentPosition pos, Expr arg | | ||
| s.head() = Impl::Private::SummaryComponent::parameter(pos) and | ||
| arg = getSourceNodeArgument(source, s.tail().headOfSingleton()) and | ||
| result.asParameter() = getCallable(arg).getParam(pos.getPosition()) | ||
paldepind marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ) | ||
| or | ||
| result.(RustDataFlow::PostUpdateNode).getPreUpdateNode().asExpr().getExpr() = | ||
| getSourceNodeArgument(source, s.headOfSingleton()) | ||
| } | ||
| RustDataFlow::Node getSinkNode(Input::SinkBase sink, Impl::Private::SummaryComponent sc) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -34,10 +34,9 @@ private module FlowTestImpl implements InputSig<Location, RustDataFlow> { | ||
| result = src.asExpr().(CallExprCfgNode).getArgument(0).toString() | ||
| or | ||
| sourceNode(src, _) and | ||
| exists(CallExprBase call | | ||
| call = src.(Node::FlowSummaryNode).getSourceElement().getCall() and | ||
| result = call.getArgList().getArg(0).toString() | ||
| ) | ||
| result = src.(Node::FlowSummaryNode).getSourceElement().getCall().getArg(0).toString() and | ||
| // Don't use the result if it contains spaces | ||
| not result.matches("% %") | ||
geoffw0 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| bindingset[src, sink] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| multipleCallTargets | ||
| | main.rs:362:14:362:30 | ... .lt(...) | | ||
| | main.rs:389:14:389:30 | ... .lt(...) | |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware this was possible in Rust; we don't currently handle it in normal data flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't thought of this. I'm working on fixing this.