* [PATCH 5.10.y stable v2] block: unhash blkdev part inode when the part is deleted
@ 2022-12-05 13:27 Ming Lei
2022-12-05 13:29 ` kernel test robot
2022-12-05 15:08 ` Greg Kroah-Hartman
0 siblings, 2 replies; 5+ messages in thread
From: Ming Lei @ 2022-12-05 13:27 UTC (permalink / raw)
To: Greg Kroah-Hartman, stable
Cc: Jens Axboe, linux-block, Ming Lei, Shiwei Cui, Christoph Hellwig,
Jan Kara
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.
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>
---
V2:
- fix one typo and Shiwei's email format
block/partitions/core.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/block/partitions/core.c b/block/partitions/core.c
index a02e22411594..e3d61ec4a5a6 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -329,6 +329,7 @@ void delete_partition(struct hd_struct *part)
struct gendisk *disk = part_to_disk(part);
struct disk_part_tbl *ptbl =
rcu_dereference_protected(disk->part_tbl, 1);
+ struct block_device *bdev;
/*
* ->part_tbl is referenced in this part's release handler, so
@@ -346,6 +347,12 @@ void delete_partition(struct hd_struct *part)
* "in-use" until we really free the gendisk.
*/
blk_invalidate_devt(part_devt(part));
+
+ bdev = bdget_part(part);
+ if (bdev) {
+ remove_inode_hash(bdev->bd_inode);
+ bdput(bdev);
+ }
percpu_ref_kill(&part->ref);
}
--
2.37.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 5.10.y stable v2] block: unhash blkdev part inode when the part is deleted
2022-12-05 13:27 [PATCH 5.10.y stable v2] block: unhash blkdev part inode when the part is deleted Ming Lei
@ 2022-12-05 13:29 ` kernel test robot
2022-12-05 15:08 ` Greg Kroah-Hartman
1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-12-05 13:29 UTC (permalink / raw)
To: Ming Lei; +Cc: stable, oe-kbuild-all
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
Rule: 'Cc: stable@vger.kernel.org' or 'commit <sha1> upstream.'
Subject: [PATCH 5.10.y stable v2] block: unhash blkdev part inode when the part is deleted
Link: https://lore.kernel.org/stable/20221205132739.844399-1-ming.lei%40redhat.com
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 5.10.y stable v2] block: unhash blkdev part inode when the part is deleted
2022-12-05 13:27 [PATCH 5.10.y stable v2] block: unhash blkdev part inode when the part is deleted Ming Lei
2022-12-05 13:29 ` kernel test robot
@ 2022-12-05 15:08 ` Greg Kroah-Hartman
2022-12-05 15:19 ` Jens Axboe
1 sibling, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2022-12-05 15:08 UTC (permalink / raw)
To: Ming Lei
Cc: stable, Jens Axboe, linux-block, Shiwei Cui, Christoph Hellwig,
Jan Kara
On Mon, Dec 05, 2022 at 09:27:39PM +0800, Ming Lei wrote:
> 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.
>
> 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>
> ---
> V2:
> - fix one typo and Shiwei's email format
>
> block/partitions/core.c | 7 +++++++
I need an ack from the block maintainers/developers to be able to take
this.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 5.10.y stable v2] block: unhash blkdev part inode when the part is deleted
2022-12-05 15:08 ` Greg Kroah-Hartman
@ 2022-12-05 15:19 ` Jens Axboe
2022-12-05 16:36 ` Greg Kroah-Hartman
0 siblings, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2022-12-05 15:19 UTC (permalink / raw)
To: Greg Kroah-Hartman, Ming Lei
Cc: stable, linux-block, Shiwei Cui, Christoph Hellwig, Jan Kara
On 12/5/22 8:08 AM, Greg Kroah-Hartman wrote:
> On Mon, Dec 05, 2022 at 09:27:39PM +0800, Ming Lei wrote:
>> 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.
>>
>> 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>
>> ---
>> V2:
>> - fix one typo and Shiwei's email format
>>
>> block/partitions/core.c | 7 +++++++
>
> I need an ack from the block maintainers/developers to be able to take
> this.
Acked-by: Jens Axboe <axboe@kernel.dk>
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 5.10.y stable v2] block: unhash blkdev part inode when the part is deleted
2022-12-05 15:19 ` Jens Axboe
@ 2022-12-05 16:36 ` Greg Kroah-Hartman
0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2022-12-05 16:36 UTC (permalink / raw)
To: Jens Axboe
Cc: Ming Lei, stable, linux-block, Shiwei Cui, Christoph Hellwig,
Jan Kara
On Mon, Dec 05, 2022 at 08:19:23AM -0700, Jens Axboe wrote:
> On 12/5/22 8:08 AM, Greg Kroah-Hartman wrote:
> > On Mon, Dec 05, 2022 at 09:27:39PM +0800, Ming Lei wrote:
> >> 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.
> >>
> >> 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>
> >> ---
> >> V2:
> >> - fix one typo and Shiwei's email format
> >>
> >> block/partitions/core.c | 7 +++++++
> >
> > I need an ack from the block maintainers/developers to be able to take
> > this.
>
> Acked-by: Jens Axboe <axboe@kernel.dk>
Thanks, now queued up for 5.10.y
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-12-05 16:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-05 13:27 [PATCH 5.10.y stable v2] block: unhash blkdev part inode when the part is deleted Ming Lei
2022-12-05 13:29 ` kernel test robot
2022-12-05 15:08 ` Greg Kroah-Hartman
2022-12-05 15:19 ` Jens Axboe
2022-12-05 16:36 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox