Commit Graph

6154 Commits

Author SHA1 Message Date
Ralf Jung
830cc58f8a rustup 2022-04-03 20:00:03 -04:00
Ralf Jung
3dcba56349 add test for nasty example 2022-04-02 00:05:27 -04:00
Ralf Jung
1d79b60a1e make strict-provenance imply check-number-validity 2022-04-01 23:59:16 -04:00
bors
732461b4cd Auto merge of #2045 - RalfJung:strict-provenance, r=RalfJung
add -Zmiri-strict-provenance

This implements [strict provenance](https://github.com/rust-lang/rust/issues/95228) in Miri. The only change is that casting an integer to a pointer does not even attempt to produce a good provenance for the given address; instead, it always uses the invalid provenance. This stricter than even `-Zmiri-tag-raw-pointers` in that it also rejects the following example (which does not even involve Stacked Borrows):
```rust
fn main() {
    let x = 22;
    let ptr = &x as *const _ as *const u8;
    let roundtrip = ptr as usize as *const u8;
    let _ = unsafe { roundtrip.offset(1) };
}
```
The new flag also implies `-Zmiri-tag-raw-pointers` since the only reason one would *not* want to tag raw pointers is to support ptr-int-ptr roundtrips.

Note that the flag does *not* check against ptr-to-int *transmutes*; that still requires `-Zmiri-check-number-validity`. You can also check for strict provenance *without* Stacked Borrows by adding `-Zmiri-disable-stacked-borrows`.

The new "Miri hard mode" flags for maximal checking are `-Zmiri-strict-provenance -Zmiri-check-number-validity`. (Add `-Zmiri-symbolic-alignment-check` if you feel extra spicy today.)
2022-04-01 22:40:26 +00:00
bors
5d5d8b17cc Auto merge of #2043 - RalfJung:max-size, r=RalfJung
Rust values can be up to isize::MAX in size

Needs https://github.com/rust-lang/rust/pull/95388
2022-04-01 21:22:59 +00:00
Ralf Jung
e13668092c rustup 2022-04-01 17:22:11 -04:00
Ralf Jung
aa04dc1eeb Rust values can be up to isize::MAX in size 2022-04-01 17:22:01 -04:00
Ralf Jung
9af03bf342 add -Zmiri-strict-provenance 2022-04-01 14:10:24 -04:00
bors
6e1ed17295 Auto merge of #2044 - RalfJung:int_log, r=RalfJung
test int_log functions

I'll have to disable many of their tests in libcore since they take too long, so let's add some of them back on our side here.
2022-03-31 15:22:18 +00:00
Ralf Jung
811e6dd71d test int_log functions 2022-03-31 11:20:24 -04:00
bors
c1bbf078f3 Auto merge of #2040 - RalfJung:pnvi, r=RalfJung
ensure that -Zmiri-check-number-validity detects integers with provenance

This actually currently *fails* for the non-array case; I will have to fix this on the rustc side.
2022-03-27 14:02:02 +00:00
bors
80fe3b1246 Auto merge of #2042 - TaKO8Ki:add-vscode-dir-to-gitignore, r=RalfJung
Add `.vscode` directory to `.gitignore`

Add `.vscode` directory to `.gitignore` for configuring `rust-analyzer`
2022-03-27 13:41:38 +00:00
Ralf Jung
f3c35d5105 rustup 2022-03-27 09:40:46 -04:00
Takayuki Maeda
0beb318b04 add .vscode to .gitignore 2022-03-27 18:41:40 +09:00
Ralf Jung
5d7c495de5 channels do ptr-int transmutes so move them to non-check-number-validity test 2022-03-26 14:33:17 -04:00
Ralf Jung
552b77e3b9 fix types in env shim to avoid ptr-int transmutes 2022-03-26 14:33:13 -04:00
Ralf Jung
ede470e1fc ensure that -Zmiri-check-number-validity detects integers with provenance 2022-03-26 14:33:13 -04:00
bors
017b0fb737 Auto merge of #2039 - RalfJung:too-big, r=RalfJung
another test for too big type

The existing test covers "slice is bigger than largest supported object" but we had no test covering "total size is bigger than largest supported object", which happens when the unsized tail itself is okay in terms of size, but together with the sized prefix it becomes too big.

Cc https://github.com/rust-lang/rust/issues/95334
2022-03-26 15:08:43 +00:00
Ralf Jung
9772c85ebc another test for too big type 2022-03-26 11:08:11 -04:00
bors
346f8f2219 Auto merge of #2036 - RalfJung:vec, r=RalfJung
regression test for reverse() unsoundness

Cc https://github.com/rust-lang/rust/pull/90821
2022-03-24 14:33:02 +00:00
bors
d46b648f85 Auto merge of #2038 - RalfJung:rustup, r=RalfJung
rustup
2022-03-24 14:07:06 +00:00
Ralf Jung
3275df31ea rustup 2022-03-24 10:06:33 -04:00
Ralf Jung
951ac65f26 regression test for reverse() unsoundness 2022-03-22 14:28:36 -04:00
Ralf Jung
694846f8b4 vec test: check number validity 2022-03-22 14:26:40 -04:00
bors
16c69fd290 Auto merge of #2033 - RalfJung:arbitrary-self-dyn, r=RalfJung
test arbitrary-self dyn receivers

Requires https://github.com/rust-lang/rust/pull/95071
2022-03-20 18:04:55 +00:00
Ralf Jung
b066856f34 rustup 2022-03-20 14:04:05 -04:00
Ralf Jung
aafc0694fc test arbitrary-self dyn receivers 2022-03-20 14:03:46 -04:00
bors
a64e6fd1b6 Auto merge of #2022 - RalfJung:remove_dir_all, r=RalfJung
test remove_dir_all

Blocked on https://github.com/rust-lang/rust/pull/94749

Cc https://github.com/rust-lang/miri/issues/1966
2022-03-20 14:38:27 +00:00
Ralf Jung
1cda05e174 rustup 2022-03-20 10:36:44 -04:00
Ralf Jung
65469fe85b test remove_dir_all 2022-03-20 10:36:27 -04:00
bors
57786678d4 Auto merge of #1975 - DrMeepster:backtrace_fix, r=RalfJung
Make backtraces work with #[global_allocator]

Currently, backtraces break when the global allocator is overridden because the allocator will attempt to deallocate memory allocated directly by Miri.

~~This PR fixes that by using a new memory kind and providing a function to deallocate it. We can't call the custom allocator to allocate because it's not possible to call a function in the middle of a shim.~~

This PR fixes that by adding a new version of the backtrace API accessible by setting `flags` to 1. Existing code still functions.

backtrace-rs PR: rust-lang/backtrace-rs#462

Fixes https://github.com/rust-lang/miri/issues/1996
2022-03-20 02:37:09 +00:00
DrMeepster
2c670b10df add new version of backtrace api using flags=1 2022-03-19 18:14:11 -07:00
bors
5d72cd987b Auto merge of #2024 - saethlin:better-local-check, r=RalfJung
Consider the cargo workspace when checking if a frame is local

`DefId::is_local` returns a result which is technically correct, but doesn't match the user's intuition when running integration tests or doctests. This incorporates the workspace crates mentioned in `cargo metadata` into the check for whether a frame is local to match user intuition.

For example, here is the backtrace you get from `MIRIFLAGS=-Zmiri-tag-raw-pointers cargo miri test` in `bytes` 1.1.0:
```
   --> /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/slice/raw.rs:131:14
    |
131 |     unsafe { &mut *ptr::slice_from_raw_parts_mut(data, len) }
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trying to reborrow for Unique at alloc67158, but parent tag <untagged> does not have an appropriate item in the borrow stack
    |
    = 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::slice::from_raw_parts_mut::<u8>` at /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/slice/raw.rs:131:14
    = note: inside `bytes::bytes::rebuild_boxed_slice` at /tmp/bytes-1.1.0/src/bytes.rs:938:19
    = note: inside closure at /tmp/bytes-1.1.0/src/bytes.rs:904:18
    = note: inside `<std::sync::atomic::AtomicPtr<()> as bytes::loom::sync::atomic::AtomicMut<()>>::with_mut::<[closure@bytes::bytes::promotable_even_drop::{closure#0}], ()>` at /tmp/bytes-1.1.0/src/loom.rs:17:17
    = note: inside `bytes::bytes::promotable_even_drop` at /tmp/bytes-1.1.0/src/bytes.rs:895:5
    = note: inside `<bytes::Bytes as std::ops::Drop>::drop` at /tmp/bytes-1.1.0/src/bytes.rs:515:18
    = note: inside `std::ptr::drop_in_place::<bytes::Bytes> - shim(Some(bytes::Bytes))` at /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:188:1
note: inside `copy_to_bytes_less` at tests/test_buf.rs:112:1
   --> tests/test_buf.rs:112:1
    |
112 | }
    | ^
