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

fix use-after-free in crossbeam-epoch/sync/queue #466

Merged
merged 1 commit into from
Feb 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crossbeam-epoch/src/sync/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//!
//! Michael and Scott. Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue
//! Algorithms. PODC 1996. http://dl.acm.org/citation.cfm?id=248106
//!
//! Simon Doherty, Lindsay Groves, Victor Luchangco, and Mark Moir. 2004b. Formal Verification of a
//! Practical Lock-Free Queue Algorithm. https://doi.org/10.1007/978-3-540-30232-2_7

use core::mem::{self, ManuallyDrop};
use core::ptr;
Expand Down Expand Up @@ -117,6 +120,11 @@ impl<T> Queue<T> {
self.head
.compare_and_set(head, next, Release, guard)
.map(|_| {
let tail = self.tail.load(Relaxed, guard);
// Advance the tail so that we don't retire a pointer to a reachable node.
if head == tail {
let _ = self.tail.compare_and_set(tail, next, Release, guard);
}
guard.defer_destroy(head);
Some(ManuallyDrop::into_inner(ptr::read(&n.data)))
})
Expand All @@ -142,6 +150,11 @@ impl<T> Queue<T> {
self.head
.compare_and_set(head, next, Release, guard)
.map(|_| {
let tail = self.tail.load(Relaxed, guard);
// Advance the tail so that we don't retire a pointer to a reachable node.
if head == tail {
let _ = self.tail.compare_and_set(tail, next, Release, guard);
}
guard.defer_destroy(head);
Some(ManuallyDrop::into_inner(ptr::read(&n.data)))
})
Expand Down