KCSAN: data-race in __put_cred / commit_creds

Status: moderation: reported on 2026/11/17 16:20
Subsystems: kasan
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+482e56035670f205b292@syzkaller.appspotmail.com
First crash: 13h05m, last: 13h05m
✨ AI cause bisection: introduced by (AI job) :
commit b030ffaedc1d638f232f6992406cdcdcc82d5602
Author: Jann Horn <jannh@google.com>
Date: Thu Aug 6 20:15:54 2026 +0000

  cred: clarify that task_struct::cred is only for the current task

  
✨ AI-generated root cause summary:

Commit b030ffaedc1d removed RCU protection from task_struct::cred under the invariant that it is only accessed synchronously by the current task. However, __put_cred() in kernel/cred.c unconditionally performs an unmarked read of current->cred in a BUG_ON() assertion. When __put_cred() is executed asynchronously from interrupt or softirq context (such as an RCU callback freeing an exited task's credentials), current refers to whichever task was interrupted on that CPU. If the interrupted task is executing commit_creds() with interrupts enabled, the plain write task->cred = new races with the softirq read of current->cred.

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

Root Cause Analysis

1. Functions, Structs, and Fields Involved


2. Background and Invariant Violation

Historically, task_struct::cred was annotated with __rcu and updated using rcu_assign_pointer(). In commit b030ffaedc1d ("cred: clarify that task_struct::cred is only for the current task"), __rcu annotations and RCU barrier helpers were removed from task_struct::cred based on the design rule that subjective credentials are only accessed synchronously by current (and during initial child setup in fork or final process teardown). Consequently, commit_creds() was changed to perform a plain, unmarked C store:

/* kernel/cred.c:416-417 */
rcu_assign_pointer(task->real_cred, new);
task->cred = new;

However, kernel/cred.c retained the following assertion inside __put_cred():

/* kernel/cred.c:76-78 */
BUG_ON(atomic_long_read(&cred->usage) != 0);
BUG_ON(cred == current->cred);
BUG_ON(cred == current->real_cred);

While task_struct::cred is private to current, __put_cred() is not strictly executed by current for its own credentials. Credential structures are reference-counted and can reach a refcount of zero asynchronously in any context, including interrupt handlers, workqueues, and RCU callbacks.


3. How the Data Race is Triggered

  1. Task Context (CPU 0): Task 7254 (dhcpcd) executes the setgroups system call and enters commit_creds() to install newly prepared credentials. It executes task->cred = new; (kernel/cred.c:417). Because interrupts are enabled during this system call, this store can be preempted by an interrupt.
  2. Interrupt / Softirq Context (CPU 0): An APIC timer interrupt occurs on CPU 0. During interrupt exit processing (__irq_exit_rcu()), pending softirqs are processed (RCU_SOFTIRQ via rcu_core()).
  3. RCU Callback Execution: The RCU engine invokes __put_task_struct_rcu_cb() to reclaim the task_struct of a previously terminated, unrelated process (tsk). This path invokes:
    __put_task_struct(tsk) -> exit_creds(tsk) -> put_cred_many(cred, 2) -> __put_cred(cred)
    
  4. Preemption and Unsynchronized Read: In softirq context, current points to whatever task was preempted on that CPUβ€”in this case, task 7254. When __put_cred() executes line 77 (BUG_ON(cred == current->cred);), it evaluates current->cred via a plain, unsynchronized read of task 7254's task->cred.
  5. KCSAN Detection: KCSAN instrumented the store in commit_creds(), established a watchpoint, and delayed CPU 0 within udelay(). When the APIC timer interrupt arrived and executed softirq RCU callbacks on the same CPU, __put_cred() read current->cred within that watchpoint window, prompting KCSAN to report a data race between __put_cred and commit_creds.

4. Remediation

Because current->cred is only meaningful to check when releasing credentials from synchronous task context, the assertion in __put_cred() should be bypassed when running in interrupt or out-of-task contexts (e.g., guarded with if (in_task()) { BUG_ON(cred == current->cred); ... }), or reads/writes of task->cred should be appropriately annotated with READ_ONCE() / WRITE_ONCE() or data-race suppression primitives.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
f731a755 assessment-kcsan πŸƒ KCSAN: data-race in __put_cred / commit_creds 2026/11/17 16:20 2026/11/17 16:20 ca622473
02ac151e bisect-cause ❓ KCSAN: data-race in __put_cred / commit_creds 2026/11/17 16:13 2026/11/17 16:13 2026/11/17 16:47 ca622473
f56033d8 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: βœ… UserNamespace: βœ… VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __put_cred / commit_creds 2026/11/17 16:01 2026/11/17 16:01 2026/11/17 16:20 ca622473

Sample crash report:
==================================================================
BUG: KCSAN: data-race in __put_cred / commit_creds

read to 0xffff8881045e07c8 of 8 bytes by interrupt on cpu 0:
 __put_cred+0x55/0xf0 kernel/cred.c:77
 exit_creds+0x12e/0x160 kernel/cred.c:-1
 __put_task_struct+0xef/0x340 kernel/fork.c:793
 __put_task_struct_rcu_cb+0x1c/0x30 kernel/fork.c:805
 rcu_do_batch kernel/rcu/tree.c:2650 [inline]
 rcu_core+0x76e/0xcb0 kernel/rcu/tree.c:2919
 rcu_core_si+0xd/0x20 kernel/rcu/tree.c:2936
 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
 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
 sysvec_apic_timer_interrupt+0x74/0x80 arch/x86/kernel/apic/apic.c:1062
 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
 native_pause arch/x86/include/asm/vdso/processor.h:13 [inline]
 delay_tsc+0x43/0xa0 arch/x86/lib/delay.c:76
 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
 commit_creds+0x403/0x730 kernel/cred.c:417
 set_current_groups kernel/groups.c:152 [inline]
 __do_sys_setgroups kernel/groups.c:218 [inline]
 __se_sys_setgroups+0x2eb/0x3a0 kernel/groups.c:198
 __x64_sys_setgroups+0x31/0x40 kernel/groups.c:198
 x64_sys_call+0x1916/0x2550 arch/x86/include/generated/asm/syscalls_64.h:117
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

write to 0xffff8881045e07c8 of 8 bytes by task 7254 on cpu 0:
 commit_creds+0x403/0x730 kernel/cred.c:417
 set_current_groups kernel/groups.c:152 [inline]
 __do_sys_setgroups kernel/groups.c:218 [inline]
 __se_sys_setgroups+0x2eb/0x3a0 kernel/groups.c:198
 __x64_sys_setgroups+0x31/0x40 kernel/groups.c:198
 x64_sys_call+0x1916/0x2550 arch/x86/include/generated/asm/syscalls_64.h:117
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 7254 Comm: dhcpcd Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

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