From: Li Nan Date: Tue, 19 Dec 2023 07:59:42 +0000 (+0800) Subject: block: add check of 'minors' and 'first_minor' in device_add_disk() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=4c434392c4777881d01beada6701eff8c76b43fe;p=linux.git block: add check of 'minors' and 'first_minor' in device_add_disk() '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 Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20231219075942.840255-1-linan666@huaweicloud.com Signed-off-by: Jens Axboe --- diff --git a/block/genhd.c b/block/genhd.c index 13db3a7943d8f..d74fb5b4ae681 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -432,7 +432,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))