linux-stable/block
Ming Lei bea54ce061 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.

Backported from the following 5.10.y commit:

5f2f775605 ("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>
2023-01-18 09:26:05 +01:00
..
partitions partitions/aix: fix usage of uninitialized lv_info and lvname structures 2018-09-19 22:43:44 +02:00
badblocks.c
bfq-cgroup.c block, bfq: fix overwrite of bfq_group pointer in bfq_find_set_group() 2020-04-02 16:34:15 +02:00
bfq-iosched.c block, bfq: protect 'bfqd->queued' by 'bfqd->lock' 2022-11-10 15:47:22 +01:00
bfq-iosched.h
bfq-wf2q.c block, bfq: correctly charge and reset entity service in all cases 2018-11-13 11:14:55 -08:00
bio-integrity.c block: bio-integrity: Advance seed correctly for larger interval sizes 2022-02-08 18:16:28 +01:00
bio.c block-map: add __GFP_ZERO flag for alloc_page in function bio_copy_kern 2022-06-06 08:20:57 +02:00
blk-cgroup.c blk-cgroup: Pre-allocate tree node on blkg_conf_prep 2020-11-10 10:29:05 +01:00
blk-core.c block: ensure bdi->io_pages is always initialized 2020-09-12 13:39:11 +02:00
blk-exec.c
blk-flush.c blk-mq: fix a hung issue when fsync 2019-02-20 10:20:44 +01:00
blk-integrity.c
blk-ioc.c block: Fix use-after-free issue accessing struct io_cq 2020-04-24 08:00:28 +02:00
blk-lib.c block: fix infinite loop if the device loses discard capability 2018-12-29 13:39:07 +01:00
blk-map.c block: fix memleak when __blk_rq_map_user_iov() is failed 2020-01-12 12:12:00 +01:00
blk-merge.c block: don't use bio->bi_vcnt to figure out segment number 2020-01-27 14:46:19 +01:00
blk-mq-cpumap.c blk-mq: don't keep offline CPUs mapped to hctx 0 2018-04-19 08:56:20 +02:00
blk-mq-debugfs.c blk-mq-debugfs: don't allow write on attributes with seq_operations set 2018-04-26 11:02:11 +02:00
blk-mq-debugfs.h
blk-mq-pci.c
blk-mq-rdma.c
blk-mq-sched.c blk-mq: only attempt to merge bio if there is rq in sw queue 2018-09-26 08:38:13 +02:00
blk-mq-sched.h
blk-mq-sysfs.c blk-mq: make sure that line break can be printed 2019-12-17 20:39:59 +01:00
blk-mq-tag.c blk-mq: Allow blocking queue tag iter callbacks 2020-04-13 10:34:23 +02:00
blk-mq-tag.h
blk-mq-virtio.c
blk-mq.c blk-mq: Swap two calls in blk_mq_exit_queue() 2021-05-22 10:57:40 +02:00
blk-mq.h blk-mq: fix sysfs inflight counter 2018-06-21 04:02:49 +09:00
blk-settings.c blk-settings: align max_sectors on "logical_block_size" boundary 2021-03-03 18:22:50 +01:00
blk-softirq.c
blk-stat.c
blk-stat.h
blk-sysfs.c blk-mq: move cancel of requeue_work to the front of blk_exit_queue 2019-10-05 12:47:37 +02:00
blk-tag.c
blk-throttle.c blk-throttle: fix UAF by deleteing timer in blk_throtl_exit() 2021-09-26 13:37:30 +02:00
blk-timeout.c
blk-wbt.c
blk-wbt.h
blk-zoned.c blk-zoned: allow BLKREPORTZONE without CAP_SYS_ADMIN 2021-09-22 11:45:24 +02:00
blk.h block: drain queue before waiting for q_usage_counter becoming zero 2018-03-03 10:24:35 +01:00
bounce.c
bsg-lib.c
bsg.c
cfq-iosched.c cfq: Suppress compiler warnings about comparisons 2018-09-15 09:45:31 +02:00
cmdline-parser.c
compat_ioctl.c block/compat_ioctl: fix range check in BLKGETSIZE 2022-04-27 13:15:31 +02:00
deadline-iosched.c
elevator.c elevator: lookup mq vs non-mq elevators 2018-12-21 14:13:10 +01:00
genhd.c block: fix use-after-free in disk_part_iter_next 2021-01-17 13:59:01 +01:00
ioctl.c
ioprio.c block: fix ioprio_get(IOPRIO_WHO_PGRP) vs setuid(2) 2021-12-14 10:16:55 +01:00
Kconfig
Kconfig.iosched
kyber-iosched.c block: kyber: fix domain token leak during requeue 2018-03-08 22:41:05 -08:00
Makefile
mq-deadline.c
noop-iosched.c
opal_proto.h
partition-generic.c block: unhash blkdev part inode when the part is deleted 2023-01-18 09:26:05 +01:00
scsi_ioctl.c
sed-opal.c block: sed-opal: kmalloc the cmd/resp buffers 2022-11-25 17:36:49 +01:00
t10-pi.c