summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2022-12-13 15:16:27 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-01-18 09:26:05 +0100
commitbea54ce061c8ff28ce7727f3a048f6ffd9267e0f (patch)
treec5a91231b65164183a6969ca393b09d33b1a5ab5
parentc23105673228c349739e958fa33955ed8faddcaf (diff)
downloadlinux-stable-bea54ce061c8ff28ce7727f3a048f6ffd9267e0f.tar.gz
linux-stable-bea54ce061c8ff28ce7727f3a048f6ffd9267e0f.tar.bz2
linux-stable-bea54ce061c8ff28ce7727f3a048f6ffd9267e0f.zip
block: unhash blkdev part inode when the part is deleted
v5.11 changes the blkdev lookup mechanism completely since commit 22ae8ce8b892 ("block: simplify bdev/disk lookup in blkdev_get"), and small part of the change is to unhash part bdev inode when deleting partition. Turns out this kind of change does fix one nasty issue in case of BLOCK_EXT_MAJOR: 1) when one partition is deleted & closed, disk_put_part() is always called before bdput(bdev), see blkdev_put(); so the part's devt can be freed & re-used before the inode is dropped 2) then new partition with same devt can be created just before the inode in 1) is dropped, then the old inode/bdev structurein 1) is re-used for this new partition, this way causes use-after-free and kernel panic. It isn't possible to backport the whole big patchset of "merge struct block_device and struct hd_struct v4" for addressing this issue. https://lore.kernel.org/linux-block/20201128161510.347752-1-hch@lst.de/ So fixes it by unhashing part bdev in delete_partition(), and this way is actually aligned with v5.11+'s behavior. Backported from the following 5.10.y commit: 5f2f77560591 ("block: unhash blkdev part inode when the part is deleted") Reported-by: Shiwei Cui <cuishw@inspur.com> Tested-by: Shiwei Cui <cuishw@inspur.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Jan Kara <jack@suse.cz> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--block/partition-generic.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/block/partition-generic.c b/block/partition-generic.c
index db57cced9b98..68bd04d044b9 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -270,6 +270,7 @@ void delete_partition(struct gendisk *disk, int partno)
struct disk_part_tbl *ptbl =
rcu_dereference_protected(disk->part_tbl, 1);
struct hd_struct *part;
+ struct block_device *bdev;
if (partno >= ptbl->len)
return;
@@ -283,6 +284,11 @@ void delete_partition(struct gendisk *disk, int partno)
kobject_put(part->holder_dir);
device_del(part_to_dev(part));
+ bdev = bdget(part_devt(part));
+ if (bdev) {
+ remove_inode_hash(bdev->bd_inode);
+ bdput(bdev);
+ }
hd_struct_kill(part);
}