-
Notifications
You must be signed in to change notification settings - Fork 488
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
Deallocating the storage of a value without running its destructor is UB #693
Conversation
Nope, this is not UB. With this clause, It is also not correct that this is required for |
Makes sense. So to check that IIUC, deallocating a stack frame containing a |
@RalfJung one way in which |
OTOH a |
Yes.
There is potential UB here from use-after-free if e.g. another thread had pointers to this stack frame. I don't think we need a new error condition in the Abstract Machine for this. |
No, I don't think so either. Do you know if miri has a model for unwinding? My mental model is that the Rust stack is a What a There are some abstractions, like Since Does something like this sounds about right? |
It doesn't. There are some PRs though that are waiting to be reviewed by me. It's just, some people keep bringing up so much stuff in the UCG, I just don't have time for code review any more.^^
Doesn't
Mostly. One detail is that really every local variable is its own "allocated object" (we don't allow ptr arithmetic between them). You can incorporate that into your model by saying that |
In most platforms, yes. In some, it is implemented with unwinding (catch_unwind + panic). |
I am talking about the abstract spec, not the implementation. Why the duplication of the entire frame? That's observably different if there are pointers to other parts of this frame that get mutated between setjmp and longjmp. (Also I feel a closed incorrect issue is the wrong place to discuss this. Could you find a better place?) |
I think it might be better to discuss this in the
I was only talking here about the case where, if such pointers exist, they are still safe to use afterwards - only the allocations in the stack for which such pointers do not exist and for which safety invariants are not violated would be "ok" to deallocate. |
That is, there are certain parts of those frames that's ok to just leak, and parts that aren't, so maybe the realization is that it does not make sense to consider |
I don't see how your model is related to that. Unwinding is being implemented at rust-lang/rust#60026 and rust-lang/miri#693. But the details are far removed from what we discussed here -- there's no question here about what happens when you unwind, right? The operational behavior implemented by Rust is clear. You were just describing a more abstract mental model.
Sure. I don't see any fundamental difference between the two. A stack frame in Miri has a list of Notice that while unwinding is in the process of being implemented, that's just the normal panic-induced unwinding (that's what I assumed you referred to). This just means running cleanup blocks. There's nothing like SJLJ in Miri. I now feel like you might have said "unwind" to refer to SJLJ, which is confusing me a lot. |
Yes, I was saying "unwind" in the context of SJLJ.
What I was discussing is a more general framework for talking about unwinding, where the only difference between "panic" unwinding and SJLJ unwinding is that when "panic" unwinding calls |
In Miri terms, that's just popping a stack frame without running any of the cleanup or unwind code. |
Notice that, opposed to |
This is required for
Pin
to be sound, but I couldn't find it documented anywhere.cc @RalfJung @Centril