KCSAN: data-race in complete_signal / stop_this_handle

Status: moderation: reported on 2026/11/17 19:36
Subsystems: ext4
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+2184c4ccdca879b45fd2@syzkaller.appspotmail.com
First crash: 4h48m, last: 4h48m
✨ AI cause bisection: candidate commits (most relevant first) (AI job):
  1da177e4c3f4 Linux-2.6.12-rc2
  7dea19f9ee63 mm: introduce memalloc_nofs_{save,restore} API
  81378da64de6 jbd2: mark the transaction context with the scope GFP_NOFS context
  
✨ AI-generated root cause summary:

A KCSAN data race occurs on the 4-byte task_struct::flags field between stop_this_handle() clearing PF_MEMALLOC_NOFS via memalloc_flags_restore() and an APIC timer interrupt in posixtimer_send_sigqueue() calling complete_signal() -> wants_signal() to test PF_EXITING. task_struct::flags packs both lockless task-local allocation flags and signal-related flags into a single unsigned int. While complete_signal() executes under p->sighand->siglock, memalloc_flags_restore() modifies current->flags without holding that lock, resulting in an unsynchronized read-write access.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 666539eecdf4:

Technical Analysis of the KCSAN Data Race

1. Functions, Structs, and Fields Involved

  • Field: struct task_struct::flags (unsigned int, 4 bytes located at byte offset 0x2c on x86_64).
  • Writer Path:
    • Task 3550 running on CPU 1 handling a page fault (ext4_page_mkwrite()) invokes jbd2_journal_stop() $\to$ stop_this_handle() (fs/jbd2/transaction.c:740).
    • stop_this_handle() restores the allocation context by calling memalloc_nofs_restore(handle->saved_alloc_context) $\to$ memalloc_flags_restore() (include/linux/sched/mm.h:341).
    • memalloc_flags_restore() executes current->flags &= ~flags;, clearing the PF_MEMALLOC_NOFS flag (bit 18, 0x00040000).
  • Reader Path:
    • APIC timer interrupt fires on CPU 0 and invokes posixtimer_send_sigqueue() (kernel/signal.c:2153).
    • CPU 0 acquires task_3550->sighand->siglock and queues the signal via posixtimer_queue_sigqueue() $\to$ complete_signal() (kernel/signal.c:980).
    • complete_signal() calls wants_signal(sig, p) (kernel/signal.c:958), which executes:
      if (p->flags & PF_EXITING)
          return false;
      
      This reads p->flags (bit 2, PF_EXITING, 0x00000004) to determine whether the target task can receive signals.

2. Root Cause & Concurrency Mechanism

  1. Unsynchronized Field Sharing:

    • struct task_struct::flags is a composite bitmask packing various per-task flags into a single 32-bit unsigned int.
    • Some flags (such as PF_EXITING) are synchronized against signal delivery by holding tsk->sighand->siglock when set in exit_signals() (kernel/signal.c:3211).
    • However, other flagsβ€”such as PF_MEMALLOC_NOFS, PF_MEMALLOC_NOIO, and PF_MEMALLOCβ€”represent local memory allocation scopes that are modified frequently by current without holding sighand->siglock or taking any lock.
    • memalloc_flags_restore() performs a plain read-modify-write (current->flags &= ~flags), and wants_signal() performs a plain read (p->flags & PF_EXITING) without using LKMM access annotations such as READ_ONCE() or WRITE_ONCE().
  2. Triggering the Race:

    • Task 3550 on CPU 1 is clearing PF_MEMALLOC_NOFS from current->flags without holding siglock.
    • Simultaneously, an interrupt on CPU 0 sends a POSIX timer signal to the thread group or process, targeting task 3550. While CPU 0 holds p->sighand->siglock, this does not synchronize with task 3550's memalloc_flags_restore().
    • KCSAN detects the concurrent read-modify-write on CPU 1 and plain read on CPU 0 at offset 0x2c.

3. Nature and Safety of the Race

  • No Lost Updates: Only the task itself (current) modifies its own current->flags at runtime; external threads only read p->flags. As there are no concurrent writers to task_struct::flags, no flag updates are lost or overwritten.
  • Independent Bit Positions: The writer operates on bit 18 (PF_MEMALLOC_NOFS), whereas the reader inspects bit 2 (PF_EXITING). On modern architectures with naturally aligned 32-bit accesses, there is no word tearing. Modifying bit 18 cannot alter the value of bit 2.
  • Invariant Stability: PF_EXITING is only set once during task termination in exit_signals() under sighand->siglock. Because CPU 0 holds p->sighand->siglock during wants_signal(), PF_EXITING cannot transition while CPU 0 is evaluating it.
  • Resolution: Marking the access with READ_ONCE(p->flags) in wants_signal() (or using atomic bitops / READ_ONCE()/WRITE_ONCE() on shared task_struct::flags accesses) informs the compiler and sanitizers that concurrent modification of unrelated bits is expected.
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
fa25b1a6 assessment-kcsan Benign: βœ… ❓ KCSAN: data-race in complete_signal / stop_this_handle 2026/11/17 19:29 2026/11/17 19:29 2026/11/17 20:18 ca622473
eb950c54 bisect-cause ❓ KCSAN: data-race in complete_signal / stop_this_handle 2026/11/17 19:28 2026/11/17 19:28 2026/11/17 20:13 ca622473
d60d4cad assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: βœ… UserNamespace: βœ… VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in complete_signal / stop_this_handle 2026/11/17 19:16 2026/11/17 19:16 2026/11/17 19:35 ca622473

