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: Add basic skeleton setup for data flow #17871

Merged
merged 2 commits into from
Oct 31, 2024

Conversation

paldepind
Copy link
Contributor

This PR adds the basic setup for data flow and taint tracking with the goal that

  • The QL compiles and is suitable for building on top of.
  • The external API for the data flow library and taint tracking is in place, such that queries can be written against them.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Oct 30, 2024
"source"
}

fn sink(s: &str) {

Check notice

Code scanning / CodeQL

Unused variable Note test

Variable 's' is not used.
@paldepind paldepind force-pushed the rust-data-flow-skeleton branch from 4f855c5 to 7217469 Compare October 30, 2024 12:04
@paldepind paldepind force-pushed the rust-data-flow-skeleton branch from 7217469 to 44bebed Compare October 30, 2024 12:16
@paldepind
Copy link
Contributor Author

The qldoc CI job is failling with the errors below. I'm not sure why it's complaining about these modules, as they're preexisting modules?

Warning: Missing QLdoc for module DataFlow::Configs
Warning: Missing QLdoc for module DataFlow::DataFlowMake

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, only some minor things. I think it would also be nice to enable the consistency checks, see e.g. https://github.com/github/codeql/blob/main/ruby/ql/consistency-queries/DataFlowConsistency.ql.


private import rust
private import codeql.dataflow.DataFlow
private import internal.DataFlowImpl as DataFlowImpl
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the as DataFlowImpl bit is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it for this line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, that goes away with the other suggested changes 😄

/**
* Gets the expression that corresponds to this node, if any.
*/
Expr asExpr() { none() }
Copy link
Contributor

Choose a reason for hiding this comment

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

The return type here should be CfgNode, because we will base data flow on the CFG and not on the AST.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me it seems a bit confusing for users and query writers if asExpr doesn't return an expression? There is also another predicate getCfgNode to get a CFG node.

From a quick grep it seems that in Swift, Go, Java, C++, and C# the asExpr predicate gives an expression. Only in Ruby does it give a CFG node.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave it at Expr, for now, and then change it once we have a proper Expr layer on top of CfgNode.

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll Outdated Show resolved Hide resolved
rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll Outdated Show resolved Hide resolved
rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll Outdated Show resolved Hide resolved
rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll Outdated Show resolved Hide resolved
rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll Outdated Show resolved Hide resolved
private module Cached {
cached
newtype TNode =
TExprNode(CfgNode n, Expr e) or
Copy link
Contributor

Choose a reason for hiding this comment

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

Cartesian product

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is now

    TExprNode(CfgNode n, Expr e) { n.getAstNode() = e } or

@paldepind paldepind merged commit b96698a into github:main Oct 31, 2024
14 of 15 checks passed
@paldepind paldepind deleted the rust-data-flow-skeleton branch October 31, 2024 07:26
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