Skip to content
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

Rust: Value flow and taint flow through formatting strings #18394

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

paldepind
Copy link
Contributor

@paldepind paldepind commented Jan 3, 2025

This PR adds:

  • Value flow through macro calls.
  • Taint flow from arguments (including those in format strings) to format_args! to the format_args! expression itself.
  • Adds two models for standard library functions used in format!.

The original goal was to get taint through the format! macro. But since its definition uses a let statement, the issue in #18330 prevents that from working. Once that is fixed, the changes here should give flow through fomat!.

MacroCall AST nodes are now included in the CFG in post-order. Previously they where skipped over and not included in the CFG, but this caused the getMacroCall predicate on MacroExprCfgNode to never have any results. Including them in the CFG fixes that, and I don't think there's any reason to exclude them.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jan 3, 2025
@paldepind paldepind marked this pull request as ready for review January 3, 2025 18:07
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some small comments.

@@ -522,6 +522,7 @@ private ExprCfgNode getALastEvalNode(ExprCfgNode e) {
result = e.(BreakExprCfgNode).getExpr() or
result = e.(BlockExprCfgNode).getTailExpr() or
result = e.(MatchExprCfgNode).getArmExpr(_) or
result = e.(MacroExprCfgNode).getMacroCall().(MacroCallCfgNode).getExpandedNode() or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this rather be

result = e.(MacroExprCfgNode).getMacroCall() or
result = e.(MacroCallCfgNode).getExpandedNode() or

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually yes, but MacroCall is not an expression and doesn't have a node in the data-flow graph, so it won't work. To do that I think we'd have to change the type of getALastEvalNode and add a new kind of data-flow node for MacroCall.

ThaSo just adding a step over the MacroCall seems simpler and is also what we do for the other kind of nodes that have their expression nested further down.

We could add a method on MacroExprCfgNode to get the expanded node directly?

@@ -0,0 +1,2 @@
edges
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be removed again.

@@ -0,0 +1,122 @@
localStep
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the corresponding .ql test missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants