KCSAN: data-race in release_task / taskstats_exit

Status: moderation: reported on 2026/11/18 03:50
Subsystems: kernel
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+f37b26d50f91f11a1cd0@syzkaller.appspotmail.com
First crash: 22h38m, last: 4h12m
✨ AI-generated root cause summary:

A data race occurs in taskstats_tgid_alloc() (kernel/taskstats.c) when an exiting thread group leader calls thread_group_empty() locklessly while a concurrent sub-thread in the same thread group is being auto-reaped in release_task(). In release_task(), __unhash_process() modifies the leader's tsk->thread_node.next pointer via list_del_rcu(&p->thread_node) with WRITE_ONCE under tasklist_lock and sighand->siglock. Concurrently, taskstats_tgid_alloc() performs an unmarked plain load of tsk->thread_node.next via list_is_last() without holding sighand->siglock or tasklist_lock, violating the kernel memory model and triggering a KCSAN data-race warning.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 63fdb511c27a:

Root Cause Analysis

1. Functions, Structs, and Fields Involved


2. Detailed Technical Mechanism and Invariant Violation

In the Linux kernel, a process's thread group list (signal->thread_head) is populated when new threads are spawned via copy_process() (kernel/fork.c:2575) using list_add_tail_rcu(&p->thread_node, &p->signal->thread_head) under tasklist_lock and sighand->siglock. When a sub-thread is unhashed during task release (__exit_signal() -> __unhash_process()), it is removed via list_del_rcu(&p->thread_node) while holding both write_lock_irq(&tasklist_lock) and spin_lock(&sighand->siglock).

list_del_rcu() invokes __list_del(entry->prev, entry->next), which writes to prev->next using WRITE_ONCE(prev->next, next).

Concurrently, during process exit:

  1. Reader Task (Group Leader, Task 9915 on CPU 0):

    • Task 9915 is the thread group leader executing do_exit() -> taskstats_exit().
    • taskstats_exit() calls taskstats_tgid_alloc(tsk):
      static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk)
      {
          struct signal_struct *sig = tsk->signal;
          struct taskstats *stats_new, *stats;
      
          stats = smp_load_acquire(&sig->stats);
          if (stats || thread_group_empty(tsk))
              return stats;
          ...
      
    • If sig->stats has not yet been allocated (e.g., if a previous exiting sub-thread's kmem_cache_zalloc() failed, as permitted by line 538, or if family_registered was not set when earlier threads exited), taskstats_tgid_alloc() executes thread_group_empty(tsk):
      static inline int thread_group_empty(struct task_struct *p)
      {
          return thread_group_leader(p) &&
                 list_is_last(&p->thread_node, &p->signal->thread_head);
      }
      
    • list_is_last(&p->thread_node, &p->signal->thread_head) tests:
      return list->next == head;
      
    • This performs a plain, unannotated load of tsk->thread_node.next. Crucially, this read occurs without holding sighand->siglock or tasklist_lock, and without using marked accessors (READ_ONCE() or RCU accessors).
  2. Writer Task (Untraced Sub-Thread, Task 9916 on CPU 1):

    • Task 9916 is an untraced sub-thread in the same thread group exiting concurrently via do_exit().
    • Because it is an untraced sub-thread, exit_notify() marks it for automatic reaping (autoreap = true) and immediately invokes release_task(p).
    • In release_task(), under tasklist_lock and sighand->siglock, __exit_signal() -> __unhash_process() calls list_del_rcu(&p->thread_node).
    • Because Task 9916 immediately followed leader Task 9915 in thread_head, p->thread_node.prev is &task_9915->thread_node.
    • __list_del() writes to prev->next (address 0xffff888101dfdce8) with WRITE_ONCE(), updating it from Task 9916's thread_node (0xffff888104633a68) to the next entry (0xffff8881025186a8).
  3. Data Race Trigger:

    • Task 9916 performs a concurrent marked 8-byte write (WRITE_ONCE) to tsk->thread_node.next.
    • Task 9915 performs a concurrent plain 8-byte read (list->next) from tsk->thread_node.next.
    • KCSAN flags this data race on 0xffff888101dfdce8.

3. Summary of Flaw

taskstats_tgid_alloc() attempts an optimistic lockless fast-path check via thread_group_empty(tsk) to avoid allocating memory if the process was single-threaded. However, thread_group_empty() relies on list_is_last(), which assumes serialized list access and performs an unannotated plain read of thread_node.next. Because concurrent sub-threads can be unhashed and deleted from thread_head concurrently, calling thread_group_empty(tsk) without holding siglock (or without atomic/RCU access annotations) violates the kernel concurrency model.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
826730b1 assessment-kcsan 🏃 KCSAN: data-race in release_task / taskstats_exit 2026/11/18 03:36 2026/11/18 03:36 ca622473
f6d538c9 bisect-cause 🏃 KCSAN: data-race in release_task / taskstats_exit 2026/11/18 03:35 2026/11/18 03:35 ca622473
d225c439 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in release_task / taskstats_exit 2026/11/18 03:32 2026/11/18 03:32 2026/11/18 03:41 ca622473

Sample crash report:
==================================================================
BUG: KCSAN: data-race in release_task / taskstats_exit

write (marked) to 0xffff888101dfdce8 of 8 bytes by task 9916 on cpu 1:
 __list_del include/linux/list.h:242 [inline]
 __list_del_entry include/linux/list.h:264 [inline]
 list_del_rcu include/linux/rculist.h:178 [inline]
 __unhash_process kernel/exit.c:153 [inline]
 __exit_signal kernel/exit.c:206 [inline]
 release_task+0x823/0xba0 kernel/exit.c:267
 exit_notify kernel/exit.c:781 [inline]
 do_exit+0xd64/0x1530 kernel/exit.c:992
 do_group_exit+0xfe/0x140 kernel/exit.c:1123
 get_signal+0xc49/0xd30 kernel/signal.c:3113
 arch_do_signal_or_restart+0x96/0x480 arch/x86/kernel/signal.c:337
 __exit_to_user_mode_loop kernel/entry/common.c:66 [inline]
 exit_to_user_mode_loop+0x161/0x940 kernel/entry/common.c:101
 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
 syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
 syscall_exit_to_user_mode include/linux/entry-common.h:343 [inline]
 do_syscall_64+0x23b/0x3a0 arch/x86/entry/syscall_64.c:107
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

read to 0xffff888101dfdce8 of 8 bytes by task 9915 on cpu 0:
 list_is_last include/linux/list.h:400 [inline]
 thread_group_empty include/linux/sched/signal.h:773 [inline]
 taskstats_tgid_alloc kernel/taskstats.c:535 [inline]
 taskstats_exit+0xbd/0x810 kernel/taskstats.c:578
 do_exit+0x427/0x1530 kernel/exit.c:949
 do_group_exit+0x138/0x140 kernel/exit.c:1123
 __do_sys_exit_group kernel/exit.c:1134 [inline]
 __se_sys_exit_group kernel/exit.c:1132 [inline]
 __x64_sys_exit_group+0x1f/0x20 kernel/exit.c:1132
 x64_sys_call+0x254f/0x2550 arch/x86/include/generated/asm/syscalls_64.h:232
 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

value changed: 0xffff888104633a68 -> 0xffff8881025186a8

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

Crashes (5):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 23:44 upstream 63fdb511c27a 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in release_task / taskstats_exit
2026/11/17 23:41 upstream 63fdb511c27a 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in release_task / taskstats_exit
2026/11/17 19:27 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in release_task / taskstats_exit
2026/11/17 11:36 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in release_task / taskstats_exit
2026/11/17 05:19 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in release_task / taskstats_exit
* Struck through repros no longer work on HEAD.