AFLplusplus / AFLplusplus/LibAFL

`ShMem` should probably require stored values to be `Sync`

未关闭
#2,809 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Rust
星标
2.6k
派生
481
平均合并
2 天 30 分钟
30 天内合并 PR
16

描述

`ShMem` can be used to create data-races if you use it to store non-`Sync` types such as `Cell`. For example, the assertion at the end of the following program fails:
```rust
use std::cell::Cell;

use libafl_bolts::os::{fork, ForkResult};
use libafl_bolts::shmem::{ShMem, ShMemProvider as _};

fn do_stuff(shmem: &impl ShMem) {
let p = shmem.as_ptr_of::>().unwrap();
for i in 0..128 {
let val = unsafe { (*p).get() };
println!("val = {val}");
unsafe { (*p).set(val + 1) };
}
}

fn main() {
let mut shmem_provider = libafl_bolts::shmem::MmapShMemProvider::default();
let shmem = shmem_provider.new_on_shmem(Cell::new(0usize)).unwrap();
shmem_provider.pre_fork().unwrap();
match unsafe { fork() }.unwrap() {
ForkResult::Parent(handle) => {
shmem_provider.post_fork(false).unwrap();
do_stuff(&shmem);
handle.status();
}
ForkResult::Child => {
shmem_provider.post_fork(true).unwrap();
do_stuff(&shmem);
std::process::abort();
}
}
let p = shmem.as_ptr_of::>().unwrap();
assert_eq!(256, unsafe { (*p).get() });
}
```
Of course, you can *also* create data-races just by using `as_mut_ptr`... But fixing that would require a whole different design, whereas it would be pretty easy to add a `Sync` bound to `ShMemProvider::new_on_shmem`, `ShMem::as_ptr_of`, etc..

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。