-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Query for dereferencing an invalid pointer #19080
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
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
|
QHelp previews: rust/ql/src/queries/security/CWE-825/AccessInvalidPointer.qhelpAccess of invalid pointerDereferencing an invalid or dangling pointer may cause undefined behavior. Memory may be corrupted causing the program to crash or behave incorrectly, in some cases exposing the program to potential attacks. RecommendationWhen dereferencing a pointer in ExampleIn the following example, unsafe {
std::ptr::drop_in_place(ptr); // executes the destructor of `*ptr`
}
// ...
unsafe {
do_something(&*ptr); // BAD: dereferences `ptr`
}In this case, undefined behavior can be avoided by rearranging the code so that the dereferencing comes before the call to unsafe {
do_something(&*ptr); // GOOD: dereferences `ptr` while it is still valid
}
// ...
{
std::ptr::drop_in_place(ptr); // executes the destructor of `*ptr`
}References
|
rust/ql/lib/codeql/rust/security/AccessInvalidPointerExtensions.qll
Outdated
Show resolved
Hide resolved
|
DCA:
|
mchammer01
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.
@geoffw0 👋🏻 - approving on behalf of Docs.
Left a few minor suggestions. Feel free to ignore the ones you don't agree with 😅
rust/ql/src/queries/security/CWE-825/AccessInvalidPointer.qhelp
Outdated
Show resolved
Hide resolved
rust/ql/src/queries/security/CWE-825/AccessInvalidPointer.qhelp
Outdated
Show resolved
Hide resolved
rust/ql/src/queries/security/CWE-825/AccessInvalidPointer.qhelp
Outdated
Show resolved
Hide resolved
Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com>
|
@mchammer01 suggestions accepted, thank you. I still need to decide what to do about the results inside |
|
Re: results inside I'll do another DCA run to confirm we no longer get false positive results. |
|
DCA
|
|
#19195 should hopefully remove the data flow inconsistencies. |
|
I've merged in the fix for the consistency check. I think this PR is ready for approval now. |
hvitved
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.
The two empty DataFlowConsistency.expected files should be deleted.
|
Good point. Done. |
hvitved
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.
I have started a final DCA run.
|
DCA LGTM. There are 2 results, in both cases the sources and sinks are good but the flow misses an |
New query
rust/access-invalid-pointerthat spots dereferences of pointers that are invalid to dereference. There are tests for two general cases, but this query is only intended to catch the first one:deallocfunction before dereferencing. Analogous tocpp/use-after-free.TODO: