KCSAN: data-race in kernel_fpu_begin_mask / stop_this_handle

Status: moderation: reported on 2026/11/19 00:06
Subsystems: kernel
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+a45a48553afaf64a37e8@syzkaller.appspotmail.com
First crash: 1d20h, last: 1d13h
✨ AI-generated root cause summary:

In arch/x86/kernel/fpu/core.c:kernel_fpu_begin_mask(), current->flags is accessed via an unmarked plain read to check for (PF_KTHREAD | PF_USER_WORKER). When kernel-mode FPU is used in softirq context (such as blake2s hashing in entropy mixing), the interrupt preempts task context on the same CPU while the task is executing a non-atomic read-modify-write on current->flags (such as memalloc_flags_restore() clearing PF_MEMALLOC_NOFS in JBD2 transaction handling without disabling interrupts). Because current->flags is updated without atomics or interrupt suppression, the concurrent plain read in the softirq constitutes a C/LKMM data race detected by KCSAN.

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

Technical Root Cause Analysis

1. Involved Subsystems, Functions, and Data Structures


2. Detailed Mechanism and Trigger Sequence

  1. Task-Context Non-Atomic Update to current->flags: A kernel thread (here, worker thread kworker/u8:8 PID 635 on CPU 1 executing ext4_end_io_rsv_work) enters JBD2 transaction completion in stop_this_handle() (fs/jbd2/transaction.c:740). It calls memalloc_nofs_restore() to restore the memory allocation context, which invokes memalloc_flags_restore() (include/linux/sched/mm.h:341):

    static inline void memalloc_flags_restore(unsigned flags)
    {
        current->flags &= ~flags;
    }
    

    This operation performs an unmarked plain C read-modify-write (&= ~PF_MEMALLOC_NOFS) on current->flags with local interrupts enabled.

  2. Preemption by Softirq / Interrupt on the Same CPU: While CPU 1 is executing this code (or delayed inside KCSAN's watchpoint instrumentation on &current->flags), an interrupt arrives on CPU 1. Upon interrupt exit (__irq_exit_rcu -> handle_softirqs), softirq handling executes blk_done_softirq(), completing SCSI request I/O.

    The completion routine feeds entropy into the random pool via add_disk_randomness() -> add_timer_randomness() -> _mix_pool_bytes() -> blake2s_update() -> blake2s_compress().

    Because irq_fpu_usable() / may_use_simd() permits kernel-mode FPU usage within softirq context, blake2s_compress() calls kernel_fpu_begin() -> kernel_fpu_begin_mask().

  3. Unsynchronized Read in kernel_fpu_begin_mask(): Inside kernel_fpu_begin_mask() (arch/x86/kernel/fpu/core.c:506):

    if (!(current->flags & (PF_KTHREAD | PF_USER_WORKER)) &&
        !test_thread_flag(TIF_NEED_FPU_LOAD))
            update_fpu_state_and_flag(x86_task_fpu(current), current);
    

    In interrupt and softirq context, current points to the task that was interrupted on that CPU (here, task 635). kernel_fpu_begin_mask() reads current->flags via a plain, unmarked C load to determine whether the interrupted task is a user task whose live FPU hardware state needs to be saved to memory before the kernel clobbers the FPU/SIMD registers.

  4. The Concurrency Invariant Violation: task_struct::flags is designed to be updated in task context without atomics or interrupt disabling, under the assumption that current->flags is strictly local to the running task. However, kernel-mode FPU allows entry from asynchronous interrupt/softirq handlers where current is the interrupted task. Reading current->flags in softirq context concurrently with task-context plain read-modify-write operations on other bits of the same 32-bit field without READ_ONCE() or data_race() creates a data race under the C and Linux Kernel Memory Models (LKMM), triggering the KCSAN report.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
1ad6a573 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in kernel_fpu_begin_mask / stop_this_handle 2026/11/18 11:05 2026/11/18 11:05 2026/11/18 11:15 eb4895d7
bf10edb5 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in kernel_fpu_begin_mask / stop_this_handle 2026/11/18 10:46 2026/11/18 10:46 2026/11/18 11:23 eb4895d7

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

read to 0xffff88810245c52c of 4 bytes by interrupt on cpu 1:
 kernel_fpu_begin_mask+0x116/0x2a0 arch/x86/kernel/fpu/core.c:506
 kernel_fpu_begin arch/x86/include/asm/fpu/api.h:41 [inline]
 blake2s_compress+0x49/0x16d0 lib/crypto/x86/blake2s.h:37
 blake2s_update+0x9a/0x150 lib/crypto/blake2s.c:119
 _mix_pool_bytes drivers/char/random.c:639 [inline]
 add_timer_randomness+0x1f6/0x390 drivers/char/random.c:1153
 add_disk_randomness+0x5b/0x80 drivers/char/random.c:1225
 scsi_end_request+0xac/0x3a0 drivers/scsi/scsi_lib.c:675
 scsi_io_completion+0x7f/0x1d0 drivers/scsi/scsi_lib.c:1125
 scsi_finish_command+0x233/0x250 drivers/scsi/scsi.c:198
 scsi_complete+0x165/0x660 drivers/scsi/scsi_lib.c:1604
 blk_complete_reqs block/blk-mq.c:1242 [inline]
 blk_done_softirq+0x8d/0xc0 block/blk-mq.c:1247
 handle_softirqs+0x109/0x310 kernel/softirq.c:669
 __do_softirq kernel/softirq.c:703 [inline]
 invoke_softirq kernel/softirq.c:542 [inline]
 __irq_exit_rcu+0x40/0xf0 kernel/softirq.c:786
 common_interrupt+0x83/0x90 arch/x86/kernel/irq.c:273
 asm_common_interrupt+0x26/0x40 arch/x86/include/asm/idtentry.h:665
 rdtsc_ordered arch/x86/include/asm/tsc.h:57 [inline]
 delay_tsc+0x5b/0xa0 arch/x86/lib/delay.c:70
 udelay include/asm-generic/delay.h:64 [inline]
 delay_access kernel/kcsan/core.c:332 [inline]
 kcsan_setup_watchpoint+0x255/0x3f0 kernel/kcsan/core.c:622
 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_convert_unwritten_io_end_vec+0xd4/0x110 fs/ext4/extents.c:5257
 ext4_end_io_end+0x78/0x290 fs/ext4/page-io.c:194
 ext4_do_flush_completed_IO fs/ext4/page-io.c:285 [inline]
 ext4_end_io_rsv_work+0x15b/0x1f0 fs/ext4/page-io.c:300
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0x582/0xab0 kernel/workqueue.c:3578
 worker_thread+0x56c/0x770 kernel/workqueue.c:3659
 kthread+0x248/0x2a0 kernel/kthread.c:436
 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

read-write to 0xffff88810245c52c of 4 bytes by task 635 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_convert_unwritten_io_end_vec+0xd4/0x110 fs/ext4/extents.c:5257
 ext4_end_io_end+0x78/0x290 fs/ext4/page-io.c:194
 ext4_do_flush_completed_IO fs/ext4/page-io.c:285 [inline]
 ext4_end_io_rsv_work+0x15b/0x1f0 fs/ext4/page-io.c:300
 process_one_work kernel/workqueue.c:3495 [inline]
 process_scheduled_works+0x582/0xab0 kernel/workqueue.c:3578
 worker_thread+0x56c/0x770 kernel/workqueue.c:3659
 kthread+0x248/0x2a0 kernel/kthread.c:436
 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 635 Comm: kworker/u8:8 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
Workqueue: ext4-rsv-conversion ext4_end_io_rsv_work
==================================================================

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