Closed
Description
Discovered by @Amanieu on IRLO. Quoting their report:
Arc::drop
contains this code:
if self.inner().strong.fetch_sub(1, Release) != 1 {
return;
}
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
:
pub fn fetch_sub(&self, val: $int_type, order: Ordering) -> $int_type {
unsafe { atomic_sub(self.v.get(), val, order) }
// HERE
}
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 the ArcInner
. However the &self
still points to the strong reference count in the ArcInner
-- so &self
dangles.
Other instances of this:
Metadata
Metadata
Assignees
Labels
Category: This is a bug.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessMedium priorityRelevant to the language team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.Working group: Embedded systems