Messages in this thread Patch in this message | | | From | Zhong Jinghua <> | Subject | [PATCH] block: Fix minor range check in device_add_disk() | Date | Wed, 25 Oct 2023 16:46:21 +0800 |
| |
From: Zhong Jinghua <zhongjinghua@huawei.com>
Checks added in patch: commit e338924bd05d ("block: check minor range in device_add_disk()") ignore the problem of first_minore < 0 and disk->minors < 0.
Fix it by adding first_minore < 0 and disk->minors < 0 check.
Fixes: e338924bd05d ("block: check minor range in device_add_disk()") Signed-off-by: Zhong Jinghua <zhongjinghua@huawei.com> --- block/genhd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/block/genhd.c b/block/genhd.c index 736215e9ddc3..8292a1e265cf 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 > (1U << MINORBITS) || + disk->first_minor + disk->minors > MINORMASK + 1) goto out_exit_elevator; } else { if (WARN_ON(disk->minors)) -- 2.31.1
| |