Root Cause Analysis
1. Functions, Structs, and Fields Involved
- File:
kernel/capability.c (invoked via net/sysctl_net.c)
- Function:
ns_capable_common() (inlined into ns_capable_noaudit())
- Struct & Field:
struct task_struct::flags (offset 0x2c, size 4 bytes, matching address 0xffff888101d2452c on the reported task_struct)
- Constants:
PF_SUPERPRIV (0x00000100 in include/linux/sched.h)
2. Mechanism and Lifecycle Violation
When a process opens a sysctl node under /proc/sys/net/ (here triggered by dhcpcd opening /proc/sys/net/... via openat), permission checking in fs/proc/proc_sysctl.c:proc_sys_permission() invokes the network sysctl permission handler net_ctl_permissions() in net/sysctl_net.c:
static int net_ctl_permissions(struct ctl_table_header *head,
const struct ctl_table *table)
{
struct net *net = container_of(head->set, struct net, sysctls);
/* Allow network administrator to have same access as root. */
if (ns_capable_noaudit(net->user_ns, CAP_NET_ADMIN)) {
...
ns_capable_noaudit() delegates to ns_capable_common() in kernel/capability.c:
static bool ns_capable_common(struct user_namespace *ns,
int cap,
unsigned int opts)
{
int capable;
...
capable = security_capable(current_cred(), ns, cap, opts);
if (capable == 0) {
current->flags |= PF_SUPERPRIV;
return true;
}
return false;
}
At line 343, ns_capable_common() performs an unmarked read-modify-write on current->flags (current->flags |= PF_SUPERPRIV;).
In the Linux kernel's task concurrency model, task_struct::flags stores process flags (PF_*), which are written strictly by the task itself (current) in task context. Concurrent tasks only read certain flags (or write separate fields like atomic_flags). However, because current->flags |= PF_SUPERPRIV; is an unmarked plain memory access rather than an annotated access (READ_ONCE()/WRITE_ONCE() or atomic flag operations), KCSAN instruments this write.
3. How the KCSAN Splat (0x0 / ns_capable_noaudit) Occurred
- Watchpoint Setup: KCSAN instrumented the read-modify-write on
current->flags in ns_capable_common(), setting a watchpoint on 0xffff888101d2452c and entering delay_access().
- Watchpoint Hit: When
CONFIG_KCSAN_INTERRUPT_WATCHER=y, kcsan_setup_watchpoint() leaves local IRQs enabled and preemption unblocked across delay_access(). A subsequent instrumented read of current->flags on CPU 1 (while current was still task 3018, e.g. during an interrupt exit / preemption window entering __schedule() or scheduler code) tripped the watchpoint.
in_task() Context: Because in_task() checks !(preempt_count() & (NMI_MASK | HARDIRQ_MASK | SOFTIRQ_OFFSET)), any read outside hardirq/NMI/softirq (for example, after irq_exit_rcu() clears the hardirq mask and calls into scheduler preemption) evaluated in_task() as true. This caused get_ctx() to return ¤t->kcsan_ctx and recorded the racing access with task_pid = 3018 and cpu_id = 1.
- Empty Stack Trace /
0x0: For standard non-scoped memory accesses, ai.ip is recorded as 0 (kernel/kcsan/report.c:652). In prepare_report_producer(), stack_trace_save() attempted to unwind the stack for the racing read. In this context (e.g., within an entry/exit or assembly stub lacking ORC unwind information), the unwinder returned 0 entries. In sanitize_stack_entries(), get_stack_skipnr() returned 0, leaving other_frame = 0x0. Consequently, print_report() printed BUG: KCSAN: data-race in 0x0 / ns_capable_noaudit, and print_stack_trace() printed 0 frames for the first access.
- No Value Change: Because
dhcpcd was already running with UID 0 / root, PF_SUPERPRIV was already set on task_struct::flags, so the read-modify-write resulted in identical values (old == new), producing no value changed: line in the KCSAN report.