Skip to content

Rust: regenerate models - #19748

Merged
redsun82 merged 2 commits into
mainfrom
redsun82/rust-models
Jun 16, 2025
Merged

Rust: regenerate models#19748
redsun82 merged 2 commits into
mainfrom
redsun82/rust-models

Conversation

@redsun82

@redsun82redsun82 commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

Models are regenerated with the fix from #19744 which corrects the order of generation.

Notice the one new FP in the tests though.

Models are regenerated with the fix from #19744
which corrects the order of generation.
@github-actionsgithub-actionsBot added the Rust Pull requests that update Rust code label Jun 13, 2025
@redsun82
redsun82 marked this pull request as ready for review June 13, 2025 10:21
CopilotAI review requested due to automatic review settings June 13, 2025 10:21
@redsun82
redsun82 requested a review from a team as a code ownerJune 13, 2025 10:21

CopilotAI left a comment

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.

Pull Request Overview

Regenerates Rust models after correcting the order of generation (CodeQL PR 19744) and updates the CWE-770 test suite to account for one newly introduced false positive.

  • Annotates the shrink call in main.rs as a spurious alert.
  • Inserts corresponding expected entries in the test’s .expected file.

Reviewed Changes

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

FileDescription
rust/ql/test/query-tests/security/CWE-770/main.rsAdded // $ SPURIOUS comment on the shrink call to mark a FP.
rust/ql/test/query-tests/security/CWE-770/UncontrolledAllocationSize.expectedAdded new expected lines for the spurious shrink alert and re-numbered model sinks/summaries.

@geoffw0geoffw0 left a comment

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.

LGTM (not that I've manually checked all the models!)

}
} else {
let _ = std::alloc::System.shrink(m4, l4, l2).unwrap();
let _ = std::alloc::System.shrink(m4, l4, l2).unwrap(); // $ SPURIOUS: Alert[rust/uncontrolled-allocation-size]=arg1 - FP

@geoffw0geoffw0Jun 13, 2025

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.

I think the model generator is right to generate flow for this, shrink is causing an allocation to happen and the new size l2 is user controlled. The reason this is a FP is because we know a shrink can only reduce the size of the allocation so the allocation is bounded - this can't be the source of a problem.

I think the right answer is to introduce a barrier. I can do this as follow-up to your PR.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

well, reading https://doc.rust-lang.org/beta/std/alloc/trait.Allocator.html#safety-4 I can't decide whether we can count on shrink actually shrinking, considering that the constraint of l2's size being smaller that l4's one is actually a safety contract to be guaranteed by the user.

However apart from that, we should know that l2 has size v, and that v < 10 here, which means we aren't really unconstrained in any case here. Or is this too much for the current implementation of the analysis? Are we doing some kind of range analysis?

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.

We don't have range analysis, we do have barrier guards and in fact the query is using them. However in this case the check on v is after the std::alloc::Layout has been created from it, so we don't notice the guard applies to the layout. I'll see if I can easily address this...

@redsun82
redsun82 merged commit 2a51749 into mainJun 16, 2025
@redsun82
redsun82 deleted the redsun82/rust-models branch June 16, 2025 06:37
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RustPull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@redsun82@geoffw0