Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RalfJung opened this issue Aug 24, 2024 · 4 comments
Open
Labels
A-shims Area: This affects the external function shims C-cleanup Category: cleaning up our code E-good-first-issue A good way to start contributing, mentoring is available

Comments

@RalfJung
Copy link
Member

RalfJung commented Aug 24, 2024

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 #3839.

To help with this, do the following:

  • rg -w deref_pointer src/shims
  • Pick one of the remaining places where we call deref_pointer
  • Figure out which type that argument is supposed to have
  • Replace the call with deref_pointer_as and the correct type

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. :)

@RalfJung RalfJung added A-shims Area: This affects the external function shims E-good-first-issue A good way to start contributing, mentoring is available C-cleanup Category: cleaning up our code labels Aug 24, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Aug 24, 2024

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
Copy link
Member Author

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

@badumbatish
Copy link

can i have a try at this?

@RalfJung
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-shims Area: This affects the external function shims C-cleanup Category: cleaning up our code E-good-first-issue A good way to start contributing, mentoring is available
Projects
None yet
Development

No branches or pull requests

3 participants