]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
loop: be paranoid on exit and prevent new additions / removals
authorLuis Chamberlain <mcgrof@kernel.org>
Fri, 19 Jun 2020 20:47:27 +0000 (20:47 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Aug 2020 06:26:15 +0000 (08:26 +0200)
[ Upstream commit 200f93377220504c5e56754823e7adfea6037f1a ]

Be pedantic on removal as well and hold the mutex.
This should prevent uses of addition while we exit.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/block/loop.c

index 475e1a738560daa8b955955d228dccee990593fc..776083963ee6c7c931ba050c765e88275bc8ba84 100644 (file)
@@ -2402,6 +2402,8 @@ static void __exit loop_exit(void)
 
        range = max_loop ? max_loop << part_shift : 1UL << MINORBITS;
 
+       mutex_lock(&loop_ctl_mutex);
+
        idr_for_each(&loop_index_idr, &loop_exit_cb, NULL);
        idr_destroy(&loop_index_idr);
 
@@ -2409,6 +2411,8 @@ static void __exit loop_exit(void)
        unregister_blkdev(LOOP_MAJOR, "loop");
 
        misc_deregister(&loop_misc);
+
+       mutex_unlock(&loop_ctl_mutex);
 }
 
 module_init(loop_init);