-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path0051-syncpool.rs
60 lines (52 loc) · 1.42 KB
/
0051-syncpool.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*!
```rudra-poc
[target]
crate = "syncpool"
version = "0.1.5"
[report]
issue_url = "https://github.com/Chopinsky/byte_buffer/issues/2"
issue_date = 2020-11-29
rustsec_url = "https://github.com/RustSec/advisory-db/pull/654"
rustsec_id = "RUSTSEC-2020-0142"
[[bugs]]
analyzer = "SendSyncVariance"
bug_class = "SendSyncVariance"
rudra_report_locations = ["src/bucket.rs:334:1: 334:38"]
```
!*/
#![forbid(unsafe_code)]
use syncpool::prelude::*;
use std::boxed::Box;
use std::rc::Rc;
const N_ITER: usize = 900_000;
const N_THREADS: usize = 6;
fn main() {
// Non-Send object (to be sent to other threads).
let rc = Rc::new(0_i32);
let mut pools = vec![];
for _ in 0..N_THREADS {
let mut pool = SyncPool::new();
let _dummy = pool.get();
let malicious = Box::new(Rc::clone(&rc));
pool.put(malicious);
pools.push(pool);
}
let mut children = vec![];
while let Some(pool) = pools.pop() {
let c = std::thread::spawn(move || {
// Moved `pool` to child thread.
let mut pool = pool;
let boxed_rc = pool.get();
for _ in 0..N_ITER {
// Data race on the internal ref count of `Rc`.
Rc::clone(boxed_rc.as_ref());
}
});
children.push(c);
}
// Join child threads.
for child in children {
child.join().unwrap();
}
assert_eq!(Rc::strong_count(&rc), 1);
}