-
Notifications
You must be signed in to change notification settings - Fork 356
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
Unix: munmap
emits "warning: integer-to-pointer cast"
#3041
Comments
Every munmap is an implicit integer-to-pointer cast in the way we have modeled it -- the provenance of the pointer does not matter, only the address does. Making the provenance matter would probably fail some theoretically legal code, though I don't know if that's code anyone would actually write... Cc @saethlin |
Yeah this is deliberate and is not well-explained in the code. I think ideally the thing to do here is to try the |
We could also say that if the pointer has some provenance then we enforce it, but if it's a What is the usecase for not requiring provenance? |
If we require provenance then you can't do things like |
We don't even support putting new pages at the end of an existing allocation (you cannot map a ta fixed address), so currently this case cannot really occur. |
Yes, I punted on implementing |
FWIW this is related to rust-lang/unsafe-code-guidelines#430 -- as of now it doesn't seem entirely clear that Rust allows such in-place growing of allocations.
But that means that the code you are worried about wouldn't report UB even if we were to make provenance matter for So, that's not an argument against making provenance matter. |
My argument (you originally asked for a use case) is that Miri shouldn't have shims that report UB when the man pages for the shims indicate that such use is valid.
Which I think means that this program is intended to be well-defined and map then unmap an address range:
And we have a test for this: miri/tests/pass-dep/shims/mmap.rs Lines 31 to 34 in 0970421
|
As the reporter, is there some way to suppress this single warning, without suppressing all strict provenance warnings? |
I am not at all convinced that the manpage allows your testcase. It is just not written precisely enough to infer much about provenance. If a mapping was created at a fixed address, then I could see the argument that one can munmap it via Your testcase would also still pass with the semantics I proposed above. Those semantics do violate provenance monotonicity, but this is all just an approximate model anyway so I'm not too bothered by that.
No, unfortunately not. @saethlin is basically arguing that mmap is fundamentally not a strict provenance compatible operation, and that's what Miri currently reflects. |
Given LLVM behavior such as this and this, I'm less and less convinced that the usage patterns you are describing, @saethlin, are actually permitted in any language that compiles to LLVM. It's true that we don't have any docs that call out the UB, but if the compiler de-facto makes it UB and that's a hard-to-change deep-rooted LLVM assumption, I'd rather have Miri flag such code than risk misbehavior. So I think we should do full provenance enforcement on the mmap APIs when the addr is not fixed by the caller, and treat them like regular (de)allocation. |
I agree, though I don't have time in the next 2 weeks or so to make this change. |
Make mmap not use expose semantics Fixes rust-lang/miri#3041 per rust-lang/miri#3041 (comment)
Make mmap not use expose semantics Fixes rust-lang/miri#3041 per rust-lang/miri#3041 (comment)
Make mmap not use expose semantics Fixes rust-lang/miri#3041 per rust-lang/miri#3041 (comment)
On both Linux and Mac, I get this warning for
munmap
:I think the miri munmap shim itself is triggering this warning. It looks like it turns the pointer into a usize on line 116 so it can check that it's aligned, and then turns it back into a pointer on 128 instead of using the original pointer.
For a quick reproduction, the code below passes the address directly returned from
mmap
back intomunmap
, without doing any integer-to-pointer casts:The text was updated successfully, but these errors were encountered: