Commit Graph

6305 Commits

Author SHA1 Message Date
bors
a5cf247469 Auto merge of #2126 - RalfJung:typo, r=RalfJung
I cannot type
2022-05-17 16:59:56 +00:00
Ralf Jung
6b6f92d4bc I cannot type 2022-05-17 18:59:27 +02:00
bors
3971d3cbb3 Auto merge of #2124 - RalfJung:rustup-toolchain, r=RalfJung
rustup-toolchain: also prepare toolchain for vscode

This is a work-around for https://github.com/rust-lang/cargo/issues/10096.
2022-05-17 13:40:16 +00:00
Ralf Jung
3406829bb3 rustup-toolchain: also prepare toolchain for vscode 2022-05-17 15:36:59 +02:00
bors
19ef76477c Auto merge of #2122 - RalfJung:rustup, r=RalfJung
rustup

I am on mobile and so I couldn't test this... let's see how it goes. ;)
2022-05-15 10:58:41 +00:00
Ralf Jung
ea63a695c8 rustup 2022-05-15 12:58:28 +02:00
bors
8f7c8f7808 Auto merge of #2121 - RalfJung:less-ice, r=RalfJung
don't ICE when libcore is missing

Fixes https://github.com/rust-lang/miri/issues/2120
2022-05-15 08:27:43 +00: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
bors
d76c2c5e1c Auto merge of #2119 - RalfJung:glob, r=RalfJung
data_race: use glob import like most files
2022-05-13 21:19:59 +00:00
Ralf Jung
fde022007b data_race: use glob import like most files 2022-05-13 23:19:17 +02:00
bors
3f111c166a Auto merge of #2114 - cbeuw:shim-rmw, r=RalfJung
Use atomic RMW for `{mutex, rwlock, cond, srwlock}_get_or_create_id` functions

This is required for #1963

`{mutex, rwlock, cond, srwlock}_get_or_create_id()` currently checks whether an ID field is 0 using an atomic read, allocate one and get a new ID if it is, then write it in a separate atomic write. This is fine without weak memory. For instance, in `pthread_mutex_lock` which may be called by two threads concurrently, only one thread can read 0, create and then write a new ID, the later-run thread will always see the newly created ID and never 0.
```rust
    fn pthread_mutex_lock(&mut self, mutex_op: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
        let this = self.eval_context_mut();

        let kind = mutex_get_kind(this, mutex_op)?.check_init()?;
        let id = mutex_get_or_create_id(this, mutex_op)?;
        let active_thread = this.get_active_thread();
```

However, with weak memory behaviour, both threads may read 0: the first thread has to see 0 because nothing else was written to it, and the second thread is not guaranteed to observe the latest value, causing a duplicate mutex to be created and both threads "successfully" acquiring the lock at the same time.

This is a pretty typical pattern requiring the use of atomic RMWs. RMW *always* reads the latest value in a location, so only one thread can create the new mutex and ID, all others scheduled later will see the new ID.
2022-05-13 19:04:59 +00:00
Andy Wang
9e38dc4d49
Move and rename offset_and_layout_to_place to deref_operand_and_offset 2022-05-13 18:42:53 +01:00
Andy Wang
10d978c180
Inline _create() calls and add assertions 2022-05-12 21:06:17 +01:00
Andy Wang
a5db2c32e5
Refactor to hide *_next_id functions 2022-05-12 20:31:40 +01:00
bors
d33e7fc31c Auto merge of #2117 - RalfJung:rustup, r=RalfJung
rustup

Cc https://github.com/rust-lang/rust/issues/96975
2022-05-12 17:02:04 +00:00
Ralf Jung
19e1c72a77 rustup 2022-05-12 19:01:04 +02:00
bors
5887b2b185 Auto merge of #2115 - rust-lang:comment_nit, r=oli-obk
Update a path to libstd source in our comments

Taken from review in https://github.com/rust-lang/miri/pull/2101
2022-05-12 10:43:48 +00:00
Oli Scherer
0ee9d3d047 Update a path to libstd source in our comments 2022-05-12 10:42:53 +00:00
Ben Kimock
972b3b340a Cleanup/Refactoring from review
* Pass a ThreadInfo down to grant/access to get the current span lazily
* Rename add_* to log_* for clarity
* Hoist borrow_mut calls out of loops by tweaking the for_each signature
* Explain the parameters of check_protector a bit more
2022-05-11 20:07:44 -04:00
Andy Wang
1a7f6d504a
Use proper atomic rmw for {mutex, rwlock, cond, srwlock}_get_or_create_id 2022-05-11 22:42:39 +01:00
bors
f84a976a77 Auto merge of #2113 - RalfJung:rustc-log, r=RalfJung
when MIRI_LOG is set, set RUSTC_LOG_ENTRY_EXIT

This will be useful once https://github.com/rust-lang/rust/pull/96898 landed.
2022-05-11 09:29:43 +00:00
Ralf Jung
c15845bf29 when MIRI_LOG is set, set RUSTC_LOG_ENTRY_EXIT 2022-05-11 10:04:30 +02:00
bors
e49ee8d8b6 Auto merge of #2112 - y86-dev:clarify-custom-rustc-issues, r=RalfJung
Clarified issues when building miri with a custom rustc

I came across these issues (see zulip threads [here](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20Changes.20not.20in.20effect) and [here](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Missing.20.2Elibrustc.2Estamp), issue [here](https://github.com/rust-lang/rust/issues/90244)) and would like to add this small bit to the docs. Feel free to change the wording.
2022-05-10 19:38:52 +00:00
Ralf Jung
4632b2c689
tweak wording 2022-05-10 21:38:32 +02:00
y86-dev
b25d7b0e34 Clarified issues when building miri with a custom rustc
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-05-10 21:30:45 +02:00
bors
6005f5d214 Auto merge of #2111 - RalfJung:python, r=RalfJung
stop relying on python being in the PATH

Even Debian removed the package that provides `/usr/bin/python`; I guess it is time to move on.
2022-05-10 10:21:33 +00:00
Ralf Jung
a2f6837574 rustfmt 2022-05-10 12:21:01 +02:00
Ralf Jung
82411c5840 stop relying on python being in the PATH 2022-05-10 12:20:55 +02:00
bors
36c274aa38 Auto merge of #2084 - rust-lang:silence, r=RalfJung
Add a command line flag to avoid printing to stdout and stderr

This is practical for tests that don't actually care about the output and thus don't want it intermingled with miri's warnings, errors or ICEs

fixes #2083
2022-05-10 07:24:07 +00:00
Oli Scherer
6dc6256413 Wording nit 2022-05-10 07:23:50 +00:00
Oli Scherer
c8b947a5ed Use alphabetical order for miri flags 2022-05-10 07:23:03 +00:00
bors
1abf2cf9dd Auto merge of #2109 - RalfJung:fmt, r=RalfJung
rustfmt
2022-05-09 09:18:52 +00:00
Ralf Jung
8dbe1d02cd rustfmt 2022-05-09 11:17:52 +02:00
bors
f791e2ee50 Auto merge of #2108 - RalfJung:rustup, r=RalfJung
rustup

Adjusts for https://github.com/rust-lang/rust/pull/96657. For now we use the fallback path in libstd.
2022-05-09 08:22:07 +00:00
Ralf Jung
5a6c4a60fe rustup 2022-05-09 10:21:15 +02:00
bors
8b9107a05d Auto merge of #2107 - RalfJung:err, r=RalfJung
test for "erroneous constant used" post-monomorphization error

Fixes https://github.com/rust-lang/miri/issues/2106
2022-05-08 15:57:22 +00:00
Ralf Jung
d585b92fe3 test for "erroneous constant used" post-monomorphization error 2022-05-08 17:56:09 +02:00
bors
3b8b6aa8b6 Auto merge of #2103 - RalfJung:rustup, r=RalfJung
rustup
2022-05-06 15:28:39 +00:00
Ralf Jung
9605ae807d rustup 2022-05-06 17:28:01 +02:00
bors
64eedc1afa Auto merge of #2100 - RalfJung:readme, r=RalfJung
tweak MIRI_SYSROOT docs
2022-05-05 08:29:12 +00:00
Ralf Jung
9bb4410d3a tweak MIRI_SYSROOT docs 2022-05-05 10:28:40 +02:00
bors
d595c6225d Auto merge of #2098 - RalfJung:papers, r=RalfJung
mention some papers that use Miri
2022-05-01 11:45:31 +00:00
Ralf Jung
1e49078a54 mention some papers that use Miri 2022-05-01 13:44:12 +02:00
bors
4bb36593e9 Auto merge of #2094 - dtolnay-contrib:truncate, r=RalfJung
Replace `as` casts in llvm.x86.addcarry.64 implementation

Recommended in https://github.com/rust-lang/miri/pull/2090#pullrequestreview-958491177.
2022-05-01 07:06:57 +00:00
bors
49366abfb0 Auto merge of #2095 - dtolnay-contrib:ref, r=RalfJung
Replace unneeded use of `ref` in favor of "match ergonomics"

The signature of `check_shim` is very amenable to this.

```rust
fn check_shim<'a, const N: usize>(…) -> InterpResult<'tcx, &'a [OpTy<'tcx, Tag>; N]>
```

Instead of:

```rust
let &[ref ptr, ref flags] = this.check_shim(…)?;
```

we can write it just as:

```rust
let [ptr, flags] = this.check_shim(…)?;
```
2022-05-01 06:34:32 +00:00
Ben Kimock
68ab457aa0 Pass AccessKind to check_protector 2022-04-30 14:59:00 -04:00