Technical Cause of the Bug
The reported KCSAN bug is a data race on struct task_struct::flags (4-byte unsigned int field located at byte offset 0x2c / bit offset 352, matching reported address 0xffff888101d322ac).
1. Conflicting Accesses and Call Chains
-
Writer (Read-Modify-Write in Process Context):
When a user process performs a privileged operation such as sys_umount(), capability checking in ns_capable() / ns_capable_common() (kernel/capability.c:343) executes:
capable = security_capable(current_cred(), ns, cap, opts);
if (capable == 0) {
current->flags |= PF_SUPERPRIV;
return true;
}
This is a plain, unmarked read-modify-write on current->flags executed in task context with local hardware interrupts enabled.
-
Reader (Plain Read in Hardirq Context):
On the same CPU, a local APIC timer interrupt fires (sysvec_apic_timer_interrupt $\to$ hrtimer_interrupt $\to$ tick_nohz_handler $\to$ update_process_times $\to$ account_process_tick $\to$ account_system_index_time / account_user_time). This tick accounting path calls acct_account_cputime(p) (kernel/tsacct.c:170), which inlines __acct_update_integrals() (kernel/tsacct.c:130):
static void __acct_update_integrals(struct task_struct *tsk,
u64 utime, u64 stime)
{
u64 time, delta;
if (unlikely(!tsk->mm || (tsk->flags & PF_KTHREAD)))
return;
...
Here, tsk is current. __acct_update_integrals() performs a plain, unmarked read of tsk->flags to test PF_KTHREAD.
2. Root Cause Mechanism
- Commit
5e65b5ca7d4e ("tsacct: skip all kernel threads") introduced the check (tsk->flags & PF_KTHREAD) into __acct_update_integrals() to skip summing RSS for kernel threads temporarily borrowing an mm via use_mm().
- However,
task_struct::flags is modified concurrently by process-context code without disabling local hard interrupts (such as setting PF_SUPERPRIV in ns_capable_common(), or other flags across the kernel).
- Because neither access is marked using LKMM concurrency primitives (
READ_ONCE() or data_race()), when the timer interrupt interrupts the task during the KCSAN watchpoint delay window on current->flags, KCSAN detects concurrent unmarked memory accesses on the same CPU and flags a data race.
3. Invariants and Resolution
PF_KTHREAD is established during process creation (copy_process() in kernel/fork.c / init_idle() in kernel/sched/core.c) and remains strictly immutable for the lifetime of the task.
- Because the hardirq handler only reads
tsk->flags and never writes to it, it does not clobber the task's read-modify-write operation, and 32-bit aligned accesses do not tear.
- In accordance with similar lockless
PF_KTHREAD inspections in the kernel (e.g., to_kthread() annotated via commit fd00a46e36a12), the plain read in __acct_update_integrals() should be annotated with READ_ONCE() (i.e. READ_ONCE(tsk->flags) & PF_KTHREAD) or data_race().