syzbot
KCSAN: data-race in complete_signal / stop_this_handle
Status:
moderation: reported on 2026/11/17 19:36
Subsystems:
ext4
Labels:
prio:low
race:benign
[Documentation on labels]
Reported-by: syzbot+2184c4ccdca879b45fd2@syzkaller.appspotmail.com
First crash: 4h48m, last: 4h48m
β¨ AI-generated root cause summary:
A KCSAN data race occurs on the 4-byte task_struct::flags field between stop_this_handle() clearing PF_MEMALLOC_NOFS via memalloc_flags_restore() and an APIC timer interrupt in posixtimer_send_sigqueue() calling complete_signal() -> wants_signal() to test PF_EXITING. task_struct::flags packs both lockless task-local allocation flags and signal-related flags into a single unsigned int. While complete_signal() executes under p->sighand->siglock, memalloc_flags_restore() modifies current->flags without holding that lock, resulting in an unsynchronized read-write access.
▶
▼
β¨ Full AI root cause analysis
Technical Analysis of the KCSAN Data Race
1. Functions, Structs, and Fields Involved
- Field:
struct task_struct::flags (unsigned int, 4 bytes located at byte offset 0x2c on x86_64).
- Writer Path:
- Task 3550 running on CPU 1 handling a page fault (
ext4_page_mkwrite()) invokes jbd2_journal_stop() $\to$ stop_this_handle() (fs/jbd2/transaction.c:740).
stop_this_handle() restores the allocation context by calling memalloc_nofs_restore(handle->saved_alloc_context) $\to$ memalloc_flags_restore() (include/linux/sched/mm.h:341).
memalloc_flags_restore() executes current->flags &= ~flags;, clearing the PF_MEMALLOC_NOFS flag (bit 18, 0x00040000).
- Reader Path:
2. Root Cause & Concurrency Mechanism
-
Unsynchronized Field Sharing:
struct task_struct::flags is a composite bitmask packing various per-task flags into a single 32-bit unsigned int.
- Some flags (such as
PF_EXITING) are synchronized against signal delivery by holding tsk->sighand->siglock when set in exit_signals() (kernel/signal.c:3211).
- However, other flagsβsuch as
PF_MEMALLOC_NOFS, PF_MEMALLOC_NOIO, and PF_MEMALLOCβrepresent local memory allocation scopes that are modified frequently by current without holding sighand->siglock or taking any lock.
memalloc_flags_restore() performs a plain read-modify-write (current->flags &= ~flags), and wants_signal() performs a plain read (p->flags & PF_EXITING) without using LKMM access annotations such as READ_ONCE() or WRITE_ONCE().
-
Triggering the Race:
- Task 3550 on CPU 1 is clearing
PF_MEMALLOC_NOFS from current->flags without holding siglock.
- Simultaneously, an interrupt on CPU 0 sends a POSIX timer signal to the thread group or process, targeting task 3550. While CPU 0 holds
p->sighand->siglock, this does not synchronize with task 3550's memalloc_flags_restore().
- KCSAN detects the concurrent read-modify-write on CPU 1 and plain read on CPU 0 at offset
0x2c.
3. Nature and Safety of the Race
- No Lost Updates: Only the task itself (
current) modifies its own current->flags at runtime; external threads only read p->flags. As there are no concurrent writers to task_struct::flags, no flag updates are lost or overwritten.
- Independent Bit Positions: The writer operates on bit 18 (
PF_MEMALLOC_NOFS), whereas the reader inspects bit 2 (PF_EXITING). On modern architectures with naturally aligned 32-bit accesses, there is no word tearing. Modifying bit 18 cannot alter the value of bit 2.
- Invariant Stability:
PF_EXITING is only set once during task termination in exit_signals() under sighand->siglock. Because CPU 0 holds p->sighand->siglock during wants_signal(), PF_EXITING cannot transition while CPU 0 is evaluating it.
- Resolution: Marking the access with
READ_ONCE(p->flags) in wants_signal() (or using atomic bitops / READ_ONCE()/WRITE_ONCE() on shared task_struct::flags accesses) informs the compiler and sanitizers that concurrent modification of unrelated bits is expected.
Sample crash report:
* Struck through repros no longer work on HEAD.