rust-lang / rust-lang/rust

"accessible" terminology in with_exposed_provenance docs is misleading

Open
#137,060 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs C-bug T-opsem
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

During stabilization, we changed the documentation of exposed provenance from saying that memory outside the AM "is always exposed" to "is always accessible". Based on a conversation I just had, I believe the new documentation to be wrong, because it suggests that this program is permitted:

use std::ptr;
fn main() {
    // Create a byte we "magically" know the address of (by capturing it)
    // Another way to stash or know a valid-to-write address would make a better demo.
    let mut byte = 0u8;
    let magic_addr = &mut byte as *mut u8 as usize;
    
    let func = |r: &mut u8| {
        *r = 123;
        unsafe {
            // The docs say:
            // memory which is outside the control of the Rust abstract machine
            // (MMIO registers, for example) is always considered to be accessible
            // with an exposed provenance
            // So this address should be accessible, according to the docs.
            // But the access here is a clear violation of the noalias attribute.
            dbg!(*ptr::with_exposed_provenance::<u8>(magic_addr))
        }
    };
    
    let ptr = ptr::with_exposed_provenance_mut::<u8>(magic_addr);
    unsafe {
        func(&mut *ptr);
    }
}

The current documentation can be traced to this part of the stabilization PR discussion: https://github.com/rust-lang/rust/pull/130350#issuecomment-2369169477

I am writing this up as I am heading to bed, so please just correct me if I seem wrong. cc @rust-lang/opsem

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the with_exposed_provenance documentation and read the linked stabilization PR discussion, especially the cited comment. Determine whether “accessible” accurately describes exposed provenance in the example, then update the terminology or clarify the docs so the permitted behavior and aliasing implications are unambiguous.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.