KCSAN: data-race in anon_pipe_read / pipe_release

Status: moderation: reported on 2026/11/20 00:08
Subsystems: fs
Labels: race:benign prio:low
[Documentation on labels]
Reported-by: syzbot+76819c64ceed92d01ea7@syzkaller.appspotmail.com
First crash: 2d21h, last: 1d10h
✨ AI-generated root cause summary:

A data race reported by KCSAN occurs on pipe->writers between anon_pipe_read() and pipe_release(). While waiting for data, anon_pipe_read() drops pipe->mutex and evaluates pipe_readable(), which executes a lockless marked read READ_ONCE(pipe->writers). Concurrently, a closing writer in pipe_release() decrements the counter under pipe->mutex using an unmarked plain write (pipe->writers--), violating the Linux Kernel Memory Model rule that concurrent plain writes to variables read locklessly without locks must be annotated with WRITE_ONCE().

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 20eef29b7c84:

Root Cause Analysis

Involved Functions, Structs, Fields, and Files


Technical Mechanism and Race Condition

In anon_pipe_read(), when a reader process finds the pipe empty and has not read any bytes yet, it drops pipe->mutex before sleeping on pipe->rd_wait:

// fs/pipe.c:411
mutex_unlock(&pipe->mutex);
if (wait_event_interruptible_exclusive(pipe->rd_wait, pipe_readable(pipe)) < 0)
    return -ERESTARTSYS;

Inside wait_event_interruptible_exclusive(), the wait condition pipe_readable(pipe) is checked while not holding pipe->mutex:

// fs/pipe.c:262
/* Done while waiting without holding the pipe lock - thus the READ_ONCE() */
static inline bool pipe_readable(const struct pipe_inode_info *pipe)
{
    union pipe_index idx = { .head_tail = READ_ONCE(pipe->head_tail) };
    unsigned int writers = READ_ONCE(pipe->writers);

    return !pipe_empty(idx.head, idx.tail) || !writers;
}

Because pipe->mutex is not held, pipe_readable() reads pipe->writers using READ_ONCE(pipe->writers) to avoid compiler re-reading and hoisting.

Concurrently, a writer process closes its file descriptor during group exit (do_group_exit() -> exit_files() -> ... -> fput() -> pipe_release()):

// fs/pipe.c:765
static int pipe_release(struct inode *inode, struct file *file)
{
    struct pipe_inode_info *pipe = file->private_data;

    mutex_lock(&pipe->mutex);
    if (file->f_mode & FMODE_READ)
        pipe->readers--;
    if (file->f_mode & FMODE_WRITE)
        pipe->writers--; // Line 773: plain, unmarked write
...

Although the write in pipe_release() is performed inside the pipe->mutex critical section, the reader in pipe_readable() accesses pipe->writers concurrently outside pipe->mutex.

Under the Linux Kernel Memory Model (LKMM), any memory location accessed concurrently where at least one thread writes must have all concurrent accesses annotated (e.g., using READ_ONCE() / WRITE_ONCE()) or synchronized by locks. Because pipe->writers-- is a plain, unmarked decrement operation rather than WRITE_ONCE(pipe->writers, pipe->writers - 1):

  1. Task 6895 executes a marked read (READ_ONCE(pipe->writers)) without holding pipe->mutex.
  2. Task 6924 executes a plain write (pipe->writers--) under pipe->mutex.
  3. KCSAN detects the concurrent unmarked write against the marked read and flags a data race.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
431e5961 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in anon_pipe_read / pipe_release 2026/11/19 08:20 2026/11/19 08:20 2026/11/19 08:39 2006bdcc
db5d956e assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in anon_pipe_read / pipe_release 2026/11/19 08:15 2026/11/19 08:15 2026/11/19 08:20 2006bdcc

Sample crash report:
==================================================================
BUG: KCSAN: data-race in anon_pipe_read / pipe_release

read (marked) to 0xffff88811c366060 of 4 bytes by task 6895 on cpu 1:
 pipe_readable fs/pipe.c:265 [inline]
 anon_pipe_read+0x54f/0x9b0 fs/pipe.c:420
 new_sync_read fs/read_write.c:473 [inline]
 vfs_read+0x6ac/0x7d0 fs/read_write.c:554
 ksys_read+0xdc/0x1a0 fs/read_write.c:696
 __do_sys_read fs/read_write.c:705 [inline]
 __se_sys_read fs/read_write.c:703 [inline]
 __x64_sys_read+0x40/0x50 fs/read_write.c:703
 x64_sys_call+0x2135/0x2550 arch/x86/include/generated/asm/syscalls_64.h:1
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

write to 0xffff88811c366060 of 4 bytes by task 6924 on cpu 0:
 pipe_release+0xb6/0x1d0 fs/pipe.c:773
 __fput+0x292/0x660 fs/file_table.c:512
 fput_close_sync+0xd5/0x1d0 fs/file_table.c:618
 filp_close_sync+0x27/0x40 fs/open.c:1574
 close_files fs/file.c:572 [inline]
 put_files_struct+0x11a/0x1e0 fs/file.c:584
 switch_files_struct fs/file.c:598 [inline]
 exit_files+0x6a/0x80 fs/file.c:604
 do_exit+0x492/0x1530 kernel/exit.c:977
 do_group_exit+0x138/0x140 kernel/exit.c:1123
 __do_sys_exit_group kernel/exit.c:1134 [inline]
 __se_sys_exit_group kernel/exit.c:1132 [inline]
 __x64_sys_exit_group+0x1f/0x20 kernel/exit.c:1132
 x64_sys_call+0x254f/0x2550 arch/x86/include/generated/asm/syscalls_64.h:232
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 6924 Comm: dhcpcd-run-hook Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/18 14:48 upstream 20eef29b7c84 eb4895d7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in anon_pipe_read / pipe_release
2026/11/17 19:37 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in anon_pipe_read / pipe_release
2026/11/17 03:04 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in anon_pipe_read / pipe_release
* Struck through repros no longer work on HEAD.