linux-stable/block/partitions
Ming Lei 5f2f775605 block: unhash blkdev part inode when the part is deleted
v5.11 changes the blkdev lookup mechanism completely since commit
22ae8ce8b8 ("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.

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>
Acked-by: Jens Axboe <axboe@kernel.dk>
2022-12-08 11:23:59 +01:00
..
acorn.c block: declare all partition detection routines in check.h 2020-03-24 07:57:08 -06:00
aix.c block: declare all partition detection routines in check.h 2020-03-24 07:57:08 -06:00
amiga.c block: declare all partition detection routines in check.h 2020-03-24 07:57:08 -06:00
atari.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
atari.h block: declare all partition detection routines in check.h 2020-03-24 07:57:08 -06:00
check.h block: move block layer internals out of include/linux/genhd.h 2020-03-25 09:50:08 -06:00
cmdline.c block: declare all partition detection routines in check.h 2020-03-24 07:57:08 -06:00
core.c block: unhash blkdev part inode when the part is deleted 2022-12-08 11:23:59 +01:00
efi.c partitions/efi: Fix partition name parsing in GUID partition entry 2020-03-08 10:00:09 +01:00
efi.h Merge branch 'efi-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2020-03-30 16:13:08 -07:00
ibm.c partitions/ibm: fix non-DASD devices 2020-10-07 07:55:35 -06:00
karma.c block: remove block/partitions/karma.h 2020-03-24 07:57:08 -06:00
Kconfig treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
ldm.c partitions: msdos: fix one-byte get_unaligned() 2021-07-20 16:05:39 +02:00
ldm.h partitions: msdos: fix one-byte get_unaligned() 2021-07-20 16:05:39 +02:00
mac.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mac.h block: declare all partition detection routines in check.h 2020-03-24 07:57:08 -06:00
Makefile block: merge partition-generic.c and check.c 2020-03-24 07:57:08 -06:00
msdos.c partitions: msdos: fix one-byte get_unaligned() 2021-07-20 16:05:39 +02:00
osf.c block: remove block/partitions/osf.h 2020-03-24 07:57:08 -06:00
sgi.c block: move the *_PARTITION enum out of genhd.h 2020-03-24 07:57:08 -06:00
sun.c block: move the *_PARTITION enum out of genhd.h 2020-03-24 07:57:08 -06:00
sysv68.c block: declare all partition detection routines in check.h 2020-03-24 07:57:08 -06:00
ultrix.c block: declare all partition detection routines in check.h 2020-03-24 07:57:08 -06:00