syzbot
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: 1d14h
✨ 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
Technical Root Cause Analysis
1. Involved Subsystems, Functions, and Data Structures
- Source file:
arch/x86/kernel/fpu/core.c
- Functions involved:
- Data structures & fields:
struct task_struct::flags (unsigned int flags, defined at include/linux/sched.h:858)
- Per-task flags:
PF_KTHREAD (0x00200000), PF_USER_WORKER (0x00004000), PF_MEMALLOC_NOFS (0x00040000)
2. Detailed Mechanism and Trigger Sequence
-
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.
-
Preemption by Softirq / Interrupt on the Same CPU:
While CPU 1 is executing this code (or delayed inside KCSAN's watchpoint instrumentation on ¤t->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().
-
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.
-
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.
Sample crash report:
* Struck through repros no longer work on HEAD.