Skip to content

LockBud False Negative for AtomicityViolation Vulnerability #126

@RJerrica

Description

@RJerrica

I encountered a ​​false negative​​ in ​​AtomicityViolation​​ detection when using ​​LockBud​​. The minimized code example is provided below. Lockbud should report an AtomicityViolation warning because atomic::store in line 15 is dependent on atomic::load in line 8. BTW, I used the cargo lockbud -k all command to run LockBud.

Minimized Code Example

use std::sync::atomic::Ordering;
use std::sync::atomic::{AtomicBool, AtomicI32};
fn gen_rand_val_i32() -> i32 {
    rand::random::<i32>()
}
fn func() {
    let a = AtomicI32::new(gen_rand_val_i32());
    let v = a.load(Ordering::Relaxed);  //atomic_reader
    let v3 = v.wrapping_add(1);
    let v4 = match v3 > 10 {
        true => v3.wrapping_add(2),
        false => v3.wrapping_sub(1),
    };
    if v4 > 11 && gen_rand_val_i32() < 12 {
        a.store(10, Ordering::Relaxed);  //atomic_writer
    }
    println!("{:?}", a);
}
fn main() {
    func();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions