Skip to content

Rust: Add support for neutral models.#21271

Open
geoffw0 wants to merge 5 commits intogithub:mainfrom
geoffw0:neutralmodels
Open

Rust: Add support for neutral models.#21271
geoffw0 wants to merge 5 commits intogithub:mainfrom
geoffw0:neutralmodels

Conversation

@geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Feb 5, 2026

Neutral models are models that neutralize generated models, allowing us to correct false positives caused by inaccurate generated models.

Sadly I was unable to produce an effective test for neutral summary models, since generated summary models of functions from the source aren't applied anyway, and it's difficult to add functions outside the source in tests. We will soon have neutral summaries of real library functions to test this feature anyway.

@geoffw0 geoffw0 added the Rust Pull requests that update Rust code label Feb 5, 2026
@geoffw0 geoffw0 requested a review from a team as a code owner February 5, 2026 09:00
Copilot AI review requested due to automatic review settings February 5, 2026 09:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for neutral models to the Rust dataflow analysis framework. Neutral models allow developers to explicitly disable generated or inherited source, sink, and summary models for specific functions, helping to correct false positives caused by inaccurate auto-generated models.

Changes:

  • Added neutralModel extensible predicate to define neutral models
  • Modified source, sink, and summary model application logic to respect neutral models
  • Added comprehensive test coverage for neutral models with sources and sinks
  • Added change notes documenting this new capability

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll Adds the neutralModel extensible predicate and implements logic to filter out generated/inherited models when neutral models exist for the same function
rust/ql/test/library-tests/dataflow/models/models.ext.yml Adds test data for neutral models including both generated and manual models with corresponding neutral models
rust/ql/test/library-tests/dataflow/models/main.rs Adds test functions and test case to verify neutral model behavior
rust/ql/test/library-tests/dataflow/models/models.expected Updates expected test output to reflect new test cases
rust/ql/lib/change-notes/2026-02-05-neutral-models.md Documents the new neutral models feature

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.

Sadly I was unable to produce an effective test for neutral summary models, since generated summary models of functions from the source aren't applied anyway, and it's difficult to add functions outside the source in tests.

Here is an idea: Add a new extensional predicate extensible predicate stub(string relativePath), add not stub(this.getRelativePath()) here, move the relevant functions into a separate file, say stubs.rs, and then add an entry for that file in models.ext.yml.

Comment on lines 158 to 159
) and
not neutralModel(f.getCanonicalPath(), "summary", _, _)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be needed, as it is handled by the shared library.

@geoffw0
Copy link
Contributor Author

geoffw0 commented Feb 5, 2026

@hvitved thanks for your suggestions, there's something else I need to work on before I get back to this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants