rust-lang / rust-lang/rust

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

Open
#130,037 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-LLVM A-sanitizers C-bug T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating ThreadSanitizer's handling of fcntl and the missing F_DUPFD_CLOEXEC interceptor. Use the Rust pipe and try_clone reproduction in the issue to observe the false positive under ThreadSanitizer, then verify that the duplicated file descriptor establishes the expected synchronization and the reproduction no longer reports a race.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, operating-systems, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.