]> git.baikalelectronics.ru Git - kernel.git/commit
nbd: prevent IDR lookups from finding partially initialized devices
authorTetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Wed, 25 Aug 2021 16:31:05 +0000 (18:31 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 25 Aug 2021 20:20:22 +0000 (14:20 -0600)
commit8f972266879118a6e0410983d9ba47285d2335f0
treea930de7bca8bc3176fbd5b7537a7e8b75f81c4eb
parent1b9553a4c96bf52fcaca1c2f8e3cb543a6d27b05
nbd: prevent IDR lookups from finding partially initialized devices

Previously nbd_index_mutex was held during whole add/remove/lookup
operations in order to guarantee that partially initialized devices are
not reachable via idr_find() or idr_for_each(). But now that partially
initialized devices become reachable as soon as idr_alloc() succeeds,
we need to skip partially initialized devices. Since it seems that
all functions use refcount_inc_not_zero(&nbd->refs) in order to skip
destroying devices, update nbd->refs from zero to non-zero as the last
step of device initialization in order to also skip partially initialized
devices.

Fixes: 695c315d0b5c ("nbd: reduce the nbd_index_mutex scope")
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
[hch: split from a larger patch, added comments]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210825163108.50713-4-hch@lst.de
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/nbd.c