lkml.org 
[lkml]   [2023]   [Oct]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] block: Fix minor range check in device_add_disk()
Date
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
\
 
 \ /
  Last update: 2023-10-25 10:42    [W:0.092 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site