]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcache: fix uninitialized closure object
authorMingzhe Zou <mingzhe.zou@easystack.cn>
Fri, 3 Apr 2026 04:21:35 +0000 (12:21 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 3 Apr 2026 11:11:08 +0000 (05:11 -0600)
In the previous patch ("bcache: fix cached_dev.sb_bio use-after-free and
crash"), we adopted a simple modification suggestion from AI to fix the
use-after-free.

But in actual testing, we found an extreme case where the device is
stopped before calling bch_write_bdev_super().

At this point, struct closure sb_write has not been initialized yet.
For this patch, we ensure that sb_bio has been completed via
sb_write_mutex.

Signed-off-by: Mingzhe Zou <mingzhe.zou@easystack.cn>
Signed-off-by: Coly Li <colyli@fnnas.com>
Link: https://patch.msgid.link/20260403042135.2221247-1-colyli@fnnas.com
Fixes: fec114a98b87 ("bcache: fix cached_dev.sb_bio use-after-free and crash")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/super.c

index 6627a381f65ae7009186ada5f91ccdd770550f65..97d9adb0bf96b0a0267784c3ee8f3be8fd138f6e 100644 (file)
@@ -1378,7 +1378,8 @@ static CLOSURE_CALLBACK(cached_dev_free)
         * The sb_bio is embedded in struct cached_dev, so we must
         * ensure no I/O is in progress.
         */
-       closure_sync(&dc->sb_write);
+       down(&dc->sb_write_mutex);
+       up(&dc->sb_write_mutex);
 
        if (dc->sb_disk)
                folio_put(virt_to_folio(dc->sb_disk));