Skip to content

Rust: Remove visibility check in path resolution #19431

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

Merged

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Apr 30, 2025

Visibility checking was originally introduced to reduce the number of path resolution inconsistencies. However, the current implementation is too restrictive, and my attempt to make it less restrictive is still not good enough.

So, instead I have come to the conclusion that we are better off without visibility checking. This also aligns with our general assumption that programs are valid, for instance our type inference logic does not actually check that the program is well-typed.

DCA shows that we gain an additional 4 % true-positive call edges (up 617,811 from 593,987).

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Apr 30, 2025
@hvitved hvitved force-pushed the rust/path-resolution-remove-visibility-check branch 2 times, most recently from edc38da to a34952d Compare May 1, 2025 07:35
@hvitved hvitved marked this pull request as ready for review May 1, 2025 12:38
@Copilot Copilot AI review requested due to automatic review settings May 1, 2025 12:38
@hvitved hvitved requested a review from a team as a code owner May 1, 2025 12:38
@hvitved hvitved requested a review from paldepind May 1, 2025 12:38
Copy link
Contributor

@Copilot 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 removes visibility checks during Rust path resolution and updates related test expectations to reflect the broader resolution scope. Key changes include:

  • Removal of isPublic/resolvePathPrivate logic and related predicates.
  • Replacement of resolvePath1 with resolvePathFull and updated resolvePath to favor source functions.
  • Updated expected outputs in consistency and dataflow tests to account for additional resolutions.

Reviewed Changes

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

File Description
rust/ql/test/query-tests/security/CWE-022/CONSISTENCY/PathResolutionConsistency.expected Expanded expected path resolutions across multiple locations
rust/ql/test/library-tests/dataflow/modeled/inline-flow.expected Added extra dataflow edges/nodes for inlined wrapper clones
rust/ql/lib/codeql/rust/internal/PathResolution.qll Removed visibility‐based filtering, introduced resolvePathFull
Comments suppressed due to low confidence (2)

rust/ql/lib/codeql/rust/internal/PathResolution.qll:1066

  • [nitpick] No tests appear to cover the new resolvesSourceFunction predicate or the updated resolvePath filtering when both library and source functions are present. Add a test case where a function exists in source and in a dependency to verify that only the source version is returned.
private predicate resolvesSourceFunction(RelevantPath path) {

rust/ql/lib/codeql/rust/internal/PathResolution.qll:1134

  • Using resolvePathFull here bypasses the filtering and caching logic in resolvePath (which prioritizes source functions and applies extractor workarounds). Consider calling resolvePath(path) or applying the same post-filter to maintain consistent behavior for use-tree imports.
result = resolvePathFull(tree.getPath())

@hvitved hvitved force-pushed the rust/path-resolution-remove-visibility-check branch from a34952d to 73fa381 Compare May 1, 2025 15:15
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.

Great :) Definitely seems nicer to have an over approximation than an under approximation.

@hvitved hvitved merged commit ae2fd52 into github:main May 2, 2025
17 checks passed
@hvitved hvitved deleted the rust/path-resolution-remove-visibility-check branch May 2, 2025 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants