syzbot
KCSAN: data-race in 0x0 / blk_account_io_start
Status:
moderation: reported on 2026/11/20 00:00
Subsystems:
block
Labels:
prio:low
race:benign
[Documentation on labels]
Reported-by: syzbot+251c5bf92bba96a3b8d1@syzkaller.appspotmail.com
First crash: 2d21h, last: 2d14h
✨ AI-generated root cause summary:
In blk_time_get_ns() (block/blk.h), the block layer attempts to cache timestamps for plugged I/O submissions by updating current->flags |= PF_BLOCK_TS using a plain, unannotated read-modify-write without disabling interrupts or preemption. When KCSAN places a watchpoint on current->flags at offset 0x2c of task_struct during blk_account_io_start(), task preemption under PREEMPT(lazy) allows the task to yield and later be scheduled back in on CPU 0. During context switch in finish_task_switch(), blk_plug_invalidate_ts() performs a plain 4-byte read of current->flags & PF_BLOCK_TS while the unwinder cannot resolve frames during task switch, triggering a data-race report against blk_time_get_ns(). Furthermore, non-atomic bitwise operations on current->flags violate concurrent access invariants when flags are inspected or cleared asynchronously across preemption points.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
1. Functions, Structs, and Files Involved
2. Triggering Mechanism and Race Condition
-
Unannotated Read-Modify-Write in blk_time_get_ns():
When a request is initiated through blk_account_io_start(), it retrieves the I/O start timestamp via blk_time_get_ns():
now = READ_ONCE(plug->cur_ktime);
if (!now) {
now = ktime_get_ns();
WRITE_ONCE(plug->cur_ktime, now);
/* Ensure PF_BLOCK_TS is set after cur_ktime. */
barrier();
current->flags |= PF_BLOCK_TS;
}
current->flags |= PF_BLOCK_TS; is a plain C 4-byte read-modify-write operation on task_struct::flags. It does not use atomic bit operations, nor is it annotated with data_race() or synchronization wrappers.
-
KCSAN Watchpoint & Preemption under PREEMPT(lazy):
With CONFIG_KCSAN_STRICT=y enabled, kcsan_ignore_address() does not suppress races on ¤t->flags. Furthermore, with CONFIG_KCSAN_INTERRUPT_WATCHER=y, kcsan_setup_watchpoint() installs a watchpoint on ¤t->flags (0xffff8881045e67ac) and executes delay_access() without disabling preemption or local interrupts.
During this delay on CPU 0, task 3288 is preempted under lazy preemption (PREEMPT(lazy)) and yields CPU 0.
-
Conflicting Access in Context Switch Path (0x0 Stack):
When task 3288 is subsequently scheduled back onto CPU 0, the scheduler's finish_task_switch() calls:
/*
* Any cached block-layer timestamp (plug->cur_ktime) is stale now,
* invalidate it.
*/
blk_plug_invalidate_ts();
Inside blk_plug_invalidate_ts() (include/linux/blk_plug.h):
static __always_inline void blk_plug_invalidate_ts(void)
{
if (unlikely(current->flags & PF_BLOCK_TS)) {
current->plug->cur_ktime = 0;
current->flags &= ~PF_BLOCK_TS;
}
}
This performs a plain 4-byte read of current->flags. Because task 3288 is in task context (in_task() == true), prepare_access_info() assigns task_pid = task_pid_nr(current) (PID 3288 on CPU 0). Because the stack unwinder cannot resolve backtrace symbols during this transition in finish_task_switch(), stack_trace_save() returns zero valid frames (other_frame = 0x0), resulting in the KCSAN data-race report:
BUG: KCSAN: data-race in 0x0 / blk_account_io_start.
3. Violated Invariants
current->flags contains multiple scheduler, memory-reclaim, and process-state flags (such as PF_MEMALLOC, PF_NOFREEZE, PF_VCPU, etc.) that can be examined or cleared across context switches, scheduler events, and asynchronous contexts. Performing unannotated, non-atomic bitwise read-modify-writes (current->flags |= PF_BLOCK_TS and current->flags &= ~PF_BLOCK_TS) without memory ordering or concurrency annotations violates KCSAN data race invariants and creates a window where plug->cur_ktime is set before PF_BLOCK_TS is observed.
Sample crash report:
* Struck through repros no longer work on HEAD.