Root Cause Analysis
1. Functions, Structs, and Fields Involved
- Source File:
kernel/exit.c
- Functions:
mm_update_next_owner() (lines 489–545) and helper __try_to_set_owner() (lines 454–468)
- Struct and Field:
struct mm_struct::owner (declared with __rcu in include/linux/mm_types.h:1377)
2. Detailed Technical Mechanism and Invariant Violation
When a task exits or performs exec, exit_mm() (or exec_mm_put_old()) calls mm_update_next_owner(mm) to find a new task to serve as the canonical owner of the mm_struct if the exiting task is the current owner.
In a multithreaded process where several threads exit concurrently (for example, as a result of do_group_exit() / sys_exit_group()):
-
Thread 1 (Task 18863), which is the current mm->owner, enters exit_mm():
-
Thread 2 (Task 18867), another exiting thread sharing the same mm, concurrently enters exit_mm():
Because Thread 1 writes to mm->owner using WRITE_ONCE() while Thread 2 concurrently reads mm->owner with a plain memory access, KCSAN detects a data race between a marked write (kernel/exit.c:462) and an unmarked read (kernel/exit.c:497).
3. Resolution
To conform to the kernel's memory model and eliminate the KCSAN data-race warning, the lockless read of mm->owner at line 497 in kernel/exit.c should be annotated using READ_ONCE(mm->owner) or rcu_access_pointer(mm->owner) (since mm->owner is an __rcu pointer).