KCSAN: data-race in memcpy_and_pad / net_rx_action

Status: moderation: reported on 2026/11/19 00:03
Subsystems: kernel
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+0dcf48192fe5ce7745db@syzkaller.appspotmail.com
First crash: 1d21h, last: 1d06h
✨ AI-generated root cause summary:

During fork/clone, arch_dup_task_struct() copies current's task_struct to the child via memcpy_and_pad() with hardware interrupts enabled. If a hardware interrupt occurs on the same CPU during this copy, IRQ exit runs pending softirqs (__irq_exit_rcu -> handle_softirqs -> net_rx_action), which borrows the interrupted task's current pointer and executes bpf_net_ctx_set(&__bpf_net_ctx), performing an unmarked write to current->bpf_net_context (offset 3184). KCSAN detects this concurrent access between the interrupted process context's 3456-byte read of current in memcpy_and_pad() and the softirq's 8-byte write in bpf_net_ctx_set() as a data race.

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

Root Cause Analysis

1. Functions, Structs, and Fields Involved

  • arch_dup_task_struct() (arch/x86/kernel/process.c:105): Invoked during dup_task_struct() (kernel/fork.c:927) in copy_process(). Copies current (src) into the allocated child dst using memcpy_and_pad(dst, arch_task_struct_size, src, sizeof(*dst), 0) (lib/string_helpers.c:1008).
  • net_rx_action() (net/core/dev.c:8178): The softirq action handler for NET_RX_SOFTIRQ, called on IRQ exit (__irq_exit_rcu() -> invoke_softirq() -> handle_softirqs()).
  • bpf_net_ctx_set() / bpf_net_ctx_clear() (include/linux/filter.h:904-920): Helpers that manage per-task BPF redirect and flush contexts.
  • struct task_struct::bpf_net_context (include/linux/sched.h:1637): Pointer located at offset 0xc70 (byte 3184 / bit 25472) in task_struct, pointing to a stack-allocated struct bpf_net_context.

2. Detailed Technical Mechanism

  1. A user task executes sys_clone(), which calls copy_process() -> dup_task_struct().
  2. dup_task_struct() calls arch_dup_task_struct(dst, orig) (orig == current). On x86, this executes:
    memcpy_and_pad(dst, arch_task_struct_size, src, sizeof(*dst), 0);
    
    This reads 3456 bytes covering the entire task_struct of current starting at address 0xffff888104cad640. This copy runs with local hardware interrupts enabled.
  3. Under KCSAN instrumentation, the read access inside memcpy_and_pad() calls __tsan_memcpy(), which sets a watchpoint across the memory range and enters kcsan_setup_watchpoint() -> delay_access() (udelay()).
  4. While the CPU is executing the delay in process context, a hardware interrupt arrives on CPU 0 (common_interrupt -> asm_common_interrupt).
  5. Upon IRQ exit on CPU 0, __irq_exit_rcu() determines that softirqs are pending and calls handle_softirqs() -> net_rx_action().
  6. When running softirqs out of interrupt exit context (!in_interrupt() softirq processing), execution context borrows the interrupted task's current pointer. In net_rx_action() (net/core/dev.c:8188):
    struct bpf_net_context __bpf_net_ctx, *bpf_net_ctx;
    ...
    bpf_net_ctx = bpf_net_ctx_set(&__bpf_net_ctx);
    
  7. bpf_net_ctx_set() writes the address of the softirq stack variable &__bpf_net_ctx into current->bpf_net_context:
    tsk->bpf_net_context = bpf_net_ctx;
    
    This 8-byte write occurs at address 0xffff888104cae2b0 (offset 3184 within current), which overlaps with the memory range currently monitored by KCSAN's read watchpoint.
  8. Because tsk->bpf_net_context = bpf_net_ctx; is an unmarked plain write to memory that is concurrently registered as being read by the interrupted task's memcpy_and_pad(), KCSAN reports a data-race between process context and interrupt context.

3. Invariants and Safety Evaluation

  • In real-world kernels without KCSAN's artificial delay:
    • Softirq handling in net_rx_action() executes synchronously on the same CPU (CPU 0) while the interrupted process's execution is suspended.
    • Every exit path in net_rx_action() (net/core/dev.c:8243) unconditionally calls bpf_net_ctx_clear(bpf_net_ctx), restoring current->bpf_net_context = NULL.
    • Because net_rx_action() finishes and clears current->bpf_net_context before CPU 0 returns to the interrupted instruction in memcpy_and_pad(), the interrupted memcpy_and_pad() only ever reads NULL for bpf_net_context both before and after the interrupt. No pointer to the softirq stack frame ever leaks into the child task struct.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
d8043b50 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in memcpy_and_pad / net_rx_action 2026/11/18 06:29 2026/11/18 06:29 2026/11/18 06:50 eb4895d7
a41d2be6 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in memcpy_and_pad / net_rx_action 2026/11/18 06:27 2026/11/18 06:27 2026/11/18 07:14 eb4895d7

Sample crash report:
==================================================================
BUG: KCSAN: data-race in memcpy_and_pad / net_rx_action

write to 0xffff888104cae2b0 of 8 bytes by interrupt on cpu 0:
 bpf_net_ctx_set include/linux/filter.h:912 [inline]
 net_rx_action+0x12e/0x850 net/core/dev.c:8188
 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
 common_interrupt+0x83/0x90 arch/x86/kernel/irq.c:273
 asm_common_interrupt+0x26/0x40 arch/x86/include/asm/idtentry.h:665
 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
 check_access kernel/kcsan/core.c:762 [inline]
 __tsan_memcpy+0x3b4/0x3c0 kernel/kcsan/core.c:1374
 memcpy_and_pad+0x48/0x80 lib/string_helpers.c:1008
 arch_dup_task_struct+0x2c/0x40 arch/x86/kernel/process.c:108
 dup_task_struct+0x6d/0x7d0 kernel/fork.c:927
 copy_process+0x570/0x2310 kernel/fork.c:2150
 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

read to 0xffff888104cad640 of 3456 bytes by task 3300 on cpu 0:
 memcpy_and_pad+0x48/0x80 lib/string_helpers.c:1008
 arch_dup_task_struct+0x2c/0x40 arch/x86/kernel/process.c:108
 dup_task_struct+0x6d/0x7d0 kernel/fork.c:927
 copy_process+0x570/0x2310 kernel/fork.c:2150
 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: 0 UID: 0 PID: 3300 Comm: syz-executor Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 18:02 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in memcpy_and_pad / net_rx_action
2026/11/17 18:02 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in memcpy_and_pad / net_rx_action
2026/11/17 10:26 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in memcpy_and_pad / net_rx_action
2026/11/17 03:22 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in memcpy_and_pad / net_rx_action
* Struck through repros no longer work on HEAD.