Technical Root Cause Analysis
1. The Racing Memory Access and Invariants Involved
The memory address reported by KCSAN (0xffff888103c4c52c, 4 bytes) corresponds to current->flags (struct task_struct::flags at byte offset 0x2c).
In inotify_update_watch() (fs/notify/inotify/inotify_user.c:636), fsnotify_group_unlock() calls memalloc_nofs_restore(group->owner_flags), which in turn invokes memalloc_flags_restore() (include/linux/sched/mm.h:341):
static inline void memalloc_flags_restore(unsigned flags)
{
current->flags &= ~flags;
}
This compound read-modify-write (&= ~flags) on current->flags is unmarked (unlike other accessors such as current_gfp_context() which explicitly uses READ_ONCE(current->flags)).
2. Why Task 7132 Hit Its Own Watchpoint on CPU 1
When memalloc_flags_restore() executed the read-modify-write on current->flags, KCSAN selected this write to set up a watchpoint in kcsan_setup_watchpoint() (kernel/kcsan/core.c:528).
Under CONFIG_KCSAN_INTERRUPT_WATCHER=y:
kcsan_setup_watchpoint() leaves interrupts enabled (local_irq_save() is skipped).
- It increments
ctx->disable_scoped, but does not increment current->kcsan_ctx.disable_count or the CPU's disable count.
- Consequently, while task 7132 pauses inside
delay_access() via udelay(), an interrupt or IRQ exit path executes with in_task() == true on CPU 1.
- During this interrupt/exit or rescheduling execution on the same CPU, an instrumented read of
current->flags occurred.
- Because
current->kcsan_ctx.disable_count was zero, kcsan_is_enabled() returned true, and check_access() located the watchpoint that task 7132 had just installed on its own task_struct::flags.
try_consume_watchpoint() succeeded, invoking kcsan_report_set_info() (kernel/kcsan/report.c:656), which recorded other_info with ai.task_pid = 7132 and ai.cpu_id = 1.
3. Why selinux_inode_permission Appeared in the Report with an Empty Stack Trace
In kcsan_report_set_info(), prepare_report_producer() calls:
other_info->num_stack_entries = stack_trace_save(other_info->stack_entries, NUM_STACK_ENTRIES, 2);
In this scenario, either num_stack_entries was 0 or all captured frames were KCSAN/entry runtime functions filtered by get_stack_skipnr(), resulting in:
other_skipnr == other_info->num_stack_entries
In print_report() (kernel/kcsan/report.c:413-416):
other_skipnr = sanitize_stack_entries(other_info->stack_entries,
other_info->num_stack_entries,
other_info->ai.ip, &other_reordered_to);
other_frame = other_info->stack_entries[other_skipnr];
When other_skipnr == other_info->num_stack_entries:
other_frame reads other_info->stack_entries[other_skipnr], which indexes beyond num_stack_entries.
release_report() only clears other_info->ai.size = 0 without zeroing other_info->stack_entries[].
- Thus,
other_frame picked up a stale function address (selinux_inode_permission) from whatever previous report occupied slot watchpoint_idx in other_infos[].
stack_trace_print(other_info->stack_entries + other_skipnr, other_info->num_stack_entries - other_skipnr, ...) was called with nr_entries = 0, printing zero stack frames under read to 0xffff888103c4c52c of 4 bytes by task 7132 on cpu 1:.