Skip to content

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

Merged
paldepind merged 7 commits into
github:mainfrom
paldepind:rust-format
Jan 6, 2025
Merged

Rust: Value flow and taint flow through formatting strings#18394
paldepind merged 7 commits into
github:mainfrom
paldepind:rust-format

Conversation

@paldepind
Copy link
Copy Markdown
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
Comment thread rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll Fixed
@paldepind paldepind marked this pull request as ready for review January 3, 2025 18:07
Copy link
Copy Markdown
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.

result = e.(BreakExprCfgNode).getExpr() or
result = e.(BlockExprCfgNode).getTailExpr() or
result = e.(MatchExprCfgNode).getArmExpr(_) or
result = e.(MacroExprCfgNode).getMacroCall().(MacroCallCfgNode).getExpandedNode() or
Copy link
Copy Markdown
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
Copy Markdown
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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, let's leave it as-is then.

@@ -0,0 +1,2 @@
edges
Copy link
Copy Markdown
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
Copy Markdown
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?

@paldepind paldepind merged commit 7248fb7 into github:main Jan 6, 2025
@paldepind paldepind deleted the rust-format branch January 6, 2025 12:57
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.

3 participants