]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
md: fix a lock order reversal in md_alloc
authorChristoph Hellwig <hch@lst.de>
Wed, 1 Sep 2021 11:38:29 +0000 (13:38 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 5 Nov 2021 08:12:44 +0000 (09:12 +0100)
commitadfef477d9cbb73c6d10213511f19449be253e92
treeeecbda4295754a578e8731461e400ea75dc15f9e
parent01a0b344f8a63378ca295b770d80a5195b71e92c
md: fix a lock order reversal in md_alloc

BugLink: https://bugs.launchpad.net/bugs/1947886
[ Upstream commit 7df835a32a8bedf7ce88efcfa7c9b245b52ff139 ]

Commit b0140891a8cea3 ("md: Fix race when creating a new md device.")
not only moved assigning mddev->gendisk before calling add_disk, which
fixes the races described in the commit log, but also added a
mddev->open_mutex critical section over add_disk and creation of the
md kobj.  Adding a kobject after add_disk is racy vs deleting the gendisk
right after adding it, but md already prevents against that by holding
a mddev->active reference.

On the other hand taking this lock added a lock order reversal with what
is not disk->open_mutex (used to be bdev->bd_mutex when the commit was
added) for partition devices, which need that lock for the internal open
for the partition scan, and a recent commit also takes it for
non-partitioned devices, leading to further lockdep splatter.

Fixes: b0140891a8ce ("md: Fix race when creating a new md device.")
Fixes: d62633873590 ("block: support delayed holder registration")
Reported-by: syzbot+fadc0aaf497e6a493b9f@syzkaller.appspotmail.com
Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: syzbot+fadc0aaf497e6a493b9f@syzkaller.appspotmail.com
Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
drivers/md/md.c