-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Models-as-data for flow summaries #18231
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /** | ||
| * Defines extensible predicates for contributing library models from data extensions. | ||
| */ | ||
|
|
||
| private import rust | ||
| private import codeql.rust.dataflow.FlowSummary | ||
|
|
||
| /** | ||
| * Holds if in a call to the function with canonical path `path`, defined in the | ||
| * crate `crate`, the value referred to by `output` is a flow source of the given | ||
| * `kind`. | ||
| * | ||
| * `output = "ReturnValue"` simply means the result of the call itself. | ||
| * | ||
| * The following kinds are supported: | ||
| * | ||
| * - `remote`: a general remote flow source. | ||
geoffw0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| extensible predicate sourceModel( | ||
|
||
| string crate, string path, string output, string kind, string provenance, | ||
| QlBuiltins::ExtensionId madId | ||
| ); | ||
|
|
||
| /** | ||
| * Holds if in a call to the function with canonical path `path`, defined in the | ||
| * crate `crate`, the value referred to by `input` is a flow sink of the given | ||
| * `kind`. | ||
| * | ||
| * For example, `input = Argument[0]` means the first argument of the call. | ||
| * | ||
| * The following kinds are supported: | ||
| * | ||
| * - `sql-injection`: a flow sink for SQL injection. | ||
| */ | ||
| extensible predicate sinkModel( | ||
| string crate, string path, string input, string kind, string provenance, | ||
| QlBuiltins::ExtensionId madId | ||
| ); | ||
|
|
||
| /** | ||
| * Holds if in a call to the function with canonical path `path`, defined in the | ||
| * crate `crate`, the value referred to by `input` can flow to the value referred | ||
| * to by `output`. | ||
| * | ||
| * `kind` should be either `value` or `taint`, for value-preserving or taint-preserving | ||
| * steps, respectively. | ||
| */ | ||
| extensible predicate summaryModel( | ||
| string crate, string path, string input, string output, string kind, string provenance, | ||
| QlBuiltins::ExtensionId madId | ||
| ); | ||
|
|
||
| /** | ||
| * Holds if the given extension tuple `madId` should pretty-print as `model`. | ||
| * | ||
| * This predicate should only be used in tests. | ||
| */ | ||
| predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) { | ||
| exists(string crate, string path, string output, string kind | | ||
| sourceModel(crate, path, kind, output, _, madId) and | ||
| model = "Source: " + crate + "; " + path + "; " + output + "; " + kind | ||
| ) | ||
| or | ||
| exists(string crate, string path, string input, string kind | | ||
| sinkModel(crate, path, kind, input, _, madId) and | ||
| model = "Sink: " + crate + "; " + path + "; " + input + "; " + kind | ||
| ) | ||
| or | ||
| exists(string type, string path, string input, string output, string kind | | ||
| summaryModel(type, path, input, output, kind, _, madId) and | ||
| model = "Summary: " + type + "; " + path + "; " + input + "; " + output + "; " + kind | ||
| ) | ||
| } | ||
|
|
||
| private class SummarizedCallableFromModel extends SummarizedCallable::Range { | ||
| private string crate; | ||
| private string path; | ||
|
|
||
| SummarizedCallableFromModel() { | ||
| summaryModel(crate, path, _, _, _, _, _) and | ||
| this = crate + "::_::" + path | ||
| } | ||
|
|
||
| override predicate propagatesFlow( | ||
| string input, string output, boolean preservesValue, string model | ||
| ) { | ||
| exists(string kind, QlBuiltins::ExtensionId madId | | ||
| summaryModel(crate, path, input, output, kind, _, madId) and | ||
| model = "MaD:" + madId.toString() | ||
| | | ||
| kind = "value" and | ||
| preservesValue = true | ||
| or | ||
| kind = "taint" and | ||
| preservesValue = false | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| extensions: | ||
| # Make sure that the extensible model predicates have at least one definition | ||
| # to avoid errors about undefined extensionals. | ||
| - addsTo: | ||
| pack: codeql/rust-all | ||
| extensible: sourceModel | ||
| data: [] | ||
|
|
||
| - addsTo: | ||
| pack: codeql/rust-all | ||
| extensible: sinkModel | ||
| data: [] | ||
|
|
||
| - addsTo: | ||
| pack: codeql/rust-all | ||
| extensible: summaryModel | ||
| data: [] |
6 changes: 6 additions & 0 deletions
6
rust/ql/lib/codeql/rust/frameworks/stdlib/lang-core.model.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| extensions: | ||
| - addsTo: | ||
| pack: codeql/rust-all | ||
| extensible: summaryModel | ||
| data: | ||
| - ["lang:core", "<crate::option::Option>::unwrap", "Argument[self].Variant[crate::option::Option::Some(0)]", "ReturnValue", "value", "manual"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.