Skip to content

-Zmiri-strict-provenance reports UB when using the address-exposing Strict Provenance APIs correctly #2134

Closed as not planned
@saethlin

Description

@saethlin
#![feature(strict_provenance)]
fn main() {
    let x = 0u8;
    let original_ptr = &x as *const u8;
    let addr = original_ptr.expose_addr();
    let new_ptr: *const u8 = core::ptr::from_exposed_addr(addr);
    unsafe {
        dbg!(*new_ptr);
    }
}
error: Undefined Behavior: dereferencing pointer failed: 0x27c02 is not a valid pointer
 --> src/main.rs:8:9
  |
8 |         dbg!(*new_ptr);
  |         ^^^^^^^^^^^^^^ dereferencing pointer failed: 0x27c02 is not a valid pointer
  |
  = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
  = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
          
  = note: inside `main` at /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/src/macros.rs:315:13
  = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error

I understand why this happens, but this is if nothing else incredibly surprising for users. The intuition is that the Strict Provenance mode in Miri should be compatible with the Strict Provenance APIs in the standard library. Could we make that happen? Or will this just be closed by the permissive provenance work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intptrcastArea: affects int2ptr and ptr2int castsC-supportCategory: Not necessarily a bug, but someone asking for support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions