Root Cause Analysis
1. Mechanism & Involved Components
- Source Files:
- Functions & Structs:
2. Technical Breakdown
During process creation via clone3() / copy_process(), dup_task_struct(current, node) creates a copy of the parent process's task structure by calling arch_dup_task_struct(tsk, orig). On x86 (arch/x86/kernel/process.c:108), this is implemented as:
memcpy_and_pad(dst, arch_task_struct_size, src, sizeof(*dst), 0);
where src points to the live current task (sizeof(*dst) = 3456 bytes). With CONFIG_THREAD_INFO_IN_TASK=y, current->thread_info is located at byte offset 0 of struct task_struct, with unsigned long flags at offset 0 of thread_info.
Because arch_dup_task_struct() runs with interrupts enabled, local interrupt handlers or other CPUs can concurrently modify fields in current->thread_info.flags via atomic bit operations. In the reported scenario:
__tsan_memcpy (instrumenting memcpy inside memcpy_and_pad()) established a KCSAN read watchpoint covering the 3456 bytes of current (starting at offset 0, address 0xffff888101dfc500).
- While
__tsan_memcpy was delaying in kcsan_setup_watchpoint() -> delay_access(), an APIC timer interrupt arrived on the same CPU (sysvec_apic_timer_interrupt).
- In interrupt context,
hrtimer_interrupt() invoked hrtimer_interrupt_rearm() (kernel/time/hrtimer.c:2211), executing:
set_thread_flag(TIF_HRTIMER_REARM);
This performs an atomic bitwise write (set_bit(TIF_HRTIMER_REARM, ¤t_thread_info()->flags)) marked by instrument_atomic_write().
- KCSAN detected the collision between the marked atomic write in the IRQ handler and the unmarked bulk read in
memcpy_and_pad().
3. Invariants & Lifecycle
When returning from an interrupt that interrupted kernel mode with interrupts enabled, irqentry_exit_to_kernel_mode_after_preempt() (include/linux/irq-entry-common.h:488) immediately calls:
irqentry_hrtimer_rearm_deferred() -> hrtimer_rearm_deferred() -> hrtimer_rearm_deferred_tif()
which tests and clears TIF_HRTIMER_REARM via hrtimer_test_and_clear_rearm_deferred_tif() and executes __hrtimer_rearm_deferred() before execution returns to the interrupted kernel code (memcpy_and_pad()). As a result, TIF_HRTIMER_REARM is strictly transient within the interrupt handler on return to kernel mode and is cleared before memcpy_and_pad() resumes copying.