loop: Avoid circular locking dependency between loop_ctl_mutex and bd_mutex
authorJan Kara <jack@suse.cz>
Thu, 8 Nov 2018 13:01:15 +0000 (14:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Jan 2019 20:40:38 +0000 (21:40 +0100)
commit5c684c250bf3b918eb4ce87f64d074c3e0306a6f
treee96b100576584bbe093edb9d9737d276ee3e0cc1
parent5f0db37d916bece442472e0714de75e330c439e8
loop: Avoid circular locking dependency between loop_ctl_mutex and bd_mutex

commit 1dded9acf6dc9a34cd27fcf8815507e4e65b3c4f upstream.

Code in loop_change_fd() drops reference to the old file (and also the
new file in a failure case) under loop_ctl_mutex. Similarly to a
situation in loop_set_fd() this can create a circular locking dependency
if this was the last reference holding the file open. Delay dropping of
the file reference until we have released loop_ctl_mutex.

Reported-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/block/loop.c