]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
block: add check of 'minors' and 'first_minor' in device_add_disk()
authorLi Nan <linan122@huawei.com>
Tue, 19 Dec 2023 07:59:42 +0000 (15:59 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jan 2024 22:52:39 +0000 (14:52 -0800)
[ 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>
block/genhd.c

index 578c09077946008a1562ac39accb5a275742c09c..4d28f1d5f9b0e0bd0841ca6b260ed0b7e8c7f15b 100644 (file)
@@ -421,7 +421,9 @@ int 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)
                        return -EINVAL;
        } else {
                if (WARN_ON(disk->minors))