Skip to content
Race condition Disclosed report Advanced

A race condition in crossbeam leads to a security vulnerability

A race condition in the crossbeam crate's deque module allows tasks to be stolen twice, leading to double-free and memory corruption in safe Rust programs. The bug affects Firefox through its use of the rayon crate, though no exploitable usage was found in Firefox.

kmaork Follow

Originally disclosed on Mozilla

  • Fixed in 54 days
  • Paid in 2 months
  • Disclosed after 54 days
Text
Created attachment 9226555
reproduce_crossbeam_deque_race.rs

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36

Steps to reproduce:

I have encountered a bug (a very slippery race condition) in the latest version of the crossbeam crate, and after some research I verified it exists in older versions too, specifically one that is used inside firefox as well. The bug involves the combined use of three functions from the deque.rs module - Worker::push, Worker::pop, Stealer::steal_batch. Later I discovered that similar race conditions exist with the other steal functions - Stealer::steal and Stealer::steal_batch_and_pop. I attached a script that reproduces the bug.


Actual results:

The bug had caused random memory corruption issues in my purely safe rust program. Specifically, it caused both a logical bug in my program, followed by a double-free.
I spent two weeks now researching and fixing this bug in my free time.
I intend to open a pull request with my fix, but wanted to let you guys know before I do that, so you'll have time to evaluate the security repercussions.
I looked into the usage of crossbeam inside firefox, and it seems to be used quite widely.
More specifically, I see it is used in Gecko. I dug into the usages a little bit, and it seems that at least one potential place for the bug to occur is in the rayon crate. The rayon crate is used widely throughout Gecko, specifically in gfx, servo and additional third-party libraries.
The good news is that the steal_batch and steal_batch_and_pop functions, when used on lifo worker queues, are much more susceptible to the race condition than the other scenarios, and I didn't find examples for such usage in firefox.
The result of the race condition is that one or more tasks in the worker queue can be stolen twice instead of other tasks that are forgotten and never stolen. If tasks are allocated on the heap, this can cause double free and a memory leak. If not, this still can cause a logical bug.


Expected results:

I have prepared a fix which I'm ready to open a pull-request for. Please let me know when I can progress with the PR without causing any harm. This is the diff if you're interested:
https://github.com/crossbeam-rs/crossbeam/compare/master...kmaork:deque_race_fix?expand=1

The original report as published on Mozilla's Bugzilla, by kmaork. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a lack of proper synchronisation in the deque's steal functions when combined with push and pop operations, allowing concurrent steals to interfere.

Impact

The race condition can cause double-free and memory leak if tasks are heap-allocated, or a logical bug otherwise; in Firefox, no exploitable usage was found.

What the attacker needed

Use of crossbeam deque with steal functions; concurrent access

The fix

The reporter has prepared a fix and intends to open a pull request.

How it was found

  1. Use the crossbeam crate's deque module with Worker::push, Worker::pop, and Stealer::steal_batch.
  2. Run the attached reproduction script that triggers the race condition.
  3. Observe memory corruption or logical errors.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A race condition is a bug where the timing of two actions causes unexpected results. Here, two threads trying to steal tasks from a queue at the same time can cause a task to be stolen twice, which can corrupt memory. This is dangerous because it can crash programs or potentially be exploited.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.