diff options
author | Li Lingfeng <lilingfeng3@huawei.com> | 2024-01-18 21:04:01 +0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-01-31 16:19:12 -0800 |
commit | 1539adf760c34ddb590c4b6abd44d567db2aff45 (patch) | |
tree | 7541d2e61443bda6ee7dce44a7c9fe0a1badb07a /block | |
parent | 902a4aab0e0439c8ceb4a223e15a08f033bbdf7b (diff) | |
download | linux-stable-1539adf760c34ddb590c4b6abd44d567db2aff45.tar.gz linux-stable-1539adf760c34ddb590c4b6abd44d567db2aff45.tar.bz2 linux-stable-1539adf760c34ddb590c4b6abd44d567db2aff45.zip |
block: Move checking GENHD_FL_NO_PART to bdev_add_partition()
[ Upstream commit 7777f47f2ea64efd1016262e7b59fab34adfb869 ]
Commit 1a721de8489f ("block: don't add or resize partition on the disk
with GENHD_FL_NO_PART") prevented all operations about partitions on disks
with GENHD_FL_NO_PART in blkpg_do_ioctl() since they are meaningless.
However, it changed error code in some scenarios. So move checking
GENHD_FL_NO_PART to bdev_add_partition() to eliminate impact.
Fixes: 1a721de8489f ("block: don't add or resize partition on the disk with GENHD_FL_NO_PART")
Reported-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
Closes: https://lore.kernel.org/all/CAOYeF9VsmqKMcQjo1k6YkGNujwN-nzfxY17N3F-CMikE1tYp+w@mail.gmail.com/
Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20240118130401.792757-1-lilingfeng@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'block')
-rw-r--r-- | block/ioctl.c | 2 | ||||
-rw-r--r-- | block/partitions/core.c | 5 |
2 files changed, 5 insertions, 2 deletions
diff --git a/block/ioctl.c b/block/ioctl.c index a74ef911e279..d1d8e8391279 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -20,8 +20,6 @@ static int blkpg_do_ioctl(struct block_device *bdev, struct blkpg_partition p; sector_t start, length; - if (disk->flags & GENHD_FL_NO_PART) - return -EINVAL; if (!capable(CAP_SYS_ADMIN)) return -EACCES; if (copy_from_user(&p, upart, sizeof(struct blkpg_partition))) diff --git a/block/partitions/core.c b/block/partitions/core.c index e137a87f4db0..e58c8b50350b 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -458,6 +458,11 @@ int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, goto out; } + if (disk->flags & GENHD_FL_NO_PART) { + ret = -EINVAL; + goto out; + } + if (partition_overlaps(disk, start, length, -1)) { ret = -EBUSY; goto out; |