[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231025084621.2338604-1-zhongjinghua@huaweicloud.com>
Date: Wed, 25 Oct 2023 16:46:21 +0800
From: Zhong Jinghua <zhongjinghua@...weicloud.com>
To: axboe@...nel.dk, penguin-kernel@...ove.sakura.ne.jp
Cc: linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
zhongjinghua@...wei.com, yi.zhang@...wei.com, yukuai3@...wei.com
Subject: [PATCH] block: Fix minor range check in device_add_disk()
From: Zhong Jinghua <zhongjinghua@...wei.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@...wei.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
Powered by blists - more mailing lists