-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: Enforce more uniqueness in Buffer.qll
#21219
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
C++: Enforce more uniqueness in Buffer.qll
#21219
Conversation
There was a problem hiding this 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 PR addresses false positive reports in buffer overflow queries caused by database inconsistencies where structs have multiple sizes. The changes add uniqueness enforcement to the Buffer.qll library by wrapping type size calculations with the unique() aggregate.
Changes:
- Added
unique()aggregate togetVariableSize()to ensure variables have a single type size - Wrapped field size calculation in
getSize()withunique()to enforce uniqueness for class field buffer sizes - Simplified
isSource()by removing redundant nestedunique()sincegetSize()now handles uniqueness
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Seems reasonable to me. My understanding is that when the database cannot agree on the size of a struct, for example due to missing or inconsistent defines, we currently end up reporting false positives. Your change narrows the domain by only reasoning about structs whose size is consistent and unique in the database avoiding those cases. Am I reading this correctly? |
|
Yep, that's exactly right 🙂 |
IdrissRio
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
We received a number of FP reports at Microsoft related to buffer overflow queries that all involve inconsistency in DBs. Sadly, I don't have access to any tracer logs so that we can debug why these inconsistencies happen, and I haven't been able to reproduce it with any locally build DBs.
The main problem is that a
structhas multiple sizes, and this PR mitigates the problem by restricting theBuffer.qlllibrary (which is used in a number of overflow-related queries) to only types with unique type sizes.Since I haven't been able to reproduce the problem I also haven't been able to provide a testcase.
Commit-by-commit review recommended.
The removed result on DCA looks like exactly the kind of result we're hoping to remove. After prepreocessing the
memsetlooks like:and this is obviously fine.