Commit Graph

3046 Commits

Author SHA1 Message Date
Christian Legnitto
73a1a27a45 Support gettimeofday on more than macos
This appears to be in linux and in openbsd as well:

* https://github.com/torvalds/linux/blob/master/lib/vdso/gettimeofday.c
* https://github.com/openbsd/src/blob/master/sys/sys/time.h#L439

Co-authored-by: Ralf Jung <post@ralfj.de>
2022-06-29 17:48:04 -04:00
Ralf Jung
839c120b40 fmt 2022-06-29 10:09:18 -04:00
Ralf Jung
f389d46b04 also prune caller_location frames when backtrace=off 2022-06-29 09:33:12 -04:00
Ralf Jung
28dea673be rustup 2022-06-29 08:33:06 -04:00
Ralf Jung
8bd4bbe3e4 tweak int2ptr diagnostics 2022-06-28 08:52:22 -04:00
bors
aaaed51ab8 Auto merge of #2279 - RalfJung:adjacent-allocs, r=RalfJung
Allow non-ZST allocations to be adjacent

Also `cargo update` in test-cargo-miri... no need to make a separate PR for that right?...
2022-06-28 02:52:23 +00:00
Ralf Jung
c16b380d6b finally we can actually have adjacent allocations :) 2022-06-27 22:52:02 -04:00
Ralf Jung
098704e10f make use of get_alloc_info 2022-06-27 21:22:46 -04:00
bors
7fafbde038 Auto merge of #2275 - RalfJung:permissive-provenance-for-all, r=RalfJung
Enable permissive provenance by default

This completes the plan laid out in https://github.com/rust-lang/miri/issues/2133:
- We use permissive provenance with wildcard pointers by default.
- We print a warning on int2ptr casts. `-Zmiri-permissive-provenance` suppresses the warning; `-Zmiri-strict-provenance` turns it into a hard error.
- Raw pointer tagging is now always enabled, so we remove the `-Zmiri-tag-raw-pointers` flag and the code for untagged pointers. (Passing the flag still works, for compatibility -- but we just ignore it, with a warning.)

We also fix an intptrcast issue:
- Only live allocations are considered when computing the AllocId from an address.

So, finally, Miri has a good story for ptr2int2ptr roundtrips *and* no weird false negatives when doing raw pointer stuff with Stacked Borrows. :-) 🎉   Thanks a lot to everyone who helped with this, in particular `@carbotaniuman` who convinced me this is even possible.

