syzbot
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
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
- A user task executes
sys_clone(), which calls copy_process() -> dup_task_struct().
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.
- 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()).
- While the CPU is executing the delay in process context, a hardware interrupt arrives on CPU 0 (
common_interrupt -> asm_common_interrupt).
- Upon IRQ exit on CPU 0,
__irq_exit_rcu() determines that softirqs are pending and calls handle_softirqs() -> net_rx_action().
- 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);
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.
- 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.
Sample crash report:
* Struck through repros no longer work on HEAD.