note: inside closure at tests/test_buf.rs:106:1
   --> tests/test_buf.rs:106:1
    |
105 |   #[test]
    |   ------- in this procedural macro expansion
106 | / fn copy_to_bytes_less() {
107 | |     let mut buf = &b"hello world"[..];
108 | |
109 | |     let bytes = buf.copy_to_bytes(5);
110 | |     assert_eq!(bytes, &b"hello"[..]);
111 | |     assert_eq!(buf, &b" world"[..])
112 | | }
    | |_^
    = note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
```
We get these because the integration tests are occurring in a crate called `test`, not the actual `bytes` crate. With this PR, we get this:
```
    = note: inside `std::slice::from_raw_parts_mut::<u8>` at /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/slice/raw.rs:131:14
note: inside `bytes::bytes::rebuild_boxed_slice` at /tmp/bytes-1.1.0/src/bytes.rs:938:19
   --> /tmp/bytes-1.1.0/src/bytes.rs:938:19
    |
938 |     Box::from_raw(slice::from_raw_parts_mut(buf, cap))
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure at /tmp/bytes-1.1.0/src/bytes.rs:904:18
   --> /tmp/bytes-1.1.0/src/bytes.rs:904:18
    |
904 |             drop(rebuild_boxed_slice(buf, ptr, len));
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside `<std::sync::atomic::AtomicPtr<()> as bytes::loom::sync::atomic::AtomicMut<()>>::with_mut::<[closure@bytes::bytes::promotable_even_drop::{closure#0}], ()>` at /tmp/bytes-1.1.0/src/loom.rs:17:17
   --> /tmp/bytes-1.1.0/src/loom.rs:17:17
    |
17  |                 f(self.get_mut())
    |                 ^^^^^^^^^^^^^^^^^
note: inside `bytes::bytes::promotable_even_drop` at /tmp/bytes-1.1.0/src/bytes.rs:895:5
   --> /tmp/bytes-1.1.0/src/bytes.rs:895:5
    |
895 | /     data.with_mut(|shared| {
896 | |         let shared = *shared;
897 | |         let kind = shared as usize & KIND_MASK;
898 | |
...   |
905 | |         }
906 | |     });
    | |______^
note: inside `<bytes::Bytes as std::ops::Drop>::drop` at /tmp/bytes-1.1.0/src/bytes.rs:515:18
   --> /tmp/bytes-1.1.0/src/bytes.rs:515:18
    |
515 |         unsafe { (self.vtable.drop)(&mut self.data, self.ptr, self.len) }
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: inside `std::ptr::drop_in_place::<bytes::Bytes> - shim(Some(bytes::Bytes))` at /home/ben/.rustup/toolchains/miri/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:188:1
note: inside `copy_to_bytes_less` at tests/test_buf.rs:112:1
   --> tests/test_buf.rs:112:1
    |
112 | }
    | ^
note: inside closure at tests/test_buf.rs:106:1
   --> tests/test_buf.rs:106:1
    |
105 |   #[test]
    |   ------- in this procedural macro expansion
106 | / fn copy_to_bytes_less() {
107 | |     let mut buf = &b"hello world"[..];
108 | |
109 | |     let bytes = buf.copy_to_bytes(5);
110 | |     assert_eq!(bytes, &b"hello"[..]);
111 | |     assert_eq!(buf, &b" world"[..])
112 | | }
    | |_^
    = note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
```

Note that this kind of inflation is rather rare to see. Most backtraces change not at all or only a tiny bit.

I originally implemented this to support another improvement to Miri diagnostics, but I think this is hairy enough to deserve its own PR, if somewhat poorly-motivated.
2022-03-18 20:38:37 +00:00
Ben Kimock
65125df1cd Consider the cargo workspace when checking if a frame is local 2022-03-18 16:28:13 -04:00
bors
8e818ffa1b Auto merge of #2029 - RalfJung:simd-bitmask, r=RalfJung
implement simd bitmask intrinsics

Cc https://github.com/rust-lang/miri/issues/1912
2022-03-17 17:18:01 +00:00
Ralf Jung
1b1321a685 fix simd_bitmask shorter than a byte on big-endian 2022-03-17 13:14:16 -04:00
Ralf Jung
b5d3a25b49 detect when unused bits of a SIMD bitmask are non-0 2022-03-17 13:08:01 -04:00
Ralf Jung
bfed3c4f0d implement simd bitmask intrinsics 2022-03-17 13:08:01 -04:00
bors
670dc7d551 Auto merge of #1971 - saethlin:sb-details, r=RalfJung
Add a lot more information to SB fatal errors

In fatal errors, this clarifies the difference between a tag not being present in the borrow stack at all, and the tag being present but granting SRO. It also introduces a little notation for memory ranges so we can mention to the user that the span may point to code that operates on multiple memory locations, but we are reporting an error at a particular offset.

This also gets rid of the unqualified phrase "the borrow stack" in errors, and clarifies that it is the borrow stack _for some location_.

The crate `pdqselect` v0.1.1:
Before:
```
2103 |     unsafe { copy_nonoverlapping(src, dst, count) }
     |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item granting read access to tag <2357> at alloc1029 found in borrow stack.
```
After:
```
2103 |     unsafe { copy_nonoverlapping(src, dst, count) }
     |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |              |
     |              attempting a read access using <2357> at alloc1029[0x0], but that tag does not exist in the borrow stack for this location
     |              this error occurs as part of an access at alloc1029[0x0..0x4]
```

And the crate `half` v1.8.2
Before:
```
131 |     unsafe { &mut *ptr::slice_from_raw_parts_mut(data, len) }
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trying to reborrow for Unique at alloc1051, but parent tag <2091> does not have an appropriate item in the borrow stack
```
After:
```
131 |     unsafe { &mut *ptr::slice_from_raw_parts_mut(data, len) }
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |              |
    |              trying to reborrow <2091> for Unique permission at alloc1051[0x0], but that tag only grants SharedReadOnly permission for this location
    |              this error occurs as part of a reborrow at alloc1051[0x0..0x6]
```
2022-03-17 13:26:29 +00:00
bors
a33f1a682d Auto merge of #2031 - RalfJung:simd, r=RalfJung
implement SIMD sqrt and fma

Cc https://github.com/rust-lang/miri/issues/1912
2022-03-17 02:15:16 +00:00
Ralf Jung
4fd5dca27c implement SIMD sqrt and fma 2022-03-16 22:13:43 -04:00
Ben Kimock
730cd27248 Print more in SB error diagnostics
This tries to clarify exactly why an access is not valid by printing
what memory range the access was over, which in combination with
tag-tracking may help a user figure out the source of the problem.
2022-03-16 20:12:04 -04:00
bors
a9a0d0e5e7 Auto merge of #2028 - RalfJung:simd-round, r=RalfJung
implement SIMD float rounding functions

Cc https://github.com/rust-lang/miri/issues/1912
2022-03-16 23:30:19 +00:00
Ralf Jung
1f237b3b7d implement SIMD float rounding functions 2022-03-16 18:53:36 -04:00
Ralf Jung
202964127b implement fabs using soft floats 2022-03-16 18:33:59 -04:00
bors
39c72db3d3 Auto merge of #2026 - jakevossen5:master, r=RalfJung
missing backtick on miri-isolation warning help

Just ran into this and figured I could fix it real quick 🙂
2022-03-16 17:10:44 +00:00
Jake Vossen
559e495195 missing backtick on miri-isolation warning help 2022-03-16 10:18:51 -06:00
bors
dce1a1b94f Auto merge of #2023 - RalfJung:simd-min-max, r=RalfJung
test integer SIMD min/max

Blocked on portable-simd getting updated in rustc.
2022-03-14 13:54:19 +00:00
Ralf Jung
f338b0229b test integer SIMD min/max 2022-03-14 09:53:49 -04:00
bors
7bc0c98621 Auto merge of #2025 - workingjubilee:fix-nightly-simd, r=RalfJung
Fixup renamed fn for Simd

This fixes rust-lang/rust#94910
2022-03-14 02:07:23 +00:00