Sample crash report:
==================================================================
BUG: KCSAN: data-race in complete_signal / stop_this_handle

read-write to 0xffff888101d8002c of 4 bytes by task 3550 on cpu 1:
 memalloc_flags_restore include/linux/sched/mm.h:341 [inline]
 memalloc_nofs_restore include/linux/sched/mm.h:401 [inline]
 stop_this_handle+0x252/0x290 fs/jbd2/transaction.c:740
 jbd2_journal_stop+0x51b/0x6a0 fs/jbd2/transaction.c:2014
 __ext4_journal_stop+0x8f/0x1d0 fs/ext4/ext4_jbd2.c:148
 ext4_dirty_inode+0xa6/0xc0 fs/ext4/inode.c:7654
 __mark_inode_dirty+0x164/0x770 fs/fs-writeback.c:2751
 generic_update_time fs/inode.c:2274 [inline]
 file_update_time_flags+0x2ae/0x2e0 fs/inode.c:2504
 file_update_time+0x17/0x20 fs/inode.c:2525
 ext4_page_mkwrite+0x16b/0xd30 fs/ext4/inode.c:7838
 do_page_mkwrite mm/memory.c:3889 [inline]
 do_shared_fault mm/memory.c:6188 [inline]
 do_fault mm/memory.c:6250 [inline]
 do_pte_missing mm/memory.c:4778 [inline]
 handle_pte_fault mm/memory.c:6665 [inline]
 __handle_mm_fault mm/memory.c:6817 [inline]
 handle_mm_fault+0x269c/0x3880 mm/memory.c:6984
 do_user_addr_fault+0x3ce/0xde0 arch/x86/mm/fault.c:1343
 handle_page_fault arch/x86/mm/fault.c:1483 [inline]
 exc_page_fault+0x62/0xa0 arch/x86/mm/fault.c:1536
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:595

read to 0xffff888101d8002c of 4 bytes by interrupt on cpu 0:
 wants_signal kernel/signal.c:958 [inline]
 complete_signal+0x8c/0x7b0 kernel/signal.c:980
 posixtimer_queue_sigqueue kernel/signal.c:2008 [inline]
 posixtimer_send_sigqueue+0x423/0x8d0 kernel/signal.c:2153
 posix_timer_queue_signal kernel/time/posix-timers.c:365 [inline]
 posix_timer_fn+0x93/0xc0 kernel/time/posix-timers.c:380
 __run_hrtimer kernel/time/hrtimer.c:2079 [inline]
 __hrtimer_run_queues+0x1f8/0x540 kernel/time/hrtimer.c:2136
 hrtimer_interrupt+0x27b/0x870 kernel/time/hrtimer.c:2255
 local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1051 [inline]
 __sysvec_apic_timer_interrupt+0x5f/0x1f0 arch/x86/kernel/apic/apic.c:1068
 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
 sysvec_apic_timer_interrupt+0x6f/0x80 arch/x86/kernel/apic/apic.c:1062
 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
 native_safe_halt arch/x86/include/asm/irqflags.h:48 [inline]
 pv_native_safe_halt+0xf/0x20 arch/x86/kernel/paravirt.c:63
 arch_safe_halt arch/x86/kernel/process.c:767 [inline]
 default_idle+0x9/0x20 arch/x86/kernel/process.c:768
 default_idle_call+0x3b/0x60 kernel/sched/idle.c:122
 cpuidle_idle_call kernel/sched/idle.c:199 [inline]
 do_idle+0x183/0x2d0 kernel/sched/idle.c:355
 cpu_startup_entry+0x24/0x30 kernel/sched/idle.c:458
 rest_init+0x101/0x110 init/main.c:789
 start_kernel+0x49f/0x4d0 init/main.c:1247
 x86_64_start_reservations+0x24/0x30 arch/x86/kernel/head64.c:310
 x86_64_start_kernel+0xfc/0x100 arch/x86/kernel/head64.c:291
 common_startup_64+0x13e/0x157

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

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 19:02 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in complete_signal / stop_this_handle
* Struck through repros no longer work on HEAD.