-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #2183 - RalfJung:better-provenance-control, r=RalfJung
adjust for better provenance control This is the Miri side of rust-lang/rust#97684.
- Loading branch information
Showing
29 changed files
with
136 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4e725bad73747a4c93a3ac53106e4b4006edc665 | ||
9d20fd109809f20c049d6895a5be27a1fbd39daa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// compile-flags: -Zmiri-permissive-provenance -Zmiri-disable-stacked-borrows | ||
#![feature(strict_provenance)] | ||
|
||
use std::mem; | ||
|
||
// This is the example from | ||
// <https://github.com/rust-lang/unsafe-code-guidelines/issues/286#issuecomment-1085144431>. | ||
|
||
unsafe fn deref(left: *const u8, right: *const u8) { | ||
let left_int: usize = mem::transmute(left); | ||
let right_int: usize = mem::transmute(right); | ||
if left_int == right_int { | ||
// The compiler is allowed to replace `left_int` by `right_int` here... | ||
let left_ptr: *const u8 = mem::transmute(left_int); | ||
// ...which however means here it could be dereferencing the wrong pointer. | ||
let _val = *left_ptr; //~ERROR dereferencing pointer failed | ||
} | ||
} | ||
|
||
fn main() { | ||
let ptr1 = &0u8 as *const u8; | ||
let ptr2 = &1u8 as *const u8; | ||
unsafe { | ||
// Two pointers with the same address but different provenance. | ||
deref(ptr1, ptr2.with_addr(ptr1.addr())); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/fail/provenance/permissive_provenance_transmute.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: Undefined Behavior: dereferencing pointer failed: $HEX is not a valid pointer | ||
--> $DIR/permissive_provenance_transmute.rs:LL:CC | ||
| | ||
LL | let _val = *left_ptr; | ||
| ^^^^^^^^^ dereferencing pointer failed: $HEX 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 `deref` at $DIR/permissive_provenance_transmute.rs:LL:CC | ||
note: inside `main` at $DIR/permissive_provenance_transmute.rs:LL:CC | ||
--> $DIR/permissive_provenance_transmute.rs:LL:CC | ||
| | ||
LL | deref(ptr1, ptr2.with_addr(ptr1.addr())); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
// compile-flags: -Zmiri-permissive-provenance -Zmiri-disable-stacked-borrows -Zmiri-allow-ptr-int-transmute | ||
// compile-flags: -Zmiri-permissive-provenance -Zmiri-disable-stacked-borrows | ||
#![feature(strict_provenance)] | ||
|
||
fn main() { | ||
let x: i32 = 3; | ||
let x_ptr = &x as *const i32; | ||
|
||
// TODO: switch this to addr() once we intrinsify it | ||
let x_usize: usize = unsafe { std::mem::transmute(x_ptr) }; | ||
// Cast back a pointer that did *not* get exposed. | ||
let ptr = x_usize as *const i32; | ||
let x_usize: usize = x_ptr.addr(); | ||
// Cast back an address that did *not* get exposed. | ||
let ptr = std::ptr::from_exposed_addr::<i32>(x_usize); | ||
assert_eq!(unsafe { *ptr }, 3); //~ ERROR Undefined Behavior: dereferencing pointer failed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
// compile-flags: -Zmiri-allow-uninit-numbers | ||
fn main() { | ||
let v: Vec<u8> = Vec::with_capacity(10); | ||
let undef = unsafe { *v.get_unchecked(5) }; | ||
let x = undef + 1; //~ ERROR this operation requires initialized memory | ||
let undef = unsafe { *v.get_unchecked(5) }; //~ ERROR uninitialized | ||
let x = undef + 1; | ||
panic!("this should never print: {}", x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.