Skip to content

Conversation

@geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Nov 17, 2025

Improve rust/access-invalid-pointer:

  • add some test cases covering issues we found in the MRVA-1000 runs.
  • add a model for core::ptr::null_mut (-> more results).
  • add a null check barrier for the query (-> fewer false positives).

Note that the null check barrier only works for immutable pointers (at present), due to some limitations in the design of barrier guards and SSA (specifically, the call to DfInput::getARead(def) from Ssa.qlls guardChecksSsaDef isn't getting us what we want). I'll write up an issue for that and I would appreciate anybody's thoughts on how best to fix it.

Copilot AI review requested due to automatic review settings November 17, 2025 15:31
@geoffw0 geoffw0 requested a review from a team as a code owner November 17, 2025 15:31
@geoffw0 geoffw0 added the Rust Pull requests that update Rust code label Nov 17, 2025
Copilot finished reviewing on behalf of geoffw0 November 17, 2025 15:34
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 PR improves the rust/access-invalid-pointer query to detect more invalid pointer access vulnerabilities while reducing false positives. The changes add support for detecting null pointers created via core::ptr::null_mut, introduce a null check barrier to reduce false positives, and include comprehensive test cases covering various conditional scenarios.

  • Adds a model for core::ptr::null_mut as a source of invalid pointers
  • Implements a null check barrier that recognizes when pointers are validated before use (currently only effective for immutable pointers due to SSA limitations)
  • Adds extensive test coverage for conditional null checks and short-circuit evaluation scenarios

Reviewed Changes

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

Show a summary per file
File Description
rust/ql/src/change-notes/2025-17-11-access-invalid-pointer.md Change note documenting the query improvements (contains date format issue in filename)
rust/ql/src/queries/security/CWE-825/AccessInvalidPointer.ql Refactored to import AccessInvalidPointer module directly and use simplified references
rust/ql/lib/codeql/rust/security/Barriers.qll Adds NotNullCheckBarrier class to recognize null pointer checks via is_null() method
rust/ql/lib/codeql/rust/security/AccessInvalidPointerExtensions.qll Integrates the new NotNullCheckBarrier into the AccessInvalidPointer analysis
rust/ql/lib/codeql/rust/frameworks/stdlib/core.model.yml Adds model for core::ptr::null_mut as a source of invalid pointers
rust/ql/test/query-tests/security/CWE-825/main.rs Adds call to new test function test_ptr_invalid_conditions
rust/ql/test/query-tests/security/CWE-825/deallocation.rs Extensive test cases for null pointer checks in various conditional scenarios
rust/ql/test/query-tests/security/CWE-825/AccessInvalidPointer.expected Updated expected results reflecting new detections and barrier behavior
rust/ql/test/query-tests/security/CWE-825/AccessAfterLifetime.expected Updated line number references due to new code additions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@paldepind paldepind left a comment

Choose a reason for hiding this comment

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

Looks good to me!

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