-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rust: Query for dereferencing an invalid pointer #19080
base: main
Are you sure you want to change the base?
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 is 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 dereference 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
Fixed
Show resolved
Hide resolved
n.(FlowSummaryNode).getSourceElement() = ce.getFunction() and | ||
arg = ce.getArgList().getAnArg() and | ||
this.asExpr().getExpr().getParentNode*() = arg | ||
) |
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.
@hvitved this is a workaround because the sinks with access path "Argument[0]"
weren't working as written. I'm not sure if I've made a trivial mistake or whether something is wrong in the MaD library?
DCA:
|
New query
rust/access-invalid-pointer
that 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:dealloc
function before dereferencing. Analogous tocpp/use-after-free
.TODO: