Skip to content

Rust: Model Pin #19529

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
merged 6 commits into from
May 27, 2025
Merged

Rust: Model Pin #19529

merged 6 commits into from
May 27, 2025

Conversation

geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented May 19, 2025

Add tests and models for std::pin::Pin, which will be required for some other work. They're not working very well though, @hvitved @paldepind can you spot what might be going wrong, particularly in the second block of test cases?

@Copilot Copilot AI review requested due to automatic review settings May 19, 2025 17:42
@geoffw0 geoffw0 added the Rust Pull requests that update Rust code label May 19, 2025
@geoffw0 geoffw0 requested a review from a team as a code owner May 19, 2025 17:42
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 adds tests for std::pin::Pin usage and models in the CodeQL standard library definitions to support pin-related dataflow.

  • Introduces a test_pin function with various pin creation and projection patterns
  • Extends lang-core.model.yml and lang-alloc.model.yml with Pin and Box::pin/into_pin summaries
  • Updates the expected flow results in inline-flow.expected to include the new pin tests

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
rust/ql/test/library-tests/dataflow/modeled/main.rs Adds test_pin with sinks expecting pin-related flows
rust/ql/test/library-tests/dataflow/modeled/inline-flow.expected Updates expected dataflow edges for pin tests
rust/ql/lib/codeql/rust/frameworks/stdlib/lang-core.model.yml Adds manual summaries for Pin methods
rust/ql/lib/codeql/rust/frameworks/stdlib/lang-alloc.model.yml Adds manual summaries for Box::pin, Box::new, into_pin
Comments suppressed due to low confidence (3)

rust/ql/lib/codeql/rust/frameworks/stdlib/lang-core.model.yml:42

  • There is a duplicate entry for <crate::pin::Pin>::into_inner. Please remove the redundant line to avoid confusion.
- ["lang:core", "<crate::pin::Pin>::into_inner", "Argument[0]", "ReturnValue", "value", "manual"]

rust/ql/lib/codeql/rust/frameworks/stdlib/lang-core.model.yml:35

  • Missing model for the pin! macro (imported via use std::pin::pin). Add an entry like -["lang:core", "crate::pin::pin", "Argument[0]", "ReturnValue", "value", "manual"] so dataflow through pin!(...) is recognized.
# Pin

rust/ql/lib/codeql/rust/frameworks/stdlib/lang-core.model.yml:35

  • Pin<T> implements Deref, but there’s no summary model to propagate dataflow through .deref(). Add a model for <crate::pin::Pin<T> as std::ops::Deref>::deref to ensure field accesses on pinned references carry over the value.
# Pin

geoffw0 and others added 2 commits May 19, 2025 21:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
paldepind
paldepind previously approved these changes May 20, 2025
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.

These models looks good to me.

Pin is modeled as if it isn't really there. That seems to work great, but one might speculate about whether storing things in it struct field could work better with the model generator. That's something one could investigate in the future if we try and generate models for Pin.

As for why tests don't really work, I think that's a limitation of the type inference/field lookup. For instance, the field lookup in

sink(pin1.val); // $ MISSING: hasValueFlow=41

works because there's an implicit dereference calling Pins implementation of the Deref trait. Currently we do not understand Deref traits, and only implement implicit dereferencing for plain &s. I confirmed that by quick eval'ing resolveStructFieldExpr in type inference which doesn't resolve any of these field expressions.

@geoffw0
Copy link
Contributor Author

geoffw0 commented May 27, 2025

Fixed merge conflict.

Currently we do not understand Deref traits, and only implement implicit dereferencing for plain &s.

Indeed, I suspect we hit this issue quite a lot.

@paldepind
Copy link
Contributor

Indeed, I suspect we hit this issue quite a lot.

I think you're right about that. I've created an internal issue for this.

@geoffw0 geoffw0 merged commit a412ad2 into github:main May 27, 2025
15 checks passed
@geoffw0
Copy link
Contributor Author

geoffw0 commented May 27, 2025

... it looks like I forgot to do a DCA run on this branch, so I've started one now ...

@geoffw0
Copy link
Contributor Author

geoffw0 commented May 27, 2025

... DCA run LGTM.

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy