rust-lang / miri

An interpreter for Rust's mid-level intermediate representation
Apache License 2.0
4.34k stars 332 forks source link

Shims cannot trust user-defined types, need to always use `deref_pointer_as` #3841

Open RalfJung opened 1 month ago

RalfJung commented 1 month ago

Calling deref_pointer means we create a place at whatever type that argument was declared at by the user. But we can't trust that type, we should ideally entirely ignore it and use deref_pointer_as everywhere. Failure to do so can lead to ICEs like https://github.com/rust-lang/miri/issues/3839.

To help with this, do the following:

Getting the correct type will be the hardest part of this, and it depends on what the correct type is. Many basic types are available in this.machine.layouts, but struct types need to be looked up in libc/std or maybe we even have to construct one ourselves (or entirely change the code). If you are unsure about a concrete case, just ask here. :)

oli-obk commented 1 month ago

Once all of them are converted we should probably add a ./miri tidy (or make it part of ./miri check and similar commands) that automatically greps and asserts that there are no new ones introduced

RalfJung commented 1 month ago

Ah yes that's a good low-tech solution.

badumbatish commented 1 week ago

can i have a try at this?