Skip to content

Commit 8bfa229

Browse files
committed
more review
1 parent 59bc0a7 commit 8bfa229

File tree

9 files changed

+31
-56
lines changed

9 files changed

+31
-56
lines changed

src/shims/native_lib/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,23 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
222222
// so we cannot assume 1 access = 1 allocation. :(
223223
let mut rg = evt_rg.addr..evt_rg.end();
224224
while let Some(curr) = rg.next() {
225-
let Some(alloc_id) =
226-
this.alloc_id_from_addr(curr.to_u64(), rg.len().try_into().unwrap(), true)
227-
else {
225+
// FIXME: ProvenanceMap should have something like get_range().
226+
let Some(alloc_id) = this.alloc_id_from_addr(
227+
curr.to_u64(),
228+
rg.len().try_into().unwrap(),
229+
/* only_exposed_allocations */ true,
230+
) else {
228231
throw_ub_format!("Foreign code did an out-of-bounds access!")
229232
};
230233
let alloc = this.get_alloc_raw(alloc_id)?;
231234
let alloc_addr = alloc.get_bytes_unchecked_raw().addr();
232235

233236
// Skip forward however many bytes of the access are contained in the current allocation.
234-
// The start of the overlap range will be the greater of the alloc base address and the
235-
// lowest remaining address in the access' range; the end will be the lesser of the end
236-
// of the allocation and the end of the access' range. Both are then shifted by `alloc_addr`
237+
// The start of the overlap range will be `curr`; the end will be the lesser of the end of
238+
// the allocation and the end of the access' range. Both are then shifted by `alloc_addr`
237239
// so that the overlap range would have index 0 as the first byte of the allocation (which
238240
// is how the methods on the allocation expect it to be).
239-
let overlap = std::cmp::max(alloc_addr, curr).strict_sub(alloc_addr)
241+
let overlap = curr.strict_sub(alloc_addr)
240242
..std::cmp::min(alloc_addr.strict_add(alloc.len()), rg.end)
241243
.strict_sub(alloc_addr);
242244
// Since `overlap` is capped in length by `rg.end`, this will inherently always be

src/shims/native_lib/trace/parent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ fn capstone_find_events(
389389
// FIXME: This could be made certain; either determine all cases where
390390
// only reads happen, or have an intermediate mempr_* function to first
391391
// map the page(s) as readonly and check if a segfault occurred.
392-
392+
393393
// Per https://docs.rs/iced-x86/latest/iced_x86/enum.OpAccess.html,
394394
// we know that the possible access types are Read, CondRead, Write,
395395
// CondWrite, ReadWrite, and ReadCondWrite. Since we got a segfault

tests/native-lib/tracing/fail/partial_init.rs renamed to tests/native-lib/fail/tracing/partial_init.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//@only-target: x86_64-unknown-linux-gnu i686-unknown-linux-gnu
2+
//@compile-flags: -Zmiri-native-lib-enable-tracing
3+
14
extern "C" {
25
fn init_n(n: i32, ptr: *mut u8);
36
}

tests/native-lib/tracing/fail/partial_init.stderr renamed to tests/native-lib/fail/tracing/partial_init.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: sharing memory with a native function called via FFI
2-
--> tests/native-lib/tracing/fail/partial_init.rs:LL:CC
2+
--> tests/native-lib/fail/tracing/partial_init.rs:LL:CC
33
|
44
LL | init_n(2, slice_ptr);
55
| ^^^^^^^^^^^^^^^^^^^^ sharing memory with a native function
@@ -10,25 +10,25 @@ LL | init_n(2, slice_ptr);
1010
= help: what this means is that Miri will easily miss Undefined Behavior related to incorrect usage of this shared memory, so you should not take a clean Miri run as a signal that your FFI code is UB-free
1111
= help: tracing memory accesses in native code is not yet fully implemented, so there can be further imprecisions beyond what is documented here
1212
= note: BACKTRACE:
13-
= note: inside `partial_init` at tests/native-lib/tracing/fail/partial_init.rs:LL:CC
13+
= note: inside `partial_init` at tests/native-lib/fail/tracing/partial_init.rs:LL:CC
1414
note: inside `main`
15-
--> tests/native-lib/tracing/fail/partial_init.rs:LL:CC
15+
--> tests/native-lib/fail/tracing/partial_init.rs:LL:CC
1616
|
1717
LL | partial_init();
1818
| ^^^^^^^^^^^^^^
1919

2020
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
21-
--> tests/native-lib/tracing/fail/partial_init.rs:LL:CC
21+
--> tests/native-lib/fail/tracing/partial_init.rs:LL:CC
2222
|
2323
LL | let _val = *slice_ptr.offset(2);
2424
| ^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
2525
|
2626
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
2727
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
2828
= note: BACKTRACE:
29-
= note: inside `partial_init` at tests/native-lib/tracing/fail/partial_init.rs:LL:CC
29+
= note: inside `partial_init` at tests/native-lib/fail/tracing/partial_init.rs:LL:CC
3030
note: inside `main`
31-
--> tests/native-lib/tracing/fail/partial_init.rs:LL:CC
31+
--> tests/native-lib/fail/tracing/partial_init.rs:LL:CC
3232
|
3333
LL | partial_init();
3434
| ^^^^^^^^^^^^^^

tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs renamed to tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//@only-target: x86_64-unknown-linux-gnu i686-unknown-linux-gnu
2+
//@compile-flags: -Zmiri-permissive-provenance -Zmiri-native-lib-enable-tracing
3+
14
extern "C" {
25
fn do_one_deref(ptr: *const *const *const i32) -> usize;
36
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: sharing memory with a native function called via FFI
2-
--> tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs:LL:CC
2+
--> tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC
33
|
44
LL | unsafe { do_one_deref(exposed) };
55
| ^^^^^^^^^^^^^^^^^^^^^ sharing memory with a native function
@@ -10,49 +10,30 @@ LL | unsafe { do_one_deref(exposed) };
1010
= help: what this means is that Miri will easily miss Undefined Behavior related to incorrect usage of this shared memory, so you should not take a clean Miri run as a signal that your FFI code is UB-free
1111
= help: tracing memory accesses in native code is not yet fully implemented, so there can be further imprecisions beyond what is documented here
1212
= note: BACKTRACE:
13-
= note: inside `unexposed_reachable_alloc` at tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs:LL:CC
13+
= note: inside `unexposed_reachable_alloc` at tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC
1414
note: inside `main`
15-
--> tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs:LL:CC
16-
|
17-
LL | unexposed_reachable_alloc();
18-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
19-
20-
warning: integer-to-pointer cast
21-
--> tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs:LL:CC
22-
|
23-
LL | let valid: *const i32 = std::ptr::with_exposed_provenance(intermediate_b.addr());
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
25-
|
26-
= help: this program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`, which means that Miri might miss pointer bugs in this program
27-
= help: see https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation
28-
= help: to ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead
29-
= help: you can then set `MIRIFLAGS=-Zmiri-strict-provenance` to ensure you are not relying on `with_exposed_provenance` semantics
30-
= help: alternatively, `MIRIFLAGS=-Zmiri-permissive-provenance` disables this warning
31-
= note: BACKTRACE:
32-
= note: inside `unexposed_reachable_alloc` at tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs:LL:CC
33-
note: inside `main`
34-
--> tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs:LL:CC
15+
--> tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC
3516
|
3617
LL | unexposed_reachable_alloc();
3718
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
3819

3920
error: Undefined Behavior: memory access failed: attempting to access 4 bytes, but got $HEX[noalloc] which is a dangling pointer (it has no provenance)
40-
--> tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs:LL:CC
21+
--> tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC
4122
|
4223
LL | let _not_ok = *invalid;
4324
| ^^^^^^^^ Undefined Behavior occurred here
4425
|
4526
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
4627
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
4728
= note: BACKTRACE:
48-
= note: inside `unexposed_reachable_alloc` at tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs:LL:CC
29+
= note: inside `unexposed_reachable_alloc` at tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC
4930
note: inside `main`
50-
--> tests/native-lib/tracing/fail/unexposed_reachable_alloc.rs:LL:CC
31+
--> tests/native-lib/fail/tracing/unexposed_reachable_alloc.rs:LL:CC
5132
|
5233
LL | unexposed_reachable_alloc();
5334
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
5435

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

57-
error: aborting due to 1 previous error; 2 warnings emitted
38+
error: aborting due to 1 previous error; 1 warning emitted
5839

tests/native-lib/pass/ptr_read_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@revisions: trace notrace
2-
//@[trace] only-target: x86_64-unknown-linux-gnu x86-unknown-linux-gnu
2+
//@[trace] only-target: x86_64-unknown-linux-gnu i686-unknown-linux-gnu
33
//@[trace] compile-flags: -Zmiri-native-lib-enable-tracing
44

55
fn main() {

tests/native-lib/pass/ptr_write_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@revisions: trace notrace
2-
//@[trace] only-target: x86_64-unknown-linux-gnu x86-unknown-linux-gnu
2+
//@[trace] only-target: x86_64-unknown-linux-gnu i686-unknown-linux-gnu
33
//@[trace] compile-flags: -Zmiri-native-lib-enable-tracing
44
//@compile-flags: -Zmiri-permissive-provenance
55

tests/ui.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,20 +343,6 @@ fn main() -> Result<()> {
343343
if cfg!(unix) && target == host {
344344
ui(Mode::Pass, "tests/native-lib/pass", &target, WithoutDependencies, tmpdir.path())?;
345345
ui(Mode::Fail, "tests/native-lib/fail", &target, WithoutDependencies, tmpdir.path())?;
346-
if cfg!(all(
347-
any(target_arch = "x86", target_arch = "x86_64"),
348-
target_os = "linux",
349-
target_env = "gnu"
350-
)) {
351-
// No pass tests here currently.
352-
ui(
353-
Mode::Fail,
354-
"tests/native-lib/tracing/fail",
355-
&target,
356-
WithoutDependencies,
357-
tmpdir.path(),
358-
)?;
359-
}
360346
}
361347

362348
Ok(())

0 commit comments

Comments
 (0)