diff options
author | Lin Feng <linf@wangsu.com> | 2021-11-12 13:36:29 +0800 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2021-12-14 20:32:54 -0700 |
commit | aa97f6cdb7e92909e17c8ca63e622fcb81d57a57 (patch) | |
tree | 3fe44f476f63dfe49cf447a31d3a5388a0267cf6 /block | |
parent | cb2ac2912a9ca7d3d26291c511939a41361d2d83 (diff) | |
download | linux-aa97f6cdb7e92909e17c8ca63e622fcb81d57a57.tar.bz2 |
bcache: fix NULL pointer reference in cached_dev_detach_finish
Commit 0259d4498ba4 ("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: 0259d4498ba4 ("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>
Diffstat (limited to 'block')
0 files changed, 0 insertions, 0 deletions