Skip to content

ThreadSanitizer false positive due to missing interceptor for fcntl(fd, F_DUPFD_CLOEXEC, ..) #130037

@tmiasko

Description

@tmiasko

While ThreadSanitizer models synchronization implied by IO operations, it currently doesn't have interceptor for fcntl(fd, F_DUPFD_CLOEXEC, ..) and as a result operations on a duplicated file descriptor don't introduce synchronization. For example, the following generates a false positive report:

#![feature(sync_unsafe_cell)]
#![feature(anonymous_pipe)]
use std::cell::*;
use std::io::*;
use std::sync::*;

fn main() {
    let c = Arc::new(SyncUnsafeCell::new(0));
    let (mut a, mut b) = std::pipe::pipe().unwrap();
    // Duplicate file descriptor. Implemented in terms of fcntl(fd, F_DUPFD_CLOEXEC, ...).
    // Comment out the following line to hide the false positive.
    let mut b = b.try_clone().unwrap();
    let t = std::thread::spawn({
        let c = c.clone();
        move || {
            unsafe { *c.get() = 1 };
            b.write_all(b".").unwrap();
        }
    });
    let mut buf = [0];
    a.read_exact(&mut buf).unwrap();
    println!("{}", unsafe { *c.get() });
    t.join().unwrap();
}

This shortcoming makes ThreadSanitizer incompatible with Tokio.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-sanitizersArea: Sanitizers for correctness and code qualityC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions