KCSAN: data-race in 0x0 / copy_process

Status: moderation: reported on 2026/11/18 06:03
Subsystems: mm
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+0bdf2dfed1c4cde2176c@syzkaller.appspotmail.com
First crash: 1d04h, last: 10h23m
✨ AI-generated root cause summary:

In copy_process() (kernel/fork.c:2198), current->flags &= ~PF_NPROC_EXCEEDED is executed unconditionally on every fork/clone invocation to clear the RLIMIT_NPROC excess indicator. Because this is an unmarked, non-atomic compound read-modify-write on the live parent task's struct task_struct::flags field, it races with concurrent lockless reads of tsk->flags (such as by scheduler hooks or asynchronous thread inspection), causing KCSAN to report a data race.

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

Root Cause Analysis

1. Components and Functions Involved

  • Source file: kernel/fork.c
  • Function: copy_process() (line 2198)
  • Data structure: struct task_struct (specifically the unsigned int flags field at offset 0x2c / 352 bits)
  • Flag macro: PF_NPROC_EXCEEDED (0x00001000 defined in include/linux/sched.h)

2. Technical Mechanism and Triggering Flow

The PF_NPROC_EXCEEDED flag is used in conjunction with credential modifications and process execution (sys_setuid, sys_setreuid, sys_setresuid via flag_nproc_exceeded() in kernel/sys.c, and checked in do_execveat_common() in fs/exec.c). When user limits are exceeded during set*uid(), PF_NPROC_EXCEEDED is flagged on current to defer the -EAGAIN failure until the subsequent execve() call, avoiding breaking applications that fail to check the return code of setuid().

During process creation via clone() or fork(), kernel_clone() calls copy_process(). At kernel/fork.c:2198:

	retval = -EAGAIN;
	if (is_rlimit_overlimit(task_ucounts(p), UCOUNT_RLIMIT_NPROC, rlimit(RLIMIT_NPROC))) {
		if (p->real_cred->user != INIT_USER &&
		    !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
			goto bad_fork_cleanup_count;
	}
	current->flags &= ~PF_NPROC_EXCEEDED;

While modifying p->flags (lines 2170, 2210–2211) modifies the newly allocated child task_struct before it is visible or runnable anywhere, line 2198 operates on current->flagsβ€”the live calling parent task.

The line performs an unconditional, unmarked compound read-modify-write (&= ~PF_NPROC_EXCEEDED) on current->flags on every fork/clone invocation, even though PF_NPROC_EXCEEDED is almost always already clear.

3. Invariant Violation and KCSAN Detection

In the Linux kernel's task concurrency model (documented in include/linux/sched.h above clear_stopped_child_used_math()):

  • Only the current task writes to its own tsk->flags (flags requiring cross-thread atomic modifications are stored in task_struct::atomic_flags with PFA_* accessors).
  • However, various kernel subsystems (e.g., preemption hooks in __schedule(), PSI, workqueue management, tracing, or asynchronous thread checks like tsk_used_math()) read tsk->flags locklessly.

Because current->flags &= ~PF_NPROC_EXCEEDED is an plain C compound read-modify-write without explicit atomic markup (such as READ_ONCE() / WRITE_ONCE()) and without checking whether current->flags & PF_NPROC_EXCEEDED is actually set before writing, KCSAN's watchpoint on the read-modify-write detects concurrent lockless reads, triggering the data race report.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
c117c923 assessment-kcsan πŸƒ KCSAN: data-race in 0x0 / copy_process 2026/11/18 06:12 2026/11/18 06:12 eb4895d7
9707932c assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: βœ… UserNamespace: βœ… VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in 0x0 / copy_process 2026/11/18 05:49 2026/11/18 05:49 2026/11/18 05:58 ca622473

Sample crash report:
==================================================================
BUG: KCSAN: data-race in 0x0 / copy_process

read to 0xffff8881046a67ac of 4 bytes by task 3711 on cpu 1:

read-write to 0xffff8881046a67ac of 4 bytes by task 3711 on cpu 1:
 copy_process+0x96e/0x2310 kernel/fork.c:2198
 kernel_clone+0x1c6/0x640 kernel/fork.c:2798
 __do_sys_clone kernel/fork.c:2940 [inline]
 __se_sys_clone kernel/fork.c:2924 [inline]
 __x64_sys_clone+0x143/0x180 kernel/fork.c:2924
 x64_sys_call+0x2479/0x2550 arch/x86/include/generated/asm/syscalls_64.h:57
 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: 1 UID: 0 PID: 3711 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (9):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 20:26 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / copy_process
2026/11/17 20:24 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / copy_process
2026/11/17 19:43 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / copy_process
2026/11/17 17:26 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / copy_process
2026/11/17 17:14 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / copy_process
2026/11/17 17:13 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / copy_process
2026/11/17 02:54 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / copy_process
2026/11/17 02:21 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / copy_process
2026/11/17 02:06 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in 0x0 / copy_process
* Struck through repros no longer work on HEAD.