rust-lang / miri

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

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

Open RalfJung opened 2 months ago

RalfJung commented 2 months 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 2 months 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 2 months ago

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

badumbatish commented 2 months ago

can i have a try at this?

RalfJung commented 1 month ago

Sure. :) I'd suggest to start with just one file and fix the deref_pointer there, to make sure you get the hang of this.

Unfortunately I won't have the time to provide a lot of mentoring. You can always try Zulip, there are other people there that can help.