Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upArc::drop has a (potentially) dangling shared ref #55005
Comments
RalfJung
added
P-medium
I-unsound 💥
labels
Oct 12, 2018
This comment has been minimized.
This comment has been minimized.
|
Potential fixes:
|
This comment has been minimized.
This comment has been minimized.
|
Turns out Clang has a similar issue, it uses |
This comment has been minimized.
This comment has been minimized.
jClaireCodesStuff
commented
Jan 6, 2019
|
It's a little spooky to see a situation where a region of code could do something undefined without an Anyway, in this twilight zone dangling pointers are not prohibited. Dereferencing dangling pointers is. Exposing somebody else's unsuspecting code to a dangling pointer is also very forbidden. But it's fine for dangling pointers to exist as long as they are dead. Remember: "dead" means "will not be accessed by anything below this point." Other languages don't even have a concept of reference lifetimes.
That can happen. But if it does, Thread A is guaranteed to fetch a reference count greater than 1, which then causes It would be undefined behavior for any method to be called after Honestly, I think you're a little too attached to the "Stacked Borrows" model - this is a situation where it doesn't work and rather than trying to understand why the model should be changed, you're arguing that the source code of stdlib should be declared unsound. If Rust continues in the tradition of LLVM, the uniqueness of |
This comment has been minimized.
This comment has been minimized.
|
The immediate problem is not about Rust, safe or unsafe, or any proposed formal semantics for it. rustc emits IR that has technically undefined behavior, because there is a pointer that is claimed to be Aside from that, there is the task of justifying the LLVM IR that rustc emits with Rust-level rules -- at minimum, in every case where emitted LLVM IR has UB, the input Rust code also needs to have UB to be able to claim rustc is correct. This issue points out a case where previous attempts at justifying the |
RalfJung
referenced this issue
Feb 7, 2019
Open
Stacked Borrows: barriers and the dereferencable attribute #88
vertexclique
referenced this issue
Feb 21, 2019
Closed
Explicitly pass strong ref as raw pointer to prevent UB in Arc::drop #58611
This comment has been minimized.
This comment has been minimized.
|
Option one:
for resolving this bug was tried in here: #58611 |
RalfJung commentedOct 12, 2018
Discovered by @Amanieu on IRLO. Quoting their report:
Arc::dropcontains this code:Once the current thread (Thread A) has decremented the reference count, Thread B could come in and free the
ArcInner.The problem becomes apparent when you look at the implementation of
fetch_sub:Note the point marked HERE: at this point we have released our claim to the
Arc(as in, decremented the count), which means that Thread B might have freed theArcInner. However the&selfstill points to the strong reference count in theArcInner-- so&selfdangles.