Root Cause Analysis
1. Confirmed Racing Object and Location
The racing 4-byte memory address 0xffff88810176d66c corresponds to current->flags (struct task_struct::flags, 32 bits, offset 0x2c / 352 bits) of the running task (PID 4922, base task_struct address 0xffff88810176d640).
The reported read-write access occurred at:
2. Mechanism and How the Race is Triggered
-
Unmarked Access in memalloc_flags_restore:
In include/linux/sched/mm.h, memory allocation scope helpers save and restore per-task allocation control flags (PF_MEMALLOC, PF_MEMALLOC_NOFS, PF_MEMALLOC_NOIO, etc.):
static inline unsigned memalloc_flags_save(unsigned flags)
{
unsigned oldflags = ~current->flags & flags;
current->flags |= flags;
return oldflags;
}
static inline void memalloc_flags_restore(unsigned flags)
{
current->flags &= ~flags;
}
Both operations perform plain, unmarked C read-modify-write accesses directly on current->flags without atomic bitops or READ_ONCE() / WRITE_ONCE().
-
KCSAN Watchpoint Handling with CONFIG_KCSAN_INTERRUPT_WATCHER:
When dquot_commit() executes memalloc_nofs_restore() and enters memalloc_flags_restore(), KCSAN sets up a watchpoint on current->flags.
Under CONFIG_KCSAN_INTERRUPT_WATCHER=y (kcsan_interrupt_watcher = true in kernel/kcsan/core.c), kcsan_setup_watchpoint() deliberately leaves local IRQs and preemption enabled on the CPU during delay_access().
-
Same-CPU Concurrent Read During Interrupt / Preemption:
While the watchpoint is active during the simulated delay on CPU 1, an interrupt fires or an IRQ return/preemption event occurs. In this context on CPU 1:
- Routine kernel code (such as scheduler accounting, preemption checks, tick processing, or task state inspection) performs an unmarked 4-byte read of
current->flags (e.g., checking PF_WQ_WORKER, PF_VCPU, or PF_EXITING).
in_task() remains true or prepare_access_info() attributes the access to task_pid_nr(current) on CPU 1, recording ai.task_pid = 4922 and ai.cpu_id = 1.
- The stack trace inside the interrupt/KCSAN framework is filtered out by
sanitize_stack_entries(), resulting in 0 remaining frames, which causes KCSAN to format the other access as 0x0 in the title and omit stack frames in the report output.
-
Resulting Violation:
According to the Linux Kernel Memory Model (LKMM), concurrent unmarked reads and writes to the same variable constitute a data race. task_struct::flags is accessed concurrently by asynchronous contexts (interrupt/tick/preemption handlers or cross-thread readers) while memalloc_flags_save() and memalloc_flags_restore() update it with plain bitwise operations.