Fixes https://github.com/rust-lang/miri/issues/2133
Fixes https://github.com/rust-lang/miri/issues/1866
Fixes https://github.com/rust-lang/miri/issues/1993
2022-06-28 01:20:40 +00:00
Ralf Jung
c1eddbc7fe show int2ptr warning once for each span (but don't duplicate the long help) 2022-06-27 20:50:45 -04:00
Ralf Jung
67e89b53e2 fix warning text 2022-06-27 20:04:46 -04:00
Ralf Jung
5719897fb0
improve old comment 2022-06-27 13:38:32 -04:00
Ralf Jung
d9e7a3ae82 typo
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-06-27 09:08:56 -04:00
Ralf Jung
b479f092a8 avoid unnecessary indirection in miri-track-raw-pointers warning 2022-06-26 23:14:16 -04:00
Ralf Jung
1a5dfbeb7a fmt 2022-06-26 22:36:45 -04:00
Ralf Jung
5c16713056 remove support for untagged pointers
good riddance!
2022-06-26 22:19:56 -04:00
Ralf Jung
294ef15adb more int2ptr cast tests, and fix casting of addresses inside dead allocations 2022-06-26 22:19:56 -04:00
Ralf Jung
13d425daeb make permissive provenance and raw-ptr tagging the default 2022-06-26 21:14:42 -04:00
infrandomness
aa072d72cc Cargo fmt 2022-06-27 01:39:25 +02:00
infrandomness
84a02787d8 Address code review
- Merge pthread_attr_getstack shim to unix/foreign_items.rs
2022-06-27 01:39:24 +02:00
infrandomness
93c61f3905 Add pthread_attr_get_np shim 2022-06-27 01:39:24 +02:00
infrandomness
f2cbd3e2bc Add pthread_attr_getstack shim 2022-06-27 01:39:24 +02:00
infrandomness
e89b4d6df2 Fix panicking ui_tests framework 2022-06-27 01:39:24 +02:00
infrandomness
97a512070a Fix pending reviews 2022-06-27 01:39:24 +02:00
infrandomness
9130034337 Initial freebsd work 2022-06-27 01:39:24 +02:00
Ralf Jung
34be937d5f add -Zmiri-report-progress to regularly print a stacktrace of what we are executing 2022-06-26 14:31:57 -04:00
bors
1589ba3bbc Auto merge of #2264 - RalfJung:not-a-fixme, r=RalfJung
remove a FIXME that is not actually a bug
2022-06-25 15:54:31 +00:00
Ralf Jung
f66c64bed2 remove a FIXME that is not actually a bug 2022-06-25 11:52:29 -04:00
Ralf Jung
58c79c5b6f tweaks and feedback 2022-06-24 22:02:17 -04:00
Ralf Jung
4fbb284a99 implement 'delimited' expose tracking so we still detect some UB 2022-06-24 20:05:56 -04:00
Ralf Jung
8d6fdaa024 make the tests pass
(and some formatting)
2022-06-24 18:03:02 -04:00
Ralf Jung
c0f7118342 reorganize exposure code a bit 2022-06-24 16:45:22 -04:00
carbotaniuman
d1e7de117c Try fix stuff 2022-06-24 16:10:23 -04:00
carbotaniuman
c7feb014b0 Maybe this wil work 2022-06-24 16:10:23 -04:00
carbotaniuman
57ce47b728 Handle wildcard pointers in SB 2022-06-24 16:10:23 -04:00
bors
655eed35b7 Auto merge of #2248 - RalfJung:arc-drop-fix, r=RalfJung
do not protect SRW items

This is the Miri version of https://github.com/rust-lang/rust/pull/98017.
2022-06-22 21:39:41 +00:00
Ralf Jung
f992099820 fix ICE when const refers to extern static 2022-06-21 21:03:40 -07:00
Ralf Jung
8d1b2ca3ec check that tag_alloc_base_pointer is not called on the wrong things 2022-06-21 21:03:40 -07:00
Ralf Jung
1b214a0d12 do not protect SRW items 2022-06-21 09:32:58 -07:00
bors
c4dd3f4ef9 Auto merge of #2228 - cbeuw:futex-fix, r=RalfJung
Prevent futex_wait from actually waiting if a concurrent waker was executed before us

Fixes #2223

Two SC fences were placed in `futex_wake` (after the caller has changed `addr`), and in `futex_wait` (before we read `addr`). This guarantees that `futex_wait` sees the value written to `addr` before the last `futex_wake` call, should one exists, and avoid going into sleep with no one else to wake us up.
ada7b72a87/src/concurrency/weak_memory.rs (L324-L326)

Earlier I proposed to use `fetch_add(0)` to read the latest value in MO, though this isn't the proper way to do it and breaks aliasing: syscall caller may pass in a `*const` from a `&` and Miri complains about write to a `SharedReadOnly` location, causing this test to fail.
ada7b72a87/tests/pass/concurrency/linux-futex.rs (L56-L68)
2022-06-18 15:10:56 +00:00
Ralf Jung
737a5b3b98
tweak correctness comment 2022-06-18 07:59:46 -07:00
Andy Wang
807a19a50a
Elaborate correctness comments 2022-06-15 01:44:32 +01:00
bors
2bbb70f584 Auto merge of #2203 - RalfJung:deprecate, r=oli-obk
deprecate -Zmiri-allow-uninit-numbers and -Zmiri-allow-ptr-int-transmute

Cc https://github.com/rust-lang/miri/issues/2187 https://github.com/rust-lang/miri/issues/2188
2022-06-13 10:23:42 +00:00
Scott McMurray
238bbd63ab Add #![feature(yeet_expr)] 2022-06-12 18:39:44 -07:00
bors
03a05ae211 Auto merge of #2195 - RalfJung:vtable-validation, r=RalfJung
test for Stacked Borrows error during vtable validation

Fixes https://github.com/rust-lang/miri/issues/2123
Needs https://github.com/rust-lang/rust/pull/97761
2022-06-12 05:34:22 +00:00
Ralf Jung
c3b8509654 rename ExperimentalUb → StackedBorrowsUb 2022-06-11 17:42:23 -07:00
Andy Wang
b6bcbf76fd
Prevent futex_wait from reading outdated value 2022-06-11 20:45:45 +01:00
infrandomness
bc27fbb2f7 Add assert_target_os_is_unix function 2022-06-11 18:50:36 +02:00
infrandomness
58d00aa642 Add target_os_is_unix helper 2022-06-11 18:45:53 +02:00
bors
ada7b72a87 Auto merge of #2227 - RalfJung:doc, r=RalfJung
make some rustdoc comments more readable
2022-06-11 15:50:11 +00:00
bors
c5f7a7d27a Auto merge of #2215 - InfRandomness:getpid_shim, r=RalfJung
Getpid shim
2022-06-11 15:25:26 +00:00
Ralf Jung
5f1ba4432b make some rustdoc comments more readable 2022-06-11 08:03:54 -07:00
bors
7656fc45cf Auto merge of #2222 - InfRandomness:cargo-docs, r=RalfJung
Add mandatory cargo_doc
2022-06-11 15:02:55 +00:00
InfRandomness
3e03054ef0 Add getpid shim 2022-06-11 11:28:50 +02:00
infrandomness
eaa1e444eb Add mandatory cargo_doc
Co-authored-by: Joshua Nelson <github@jyn.dev>
2022-06-11 10:59:57 +02:00
Ralf Jung
4da48e06c7 make frame_in_std check work with inlining 2022-06-10 20:25:58 -07:00
bors
4d6eca1c08 Auto merge of #2218 - Nilstrieb:faster-tag-partial-eq, r=RalfJung
Optimize `SbTag::eq`

The code before generated really bad code with a branch.
This nudges LLVM towards being smarter and simply comparing
the integers.

See https://github.com/rust-lang/miri/pull/2214#issuecomment-1150124617
2022-06-08 17:34:16 +00:00
Nilstrieb
93db9a6d71 Add comment to explain manual optimization 2022-06-08 19:29:54 +02:00
Nilstrieb
c01bf62ee4 Allow clippy::derive_hash_xor_eq 2022-06-08 18:43:12 +02:00
Nilstrieb
956a84bfe0 Optimize SbTag::eq
The code before generated really bad code with a branch.
This nudges LLVM towards being smarter and simply comparing
the integers.
2022-06-08 18:22:48 +02:00
Ralf Jung
657386cc91 rustup 2022-06-08 12:10:54 -04:00
Ralf Jung
a310ccc9a4 some clippy-induced cleanup 2022-06-08 08:06:32 -04:00
Ralf Jung
7a5de0c98a silence another clippy lint 2022-06-07 16:01:44 -04:00
InfRandomness
4758ce74ef Fix typo 2022-06-07 17:43:45 +00:00
Ralf Jung
bf372a8fbc remove warning about thread support being experimental 2022-06-06 20:16:02 -04:00
Ralf Jung
b64c9a0a83 make scheduler preemptive, with configurable preemption rate 2022-06-06 20:16:02 -04:00
Ralf Jung
dac95a3ad8 rename AllocationMap → RangeObjectMap 2022-06-06 20:16:02 -04:00
Ralf Jung
14913e993b deprecate -Zmiri-allow-uninit-numbers and -Zmiri-allow-ptr-int-transmute 2022-06-06 16:07:30 -04:00
Andy Wang
1b32d14255
Make racy imperfectly overlapping atomic access unsupported instead of UB
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-06-06 19:16:02 +01:00
Andy Wang
bf7a5c4154
Add more backgrounds on lazy store buffers
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-06-06 19:16:02 +01:00
Andy Wang
6fb7c131ed
Remove unused lifetimes 2022-06-06 19:16:02 +01:00
Andy Wang
c731071640
Give flag temp disabling race detector a better name 2022-06-06 19:16:00 +01:00
Andy Wang
8215702d5a
Refer to GitHub issue on overwritten init value 2022-06-06 19:16:00 +01:00
Andy Wang
4a07f78dad
Forbade all racing mixed size atomic accesses 2022-06-06 19:16:00 +01:00
Andy Wang
ceb173d647
Move logic out of machine.rs 2022-06-06 19:15:59 +01:00
Andy Wang
a7c832b04a
Wording improvements
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-06-06 19:15:59 +01:00
Andy Wang
6a73dedb36
Update experimental threading warning 2022-06-06 19:15:59 +01:00
Andy Wang
bfa56454e9
Split extra_cpp tests into sound and unsafe 2022-06-06 19:15:58 +01:00
Andy Wang
613d60db0b
Allow non-racy mixed size accesses 2022-06-06 19:15:58 +01:00
Andy Wang
226ed41cca
Destroy store buffers on non-racy non-atomic accesses 2022-06-06 19:15:58 +01:00
Andy Wang
2321b15342
Differentiate between not multithreading and temp disabling race detection 2022-06-06 19:15:57 +01:00
Andy Wang
6d27f188c2
Update src/concurrency/weak_memory.rs
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-06-06 19:15:56 +01:00
Andy Wang
e2002b4c65
Amend experimental thread support warnings 2022-06-06 19:15:55 +01:00
Andy Wang
92145373c3
Put the initialisation value into the store buffer 2022-06-06 19:15:55 +01:00
Andy Wang
577054c6de
Rename variables in AllocationMap 2022-06-06 19:15:54 +01:00
Andy Wang
6b54c92377
Throw UB on imperfectly overlapping access 2022-06-06 19:15:54 +01:00
Andy Wang
5a4a1bfccc
Remove incorrect comment 2022-06-06 19:15:54 +01:00
Andy Wang
335667c774
Move buffered functions into their own ext trait 2022-06-06 19:15:53 +01:00
Andy Wang
8739e45bef
Move data_race and weak_memory into a submodule 2022-06-06 19:15:53 +01:00
Andy Wang
6040c9f50a
Refactor store buffer search conditions 2022-06-06 19:15:25 +01:00
Andy Wang
773131bb26
Improve privacy and comments 2022-06-06 19:15:24 +01:00
Andy Wang
62b514e235
Update README 2022-06-06 19:15:24 +01:00
Andy Wang
89138a67dc
Add more top-level comments 2022-06-06 19:15:23 +01:00
Andy Wang
11ca975cd8
Move type definitions together and clarify fetch_store on empty buffer 2022-06-06 19:15:22 +01:00
Andy Wang
53f4887659
Use a new AllocationMap to store store buffers in the same allocation 2022-06-06 19:15:21 +01:00
Andy Wang
ecdab5ff35
Clearer boundries between alloc metadata with multiple buffers and an individual store buffer 2022-06-06 19:15:21 +01:00
Andy Wang
aca3b3a645
set_at_index sets the default value (0) if index doesn't exist in the other vector 2022-06-06 19:15:20 +01:00
Andy Wang
e7698f4f07
Implement weak memory emulation 2022-06-06 19:15:20 +01:00
Andy Wang
8d36e8b32c
Add weak memory config option 2022-06-06 19:15:19 +01:00
bors
3361eabf38 Auto merge of #2183 - RalfJung:better-provenance-control, r=RalfJung
adjust for better provenance control

This is the Miri side of https://github.com/rust-lang/rust/pull/97684.
2022-06-06 16:57:34 +00:00
bors
cd73c861c4 Auto merge of #2202 - InfRandomness:infrandomness/rustdoc-fixes, r=RalfJung
Fix rustdoc warnings

This fixes the rustdoc warnings presented by the tool
2022-06-06 16:32:05 +00:00
infrandomness
3ba6456181 Fix rustdoc warnings 2022-06-06 18:30:15 +02:00
Ralf Jung
63625b0397 adjust for better provenance control 2022-06-06 11:43:25 -04:00
Ralf Jung
f31a8e0951 argument parsing: make better use of strip_prefix 2022-06-06 11:07:25 -04:00
infrandomness
d0a0369a24 Refactor POSIX to UNIX
This renames the directory containing posix to unix; where applicable,
it also rename functions with the word "posix" to "unix"
2022-06-05 22:46:34 +02:00
bors
2eae474673 Auto merge of #2197 - RalfJung:round-robin, r=RalfJung
make Miri's scheduler proper round-robin

When thread N blocks or yields, we activate thread N+1 next, rather than always activating thread 0. This should guarantee that as long as all threads regularly yield, each thread eventually takes a step again.

Fixes the "multiple loops that yield playing ping-pong" part of https://github.com/rust-lang/miri/issues/1388.
`@cbeuw` I hope this doesn't screw up the scheduler-dependent tests you are adding in your PR.
2022-06-05 18:37:07 +00:00
Ralf Jung
47745380cd make Miri's scheduler proper round-robin 2022-06-05 14:22:00 -04:00
bors
5f988ab553 Auto merge of #2189 - RalfJung:clippy, r=RalfJung
run Clippy on CI

and fix some things it complains about. Also use `rustup-toolchain` script on CI (reduces code duplication, and good thing to make sure it keeps working, since we recommend it in the docs).

I left `ui_test` out for now; I'll leave those nits to `@oli-obk.` ;)
2022-06-05 15:18:39 +00:00
Ralf Jung
32c03080f1 rustup 2022-06-04 19:43:46 -04:00
Ralf Jung
151b6b13e0 clippy: main crate 2022-06-04 13:29:00 -04:00
Matthias Krüger
bcc491a6ba clippy fixes
clippy::redundant_closure
clippy::unnecessary_mut_passed
clippy::single_char_pattern
clippy::clone_on_copy
clippy::into_iter_on_ref
clippy::extra_unused_lifetimes
2022-06-04 17:10:32 +02:00
Ralf Jung
e79a331fea do not pass TyCtxt by reference 2022-06-02 15:11:22 -04:00
Oli Scherer
4b100a1b58 Check that diagnostics happen in the line that they are annotated for 2022-06-01 11:47:54 +00:00
Ralf Jung
62c48b2998 fix some lifetime names 2022-05-31 08:45:01 -04:00
Ralf Jung
eb6d4cdac0 reduce some code duplication 2022-05-31 08:43:17 -04:00
bors
aa589d3dc7 Auto merge of #2145 - saethlin:zero-size-creation, r=RalfJung
Save a created event for zero-size reborrows

Currently, we don't save a created event for zero-sized reborrows. Attempting to use something from a zero-sized reborrow is surprisingly common, for example on `minimal-lexical==0.2.1` we previously just emit this:
```
Undefined Behavior: attempting a write access using <187021> at alloc72933[0x0], but that tag does not exist in the borrow stack for this location
    --> /root/rust/library/core/src/ptr/mod.rs:1287:9
     |
1287 |         copy_nonoverlapping(&src as *const T, dst, 1);
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |         |
     |         attempting a write access using <187021> at alloc72933[0x0], but that tag does not exist in the borrow stack for this location
     |         this error occurs as part of an access at alloc72933[0x0..0x8]
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

     = note: inside `std::ptr::write::<u64>` at /root/rust/library/core/src/ptr/mod.rs:1287:9
note: inside `minimal_lexical::stackvec::StackVec::push_unchecked` at /root/build/src/stackvec.rs:82:13
    --> /root/build/src/stackvec.rs:82:13
     |
82   |             ptr::write(self.as_mut_ptr().add(self.len()), value);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

... backtrace continues...
```
Which leaves us with the question "where did we make this pointer?" because for every other diagnostic you get a "was created by" note, so I suspect people might be tempted to think there is a Miri bug here. I certainly was.

---
This code duplication is so awful, I'm going to take a look at cleaning it up later. The fact that `ptr_get_alloc_id` can fail in this situation makes things annoying.
2022-05-30 23:43:51 +00:00
Ben Kimock
ba9391334e Add support for _COARSE clocks, spruce up comments 2022-05-30 11:26:10 -04:00
Ben Kimock
9a1475dbe2 Save a created event for zero-size reborrows 2022-05-29 16:45:26 -04:00
Ralf Jung
7cd5fc3de3 rustup 2022-05-29 14:06:35 +02:00
Ralf Jung
8c42ef1dee enable number validity checking and ptr::invalid checking by default 2022-05-25 16:17:41 +02:00
Oli Scherer
f1756c3ddd Add a custom ui test runner and move all tests to it 2022-05-25 13:31:26 +00:00
Jakob Degen
168c83a0b7 Adjust Miri to also require return places everywhere 2022-05-24 17:16:36 +02:00
Ralf Jung
697dca2e0e clean up int2ptr code a bit 2022-05-23 10:03:33 +02:00
bors
ab03d32622 Auto merge of #2059 - carbotaniuman:master, r=RalfJung
Initial work on Miri permissive-exposed-provenance

Miri portions of the changes for portions of a permissive ptr-to-int model for Miri. This is more restrictive than what we currently have so it will probably need a flag once I figure out how to hook that up.

> This implements a form of permissive exposed-address provenance, wherein the only way to expose the address is with a cast to usize (ideally expose_addr). This is more restrictive than C in that stuff like reading the representation bytes (via unions, type-punning, transmute) does not expose the address, only expose_addr. This is less restrictive than C in that a pointer casted from an integer has union provenance of all exposed pointers, not any udi stuff.

There's a few TODOs here, namely related to `fn memory_read` and friends. We pass it the maybe/unreified provenance before `ptr_get_alloc` reifies it into a concrete one, so it doesn't have the `AllocId` (or the SB tag, but that's getting ahead of ourselves). One way this could be fixed is changing `ptr_get_alloc` and (`ptr_try_get_alloc_id` on the rustc side) to return a pointer with the tag fixed up. We could also take in different arguments, but I'm not sure what works best.

The other TODOs here are how permissive this model could be. This currently does not enforce that a ptr-to-int cast happens before the corresponding int-to-ptr (colloquial meaning of happens before, not atomic meaning). Example:

```
let ptr = 0x2000 as *const i32;
let a: i32 = 5;
let a_ptr = &a as *const i32;

// value is 0x2000;
a_ptr as usize;

println!("{}", unsafe { *ptr }); // this is valid
```

We also allow the resulting pointer to dereference different non-contiguous allocations (the "not any udi stuff" mentioned above), which I'm not sure if is allowed by LLVM.

This is the Miri side of https://github.com/rust-lang/rust/pull/95826.
2022-05-23 07:24:33 +00:00
carbotaniuman
f7bc441fd3 Initial work on permissive provenance 2022-05-23 09:07:31 +02:00
bors
72e11d370a Auto merge of #2105 - thomcc:flip-failure-rate, r=RalfJung
Fix backwards `cmpxchg_weak_failure_rate` check

Uh, I guess I got this backwards a long time ago 😓.
2022-05-23 07:03:49 +00:00
Thom Chiovoloni
fdfbd7a658
Fix backwards cmpxchg_weak_failure_rate check 2022-05-22 20:24:08 -07:00
Ben Kimock
b20c6cfd81 Factor current-span logic into a lazy caching handle 2022-05-22 18:23:01 -04:00
Matthias Krüger
89da571b5d shims: fs: silence stderr instead of stdout.
Fixes #2143
2022-05-22 21:54:00 +02:00
Matthias Krüger
d7d7a9a162 [NFC] shims: fs: fmt 2022-05-22 21:47:44 +02:00
bors
e3227cfc7e Auto merge of #2141 - saethlin:early-diagnostics-ice, r=RalfJung
Adjust diagnostics assertion so we don't ICE in setup

Fixes https://github.com/rust-lang/miri/issues/2076 just by handling diagnostics produced during setup. The tracking notes don't have any spans but it's better than an ICE.

It looks like we leak allocations 1..20, and allocations 13..19 don't have any creation notes, and 14 only has a `FreedAlloc` alloc tracking diagnostic.
2022-05-22 16:17:17 +00:00
Ralf Jung
73534a678d
tweak comment 2022-05-22 18:16:59 +02:00
Ben Kimock
486a769935 Handle diagnotics emitted in runtime initialization 2022-05-22 11:28:40 -04:00
bors
d58abab2e7 Auto merge of #2142 - saethlin:cleanup-data-race-ice, r=oli-obk
Make allow_data_races_* public and use it during EnvVars::cleanup

Fixes https://github.com/rust-lang/miri/issues/2020

I've tried for hours now to come up with a test case for this ICE with no luck. I suspect there's something about the way the data race detection works under these conditions that I just don't understand 😩.

But I tried this change out on a handful of crates and I don't see any more ICEs of this form. For whatever reason it seems like `bastion==0.4.5` is a good way to run into this, with the flags
```
MIRIFLAGS="-Zmiri-tag-raw-pointers -Zmiri-panic-on-unsupported -Zmiri-disable-isolation" cargo +miri miri test --no-fail-fast --doc
```
I think all the cases I've run into with this involve both `-Zmiri-panic-on-unsupported` and `-Zmiri-tag-raw-pointers`, so it could be that the combination of an unexpected panic and a machine halt is required.
2022-05-22 06:18:29 +00:00
Mateusz Gienieczko
bd731508d4
Use precomputed layouts. 2022-05-22 01:01:12 +02:00
Mateusz Gienieczko
a40ff562a0
Add i16 and u16 primitive layout. 2022-05-22 01:00:59 +02:00
Mateusz Gienieczko
2fa53c0385
Dynamic offset calculation in GetSystemInfo. 2022-05-21 21:42:25 +02:00
Ben Kimock
3cfce6ffb2 Make allow_data_races_* public to silence data races during cleanup 2022-05-21 15:16:15 -04:00
Mateusz Gienieczko
63e98aee0c
Change GetSystemInfo to explicit offset. 2022-05-21 19:44:12 +02:00
Mateusz Gienieczko
c4ee368acb
Set page size in GetSystemInfo. 2022-05-21 18:17:25 +02:00
Ralf Jung
8b4d613cc8 rustup 2022-05-20 18:37:57 +02:00
bors
9230b92cf2 Auto merge of #2128 - saethlin:fix-creation-range, r=RalfJung
Pass the correct size to the AllocRange for log_creation

Fixes https://github.com/rust-lang/miri/issues/2127

I guess all I needed was a bit of sleep and reassurance that this diagnostic is the wrong part of that situation.
2022-05-19 15:08:22 +00:00
Ben Kimock
ada864f387 Pass the correct size to the AllocRange for log_creation 2022-05-19 09:29:08 -04:00
Ralf Jung
ea63a695c8 rustup 2022-05-15 12:58:28 +02:00
Ralf Jung
90a190e03b don't ICE when libcore is missing 2022-05-15 10:26:47 +02:00
bors
90d28eada1 Auto merge of #2116 - carbotaniuman:minimal-miri-changes, r=RalfJung
Minimal miri changes for rustc permissive provenance

Simple no-op changes to adapt to new API surface.
2022-05-15 07:11:51 +00:00
bors
98c8c8f9b5 Auto merge of #2030 - saethlin:track-alloc-history, r=oli-obk
Print spans where tags are created and invalidated

5225225 called this "automatic tag tracking" and I think that may be a reasonable description, but I would like to kill tag tracking as a primary use of Miri if possible. Tag tracking isn't always possible; for example if the UB is only detected with isolation off and the failing tag is made unstable by removing isolation. (also it's bad UX to run the tool twice)

This is just one of the things we can do with https://github.com/rust-lang/miri/pull/2024

The memory usage of this is _shockingly_ low, I think because the memory usage of Miri is driven by allocations where each byte ends up with its own very large stack. The memory usage in this change is linear with the number of tags, not tags * bytes. If memory usage gets out of control we can cap the number of events we save per allocation, from experience we tend to only use the most recent few in diagnostics but of course there's no guarantee of that so if we can manage to keep everything that would be best.

In many cases now I can tell exactly what these codebases are doing wrong just from the new outputs here, which I think is extremely cool.

New helps generated with plain old `cargo miri test` on `rust-argon2` v1.0.0:
```
test argon2::tests::single_thread_verification_multi_lane_hash ... error: Undefined Behavior: trying to reborrow <1485898> for Unique permission at alloc110523[0x0], but that tag does not exist in the borrow stack for this location
   --> /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/mem/manually_drop.rs:89:9
    |
89  |         slot.value
    |         ^^^^^^^^^^
    |         |
    |         trying to reborrow <1485898> for Unique permission at alloc110523[0x0], but that tag does not exist in the borrow stack for this location
    |         this error occurs as part of a reborrow at alloc110523[0x0..0x20]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <1485898> was created by a retag at offsets [0x0..0x20]
   --> src/memory.rs:42:13
    |
42  |             vec.push(unsafe { &mut (*ptr) });
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <1485898> was later invalidated at offsets [0x0..0x20]
   --> src/memory.rs:42:31
    |
42  |             vec.push(unsafe { &mut (*ptr) });
    |                               ^^^^^^^^^^^
```

And with `-Zmiri-tag-raw-pointers` on `slab` v0.4.5
```
error: Undefined Behavior: trying to reborrow <2915> for Unique permission at alloc1418[0x0], but that tag does not exist in the borrow stack for this location
   --> /tmp/slab-0.4.5/src/lib.rs:835:16
    |
835 |         match (&mut *ptr1, &mut *ptr2) {
    |                ^^^^^^^^^^
    |                |
    |                trying to reborrow <2915> for Unique permission at alloc1418[0x0], but that tag does not exist in the borrow stack for this location
    |                this error occurs as part of a reborrow at alloc1418[0x0..0x10]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <2915> was created by a retag at offsets [0x0..0x10]
   --> /tmp/slab-0.4.5/src/lib.rs:833:20
    |
833 |         let ptr1 = self.entries.get_unchecked_mut(key1) as *mut Entry<T>;
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: <2915> was later invalidated at offsets [0x0..0x20]
   --> /tmp/slab-0.4.5/src/lib.rs:834:20
    |
834 |         let ptr2 = self.entries.get_unchecked_mut(key2) as *mut Entry<T>;
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

And without raw pointer tagging, `cargo miri test` on `half` v1.8.2
```
error: Undefined Behavior: trying to reborrow <untagged> for Unique permission at alloc1340[0x0], but that tag only grants SharedReadOnly permission for this location
   --> /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/slice/raw.rs:141:9
    |
141 |         &mut *ptr::slice_from_raw_parts_mut(data, len)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |         |
    |         trying to reborrow <untagged> for Unique permission at alloc1340[0x0], but that tag only grants SharedReadOnly permission for this location
    |         this error occurs as part of a reborrow at alloc1340[0x0..0x6]
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: tag was most recently created at offsets [0x0..0x6]
   --> /tmp/half-1.8.2/src/slice.rs:309:22
    |
309 |         let length = self.len();
    |                      ^^^^^^^^^^
help: this tag was also created here at offsets [0x0..0x6]
   --> /tmp/half-1.8.2/src/slice.rs:308:23
    |
308 |         let pointer = self.as_ptr() as *mut u16;
    |                       ^^^^^^^^^^^^^
```
The second suggestion is close to guesswork, but from experience it tends to be correct (as in, it tends to locate the pointer the user wanted) more often that it doesn't.
2022-05-14 19:27:04 +00:00
carbotaniuman
f8478df6dc Bump rustc for permissive provenance 2022-05-14 13:03:47 -05:00
Ben Kimock
8ff0aac06c More review feedback
* Store the local crates in an Rc<[CrateNum]>
* Move all the allocation history into Stacks
* Clean up the implementation of get_logs_relevant_to a bit
2022-05-13 19:04:51 -04:00
Ralf Jung
fde022007b data_race: use glob import like most files 2022-05-13 23:19:17 +02:00