Re: [PATCH 1/1] bcache: fix use-after-free when waiting for dirty-init threads

From: Coly Li

Date: Thu Nov 12 2026 - 11:09:13 EST


Hi Chen Fan,

Thanks for the patch.

> 2026年11月5日 21:19,Chen Fan <fan.chen@xxxxxxxxxxxx> 写道:
>
> We use multiple threads to count dirty sectors in parallel (read-only).
> bch_sectors_dirty_init() waits for the last dirty-init thread to set
> state.started to 0.
>
> However, after the last thread sets state.started to 0 but before it calls
> wake_up(&state->wait), bch_sectors_dirty_init() may observe started == 0,
> return from wait_event() directly, and free local variable state.
> The subsequent wake_up(&state->wait) then accesses freed memory, because
> bch_sectors_dirty_init() has already exited.
>
> Fix this by using a completion to wait for all dirty-init threads, so that
> no dirty-init thread can still access state after the wait completes.
>
> This issue was triggered in our environment with the following stack:
> ------------[ cut here ]------------
> [30433.391386] Internal error: Oops: 0000000096000047 [#1] SMP
> [30433.585804] CPU: 54 PID: 48242 Comm: bch_dirtcnt[1] Kdump: loaded Tainted: G 6.6.0-98.0.0.90.aarch64 #1
> [30433.718972] Call trace:
> [30433.722722] native_queued_spin_lock_slowpath+0x33c/0x420
> [30433.729401] __wake_up_common_lock+0xbc/0x118
> [30433.735050] __wake_up+0x20/0x38
> [30433.739575] bch_dirty_init_thread+0x1c0/0x1f8 [bcache]
> [30433.746169] kthread+0xf0/0x108
> [30433.750583] ret_from_fork+0x10/0x20
> [30433.755425] Code: 91002020 8b040284 f862d8a5 aa0403e2 (f8256841)
> ---[ end trace ]---
>
> Signed-off-by: Chen Fan <fan.chen@xxxxxxxxxxxx>


Recently I am overwhelmed by the CVE flood, let me respond you (and other patches) next week.

Best regards,

Coly Li