summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorLi Nan <linan122@huawei.com>2023-12-19 10:59:42 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-01-26 02:27:28 +0300
commite765363ecfa8888aee715d0d5f369b82a49d85f2 (patch)
treebae35e7ad942b47c219c3055e931d998852444db /block
parenta4529948df7a3670606f005260fd2d636dc688d2 (diff)
downloadlinux-e765363ecfa8888aee715d0d5f369b82a49d85f2.tar.xz
block: add check of 'minors' and 'first_minor' in device_add_disk()
[ Upstream commit 4c434392c4777881d01beada6701eff8c76b43fe ] 'first_minor' represents the starting minor number of disks, and 'minors' represents the number of partitions in the device. Neither of them can be greater than MINORMASK + 1. Commit e338924bd05d ("block: check minor range in device_add_disk()") only added the check of 'first_minor + minors'. However, their sum might be less than MINORMASK but their values are wrong. Complete the checks now. Fixes: e338924bd05d ("block: check minor range in device_add_disk()") Signed-off-by: Li Nan <linan122@huawei.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20231219075942.840255-1-linan666@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/genhd.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/block/genhd.c b/block/genhd.c
index f618e6585e83..ddb17c4adc8a 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -444,7 +444,9 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
DISK_MAX_PARTS);
disk->minors = DISK_MAX_PARTS;
}
- if (disk->first_minor + disk->minors > MINORMASK + 1)
+ if (disk->first_minor > MINORMASK ||
+ disk->minors > MINORMASK + 1 ||
+ disk->first_minor + disk->minors > MINORMASK + 1)
goto out_exit_elevator;
} else {
if (WARN_ON(disk->minors))