Commit Graph

267 Commits

Author SHA1 Message Date
Ralf Jung e649a9acfb check for extern static size mismatches 2022-07-20 18:32:03 -04:00
Ralf Jung 59f9a918ed handle get_alloc_extra the same throughout Stacked Borrows 2022-07-20 17:57:31 -04:00
Ralf Jung ff4666f39c rustup 2022-07-20 16:02:06 -04:00
bors 8757d866ab Auto merge of #2350 - RalfJung:remove-deprecated, r=oli-obk
remove deprecated options

These have been deprecated a month ago and nobody said they need them. Is that enough time? We can also let this PR sit a little.

Cc https://github.com/rust-lang/miri/issues/2187 https://github.com/rust-lang/miri/issues/2188
(keeping them open to track removing their supporting infrastructure in the core interpreter)
2022-07-19 12:29:29 +00:00
Ben Kimock 4eff60ad6e Rearrange and document the new implementation
stacked_borrow now has an item module, and its own FrameExtra. These
serve to protect the implementation of Item (which is a bunch of
bit-packing tricks) from the primary logic of Stacked Borrows, and the
FrameExtra we have separates Stacked Borrows more cleanly from the
interpreter itself.

The new strategy for checking protectors also makes some subtle
performance tradeoffs, so they are now documented in Stack::item_popped
because that function primarily benefits from them, and it also touches
every aspect of them.

Also separating the actual CallId that is protecting a Tag from the Tag
makes it inconvienent to reproduce exactly the same protector errors, so
this also takes the opportunity to use some slightly cleaner English in
those errors. We need to make some change, might as well make it good.
2022-07-12 21:03:54 -04:00
Ben Kimock afa1dddcf9 Store protectors outside Item, pack Tag and Perm
Previously, Item was a struct of a NonZeroU64, an Option which was
usually unset or irrelevant, and a 4-variant enum. So collectively, the
size of an Item was 24 bytes, but only 8 bytes were used for the most
part.

So this takes advantage of the fact that it is probably impossible to
exhaust the total space of SbTags, and steals 3 bits from it to pack the
whole struct into a single u64. This bit-packing means that we reduce
peak memory usage when Miri goes memory-bound by ~3x. We also get CPU
performance improvements of varying size, because not only are we simply
accessing less memory, we can now compare a Vec<Item> using a memcmp
because it does not have any padding.
2022-07-12 21:01:33 -04:00
Ralf Jung 49a6c230cb remove deprecated options 2022-07-11 21:28:54 -04:00
Ralf Jung 5fed3ebc26 adjust code for copy_op changes 2022-07-06 21:40:31 -04:00
Ralf Jung 501a6b4687 rustup 2022-07-06 14:06:15 -04:00
Ralf Jung 907a003f14 tweak format strings 2022-07-06 09:47:48 -04:00
Ralf Jung f3f4bafa1b rustup 2022-07-05 18:16:20 -04:00
Ralf Jung d9c441c5ab put call to stacked borrows end_call in a more sensible place 2022-07-02 18:38:07 -04:00
InfRandomness 5ec25359ff Add environ extern implementation to freebsd
Signed-off-by: InfRandomness <infrandomness@gmail.com>
2022-07-02 12:42:14 +02:00
Ralf Jung dfdedae840 avoid copying thread manager state in data race detector 2022-07-01 17:07:29 -04:00
Ralf Jung 7f3fbbdee7 allocation tracking: also print size, alignment, kind of the allocation 2022-06-30 22:24:23 -04:00
Ralf Jung c4e86e103e add option for recursive field retagging 2022-06-29 18:22:30 -04:00
Ralf Jung 5c16713056 remove support for untagged pointers
good riddance!
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
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
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 c0f7118342 reorganize exposure code a bit 2022-06-24 16:45:22 -04:00
carbotaniuman 57ce47b728 Handle wildcard pointers in SB 2022-06-24 16:10:23 -04: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 657386cc91 rustup 2022-06-08 12:10:54 -04:00
Ralf Jung b64c9a0a83 make scheduler preemptive, with configurable preemption rate 2022-06-06 20:16:02 -04:00
Andy Wang 8215702d5a Refer to GitHub issue on overwritten init value 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 226ed41cca Destroy store buffers on non-racy non-atomic accesses 2022-06-06 19:15:58 +01:00
Andy Wang 8739e45bef Move data_race and weak_memory into a submodule 2022-06-06 19:15:53 +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 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
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
Ralf Jung 151b6b13e0 clippy: main crate 2022-06-04 13:29:00 -04:00
Ralf Jung e79a331fea do not pass TyCtxt by reference 2022-06-02 15:11:22 -04: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
carbotaniuman f7bc441fd3 Initial work on permissive provenance 2022-05-23 09:07:31 +02:00
Ben Kimock b20c6cfd81 Factor current-span logic into a lazy caching handle 2022-05-22 18:23:01 -04:00
Mateusz Gienieczko a40ff562a0 Add i16 and u16 primitive layout. 2022-05-22 01:00:59 +02:00
Ralf Jung 8b4d613cc8 rustup 2022-05-20 18:37:57 +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