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 support for MaD sources and sinks with access paths #18298

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

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Dec 16, 2024

Overview

This PR adds support for defining flow sources/sinks for Rust with non-trivial access paths. For example, one may define

extensions:
  - addsTo:
      pack: codeql/rust-all
      extensible: sourceModel
    data:
      - ["repo::test", "crate::my_option_source", "ReturnValue.Variant[crate::option::Option::Some(0)]", "test-source", "manual"]

which models calls to crate::my_option_source as flow sources of kind test-source, but where the origin of tainted data is not directly the result of the call, but rather stored inside Option::Some in the result of the call.

Similarly, one may define a sink restricted to data stored inside Option::Some:

extensions:
  - addsTo:
      pack: codeql/rust-all
      extensible: sinkModel
    data:
      - ["repo::test", "crate::my_option_sink", "Argument[0].Variant[crate::option::Option::Some(0)]", "test-sink", "manual"]

Implementation

The implementation piggy-backs on the existing FlowSummaryImpl library, which already has functionality for specifying flow summaries with non-trivial input/output access paths. For a flow source like my_option_source above, we synthesize a store step from synthetic source nodes to actual calls to my_option_source, and dually for sinks like my_option_sink, we synthesize read steps from arguments to synthetic sink nodes.

The functionality is currently limited to Rust, but other languages should be able to adopt relatively easily.

@github-actions github-actions bot added Rust Pull requests that update Rust code DataFlow Library labels Dec 16, 2024
@@ -175,6 +175,19 @@
sink(t.1); // $ hasValueFlow=11
}

// has a source model
fn enum_source(i: i64) -> MyFieldEnum {

Check notice

Code scanning / CodeQL

Unused variable Note test

Variable 'i' is not used.
@@ -175,6 +175,53 @@
sink(t.1); // $ hasValueFlow=11
}

impl MyFieldEnum {
// has a source model
fn source(&self, i: i64) -> MyFieldEnum {

Check notice

Code scanning / CodeQL

Unused variable Note test

Variable 'i' is not used.
}

// has a sink model
fn enum_sink(e: MyFieldEnum) {}

Check notice

Code scanning / CodeQL

Unused variable Note test

Variable 'e' is not used.
@hvitved hvitved force-pushed the rust/mad-source-sink branch from 707bebb to efbbea1 Compare December 17, 2024 14:52
@hvitved hvitved force-pushed the rust/mad-source-sink branch from efbbea1 to 67f7387 Compare December 18, 2024 09:46
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Dec 18, 2024
@hvitved hvitved marked this pull request as ready for review December 18, 2024 10:09
@hvitved hvitved requested review from a team as code owners December 18, 2024 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# C++ DataFlow Library Go Java no-change-note-required This PR does not need a change note Python Ruby Rust Pull requests that update Rust code Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant