WSL2-Linux-Kernel/drivers/md/bcache
Lin Feng aa97f6cdb7 bcache: fix NULL pointer reference in cached_dev_detach_finish
Commit 0259d4498b ("bcache: move calc_cached_dev_sectors to proper
place on backing device detach") tries to fix calc_cached_dev_sectors
when bcache device detaches, but now we have:

cached_dev_detach_finish
    ...
    bcache_device_detach(&dc->disk);
        ...
        closure_put(&d->c->caching);
        d->c = NULL; [*explicitly set dc->disk.c to NULL*]
    list_move(&dc->list, &uncached_devices);
    calc_cached_dev_sectors(dc->disk.c); [*passing a NULL pointer*]
    ...

Upper codeflows shows how bug happens, this patch fix the problem by
caching dc->disk.c beforehand, and cache_set won't be freed under us
because c->caching closure at least holds a reference count and closure
callback __cache_set_unregister only being called by bch_cache_set_stop
which using closure_queue(&c->caching), that means c->caching closure
callback for destroying cache_set won't be trigger by previous
closure_put(&d->c->caching).
So at this stage(while cached_dev_detach_finish is calling) it's safe to
access cache_set dc->disk.c.

Fixes: 0259d4498b ("bcache: move calc_cached_dev_sectors to proper place on backing device detach")
Signed-off-by: Lin Feng <linf@wangsu.com>
Signed-off-by: Coly Li <colyli@suse.de>
Link: https://lore.kernel.org/r/20211112053629.3437-2-colyli@suse.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-12-14 20:32:54 -07:00
..
Kconfig block: make the block holder code optional 2021-08-09 11:50:42 -06:00
Makefile bcache: add sysfs file to display feature sets information of cache set 2020-07-25 07:38:21 -06:00
alloc.c bcache: remove PTR_CACHE 2021-04-11 08:37:55 -06:00
bcache.h bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
bcache_ondisk.h bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
bset.c bcache: Avoid comma separated statements 2021-02-10 08:06:00 -07:00
bset.h bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
btree.c bcache: Revert "bcache: use bvec_virt" 2021-11-08 06:23:17 -07:00
btree.h bcache: remove embedded struct cache_sb from struct cache_set 2020-10-02 14:25:30 -06:00
closure.c bcache: Convert to DEFINE_SHOW_ATTRIBUTE 2020-10-02 14:25:29 -06:00
closure.h
debug.c bcache: use bvec_kmap_local in bch_data_verify 2021-10-20 08:40:54 -06:00
debug.h
extents.c bcache: remove PTR_CACHE 2021-04-11 08:37:55 -06:00
extents.h
features.c bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
features.h bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
io.c bcache: remove the backing_dev_name field from struct cached_dev 2021-10-20 08:40:54 -06:00
journal.c md: bcache: Trivial typo fixes in the file journal.c 2021-04-11 08:37:56 -06:00
journal.h Revert "bcache: fix fifo index swapping condition in journal_pin_cmp()" 2019-11-18 08:35:47 -07:00
movinggc.c bcache: remove for_each_cache() 2020-10-02 14:25:29 -06:00
request.c bcache: remove bch_crc64_update 2021-10-20 08:40:54 -06:00
request.h block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
stats.c bcache: remove bcache device self-defined readahead 2021-06-08 15:06:03 -06:00
stats.h bcache: remove bcache device self-defined readahead 2021-06-08 15:06:03 -06:00
super.c bcache: fix NULL pointer reference in cached_dev_detach_finish 2021-12-14 20:32:54 -07:00
sysfs.c bcache: remove the backing_dev_name field from struct cached_dev 2021-10-20 08:40:54 -06:00
sysfs.h bcache: replace snprintf in show functions with sysfs_emit 2021-10-29 06:43:21 -06:00
trace.c
util.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
util.h for-5.16/bdev-size-2021-10-29 2021-11-01 09:50:37 -07:00
writeback.c bcache: remove bdev_sectors 2021-10-18 14:43:22 -06:00
writeback.h bcache: consider the fragmentation when update the writeback rate 2021-02-10 08:05:59 -07:00