syzbot
KCSAN: data-race in device_del / rcu_core
Status:
moderation: reported on 2026/11/17 15:48
Subsystems:
kernel
Labels:
race:benign
prio:high
[Documentation on labels]
Reported-by: syzbot+84dcd5d1da09793f0c05@syzkaller.appspotmail.com
First crash: 12h44m, last: 12h44m
✨ AI-generated root cause summary:
A data race occurs on task_struct::flags between process context and interrupt/softirq context. During device unregistration in device_del(), memalloc_noio_restore() calls memalloc_flags_restore(), performing an unmarked plain read-modify-write (current->flags &= ~flags;) to clear PF_MEMALLOC_NOIO with interrupts enabled. An APIC timer interrupt interrupting this task triggers RCU_SOFTIRQ, where rcu_do_batch() calls is_idle_task(current) to check whether callback processing should yield, performing an unmarked plain read (p->flags & PF_IDLE) on the same flags word of the interrupted task. Because neither access uses READ_ONCE()/WRITE_ONCE() or synchronization, KCSAN detects a concurrent read and write to task_struct::flags.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Functions, Structs, and Fields Involved
2. Technical Mechanism and Trigger Sequence
-
Task Context Modification of task_struct::flags:
During network namespace cleanup (cleanup_net() -> default_device_exit_batch() -> unregister_netdevice_many_notify() -> netdev_unregister_kobject()), device_del() executes under process context with interrupts enabled.
At line 3989 of drivers/base/core.c, device_del() restores allocation flags using:
memalloc_noio_restore(noio_flag);
This invokes memalloc_flags_restore() in include/linux/sched/mm.h:
static inline void memalloc_flags_restore(unsigned flags)
{
current->flags &= ~flags;
}
This operation executes an unmarked, non-atomic plain C read-modify-write on current->flags to clear the PF_MEMALLOC_NOIO bit.
-
Interruption by Timer Softirq:
While KCSAN delays the access to instrument concurrent memory accesses (or during this write window on CPU 0), an APIC timer interrupt fires on CPU 0, interrupting the task (PID 1788, kworker).
On interrupt exit (__irq_exit_rcu()), pending softirqs are served via handle_softirqs(), which processes RCU_SOFTIRQ via rcu_core() and rcu_do_batch().
-
Softirq Context Inspection of task_struct::flags:
Because softirqs execute on the same CPU in the context of the interrupted task, current remains set to task 1788.
In kernel/rcu/tree.c:
if (in_serving_softirq()) {
if (count >= bl && (need_resched() || !is_idle_task(current)))
break;
rcu_do_batch() evaluates is_idle_task(current) to determine whether the RCU callback batch should be broken to prevent starving other tasks or softirqs. is_idle_task() (include/linux/sched.h) executes:
static __always_inline bool is_idle_task(const struct task_struct *p)
{
return !!(p->flags & PF_IDLE);
}
This is an unmarked plain C read on p->flags (current->flags).
-
KCSAN Data-Race Detection:
Neither the read in is_idle_task() nor the read-modify-write in memalloc_flags_restore() is marked with atomic accessors or READ_ONCE() / WRITE_ONCE(), nor are interrupts disabled during memalloc_flags_restore(). As a result, KCSAN flags the concurrent read and write to current->flags (0xffff8881046722ac) as a data race between task context and softirq context.
Sample crash report:
* Struck through repros no longer work on HEAD.