[BUG] tsacct: KCSAN data race on task flags between acct_account_cputime() and capable()
From: Puranam, Ananta Srikar
Date: Tue Nov 10 2026 - 23:53:51 EST
Hi,
I'm Ananta Srikar Puranam, a PhD student at Washington State University.
I'm reporting this bug on behalf of my team: Dr. Swarn Priya and
Dr. Basavesh Ammanaghatta Shivakumar (both Cc'd).
KCSAN reports a data race on task_struct::flags between the timer
interrupt's task accounting and capable(). acct_account_cputime()
reads tsk->flags to test PF_KTHREAD, while capable() sets PF_SUPERPRIV
in the same word with a plain read-modify-write. The read only tests
PF_KTHREAD, which is stable for a userspace task, so the accounting
decision is unaffected; the race is intentional but not annotated.
Trigger
=======
A minimal initramfs whose static init, running as root:
- mounts debugfs and limits KCSAN reports to acct_account_cputime and
capable (whitelist), then turns KCSAN on;
- calls finit_module(-1, "", 0) in a loop for three seconds.
Each call reaches capable(CAP_SYS_MODULE) through may_init_module(),
which sets PF_SUPERPRIV, before failing with EBADF. No module is
loaded. The timer interrupt on the same CPU then reads the same flags
word in acct_account_cputime().
Observed (current mainline, x86_64)
===================================
BUG: KCSAN: data-race in acct_account_cputime / capable
read to 0xffff8b0001e32f2c of 4 bytes by interrupt on cpu 0:
acct_account_cputime+0x42/0x1a0
update_process_times+0x30/0xe0
tick_nohz_handler+0x116/0x300
__hrtimer_run_queues+0x1ee/0x3d0
hrtimer_interrupt+0x1f1/0x3a0
__sysvec_apic_timer_interrupt+0x74/0x1a0
sysvec_apic_timer_interrupt+0x6b/0x80
asm_sysvec_apic_timer_interrupt+0x1a/0x20
delay_tsc+0x34/0xa0
kcsan_setup_watchpoint+0x1ff/0x580
capable+0x69/0x90
__x64_sys_finit_module+0x4a/0xd0
x64_sys_call+0x100d/0x2560
do_syscall_64+0xe0/0x3f0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
write to 0xffff8b0001e32f2c of 4 bytes by task 83 on cpu 0:
capable+0x69/0x90
__x64_sys_finit_module+0x4a/0xd0
x64_sys_call+0x100d/0x2560
do_syscall_64+0xe0/0x3f0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 83 Comm: init Not tainted 7.4.0-rc2-g067c5c24cef2 #1 PREEMPT(lazy)
The timer interrupt arrives while KCSAN is holding a watchpoint on the
write in capable(), so both accesses are on the same CPU. KCSAN was
limited to these two functions; there was no warning or oops.
Tested
======
- Mainline 067c5c24cef2 ("Merge tag 'page_alloc-for-7.4-rc2' ..."),
7.4.0-rc2-g067c5c24cef2, x86_64 under KVM:
reproduced in 3/3 boots: 116 reports in 5,614,538 capable()
calls (37, 35 and 44 per boot)
- The same tree with the proposed patch, same .config:
no KCSAN report in 3/3 boots, 5,764,984 capable() calls
Cause
=====
__acct_update_integrals(), inlined into acct_account_cputime(), does:
if (unlikely(!tsk->mm || (tsk->flags & PF_KTHREAD)))
return;
and capable() -> ns_capable() -> ns_capable_common() does:
capable = security_capable(current_cred(), ns, cap, opts);
if (capable == 0) {
current->flags |= PF_SUPERPRIV;
return true;
}
When the timer interrupt lands on current, both accesses touch the same
4-byte flags word with no marking. The PF_KTHREAD test was introduced
by:
5e65b5ca7d4e ("tsacct: skip all kernel threads")
which is in v7.0-rc1 and later.
Impact
======
The race is on unrelated bits: the concurrent write only sets
PF_SUPERPRIV, and the read only uses PF_KTHREAD, which does not change
for a userspace task. I observed a KCSAN report, not a wrong
accounting decision, crash, or memory corruption. Per
Documentation/process/threat-model.rst this is a regular bug, not a
vulnerability. I have only tested with CONFIG_KCSAN_STRICT=y and
CONFIG_KCSAN_INTERRUPT_WATCHER=y.
Setup
=====
Host: Ubuntu 26.04.1 LTS, x86_64
Toolchain: Ubuntu GCC 15.2.0 / GNU ld 2.46 (built with O=)
Config: x86_64_defconfig plus kernel/configs/kvm_guest.config
plus
CONFIG_DEBUG_FS=y
CONFIG_KCSAN=y
CONFIG_KCSAN_STRICT=y
CONFIG_KCSAN_INTERRUPT_WATCHER=y
CONFIG_KCSAN_REPORT_ONCE_IN_MS=0
CONFIG_KCSAN_SKIP_WATCH=4000
(resolved with olddefconfig; full .config available)
QEMU: qemu-system-x86_64 10.2.1 with KVM, -smp 2 -m 1024M,
no network
Guest: initramfs only, with the static init described above;
kernel log captured from the serial console on the host
The source reproducer (init program and QEMU wrapper) is available
privately on request. Per Documentation/process/security-bugs.rst I
have not posted it to the list.
Fix
===
A proposed patch marks the load with data_race(tsk->flags), as
task_css_set_check() already does for its task->flags test. On
067c5c24cef2 with the patch applied, the reproducer produced no KCSAN
report (see Tested).
Tool transparency
=================
The root-cause analysis, original reproducer and proposed fix were
prepared with the help of an AI coding assistant (OpenAI Codex). The
QEMU/KVM reproduction environment and the reproducer used for the
results above were set up with Anthropic's Claude Code. I re-ran the
reproduction myself and have checked the statements in this report.
Thanks,
Srikar