KCSAN: data-race in anon_pipe_write / pipe_poll

Status: moderation: reported on 2026/11/19 00:03
Subsystems: fs
Labels: race:benign prio:low
[Documentation on labels]
Reported-by: syzbot+3ead27672108095eb2a0@syzkaller.appspotmail.com
First crash: 1d13h, last: 17h38m
✨ AI cause bisection: candidate commits (most relevant first) (AI job):
commit 8cefc107ca54c8b06438b7dc9cc08bc0a11d5b98
Author: David Howells <dhowells@redhat.com>
Date: Fri Nov 15 13:30:32 2019 +0000

  pipe: Use head and tail pointers for the ring, not cursor and length

commit 3d252160b818045f3a152b13756f6f37ca34639d
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Tue Mar 4 13:51:38 2025 +0000

  fs/pipe: Read pipe->{head,tail} atomically outside pipe->mutex
  
✨ AI-generated root cause summary:

A data race exists between anon_pipe_write() updating pipe->head and pipe_poll() reading pipe->head_tail. In pipe_poll() (as well as pipe_readable() and pipe_writable()), pipe->head_tail is read locklessly using READ_ONCE(pipe->head_tail) to atomically evaluate both ring indices. However, writers such as anon_pipe_write() update pipe->head using a plain unmarked 4-byte assignment (pipe->head = head + 1) without WRITE_ONCE() or a __data_racy annotation, which KCSAN detects as an unmarked write racing with a marked read on overlapping bytes.

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

Technical Breakdown and Root Cause Analysis

1. Functions, Structs, and Fields Involved

  • struct pipe_inode_info / union pipe_index (include/linux/pipe_fs_i.h):
    union pipe_index {
        unsigned long head_tail;
        struct {
            pipe_index_t head;
            pipe_index_t tail;
        };
    };
    
    On 64-bit architectures, pipe_index_t is a 4-byte unsigned int, and unsigned long head_tail is 8 bytes. head overlaps with the lower 4 bytes of head_tail at offset 0.
  • pipe_poll() (fs/pipe.c:725): Reads the combined 8-byte pipe->head_tail member outside pipe->mutex via READ_ONCE(pipe->head_tail).
  • anon_pipe_write() (fs/pipe.c:563): Writes the 4-byte pipe->head member while holding pipe->mutex via a plain assignment pipe->head = head + 1;.

2. Triggering Mechanism and Root Cause

In commit 3d252160b818 ("fs/pipe: Read pipe->{head,tail} atomically outside pipe->mutex"), union pipe_index was introduced with the unsigned long head_tail field so that lockless callers (pipe_poll(), pipe_readable(), pipe_writable()) can inspect both head and tail in a single atomic 64-bit read without acquiring pipe->mutex.

In pipe_poll():

idx.head_tail = READ_ONCE(pipe->head_tail);

Task 3279 executes an intentional, marked 8-byte load of pipe->head_tail without holding pipe->mutex.

Concurrently, Task 3293 in anon_pipe_write():

pipe->head = head + 1;

executes a plain, unmarked 4-byte store to pipe->head (the lower 4 bytes of pipe->head_tail).

Under the Linux Kernel Memory Model (LKMM) and KCSAN rules, when an unmarked write access races with a marked read on overlapping memory bytes (0xffff8881003b1848), KCSAN flags it as a data race because the compiler is not strictly prevented from inventing stores or tearing plain writes. Neither pipe->head nor pipe->tail are updated with WRITE_ONCE() (or annotated as __data_racy in union pipe_index).


3. Invariant and Lifecycle Verification

  • Buffer Initialization Timing: In anon_pipe_write() (fs/pipe.c:563-575), pipe->head = head + 1 is updated prior to populating buf->page, buf->ops, and buf->len. However, anon_pipe_write() holds pipe->mutex throughout this entire block (and normal write disallows watch-queue pipes via pipe_has_watch_queue(pipe)). Any reader attempting to read or dereference pipe->bufs (such as anon_pipe_read()) must acquire pipe->mutex first, serializing strictly after the writer finishes initializing the buffer. Lockless callers (pipe_poll(), pipe_readable(), pipe_writable()) only check pipe_empty() / pipe_full() against indices and do not inspect or dereference pipe->bufs.
  • Resolution: Marking the write using WRITE_ONCE(pipe->head, head + 1) (along with other index updates like pipe_update_tail()), or qualifying the union pipe_index members with __data_racy, eliminates the data race.
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
15d97319 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in anon_pipe_write / pipe_poll 2026/11/18 09:47 2026/11/18 09:47 2026/11/18 10:32 eb4895d7
3cf206f7 bisect-cause ❓ KCSAN: data-race in anon_pipe_write / pipe_poll 2026/11/18 09:31 2026/11/18 09:31 2026/11/18 10:28 eb4895d7
e4f53ae6 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in anon_pipe_write / pipe_poll 2026/11/18 09:31 2026/11/18 09:31 2026/11/18 10:13 eb4895d7

Sample crash report:
==================================================================
BUG: KCSAN: data-race in anon_pipe_write / pipe_poll

read (marked) to 0xffff8881003b1848 of 8 bytes by task 3279 on cpu 1:
 pipe_poll+0x1a9/0x320 fs/pipe.c:725
 vfs_poll include/linux/poll.h:82 [inline]
 select_poll_one fs/select.c:480 [inline]
 do_select+0x93a/0xf50 fs/select.c:536
 core_sys_select+0x44d/0x700 fs/select.c:677
 do_pselect fs/select.c:770 [inline]
 __do_sys_pselect6 fs/select.c:809 [inline]
 __se_sys_pselect6+0x23f/0x2a0 fs/select.c:800
 __x64_sys_pselect6+0x78/0x90 fs/select.c:800
 x64_sys_call+0x1dfc/0x2550 arch/x86/include/generated/asm/syscalls_64.h:271
 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 0xffff8881003b1848 of 4 bytes by task 3293 on cpu 0:
 anon_pipe_write+0x968/0x10b0 fs/pipe.c:563
 new_sync_write fs/read_write.c:575 [inline]
 vfs_write+0x57a/0x9b0 fs/read_write.c:667
 ksys_write+0xdc/0x1a0 fs/read_write.c:719
 __do_sys_write fs/read_write.c:730 [inline]
 __se_sys_write fs/read_write.c:727 [inline]
 __x64_sys_write+0x40/0x50 fs/read_write.c:727
 x64_sys_call+0x154e/0x2550 arch/x86/include/generated/asm/syscalls_64.h:2
 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: 3293 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/18 07:09 upstream 20eef29b7c84 eb4895d7 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in anon_pipe_write / pipe_poll
2026/11/17 21:37 upstream 63fdb511c27a 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in anon_pipe_write / pipe_poll
2026/11/17 20:33 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in anon_pipe_write / pipe_poll
2026/11/17 11:17 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in anon_pipe_write / pipe_poll
* Struck through repros no longer work on HEAD.