mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] block: Fix minor range check in device_add_disk()
@ 2023-10-25  8:46 Zhong Jinghua
  2023-10-25 10:06 ` Tetsuo Handa
  0 siblings, 1 reply; 5+ messages in thread
From: Zhong Jinghua @ 2023-10-25  8:46 UTC (permalink / raw)
  To: axboe, penguin-kernel
  Cc: linux-block, linux-kernel, zhongjinghua, yi.zhang, yukuai3

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-30  9:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-25  8:46 [PATCH] block: Fix minor range check in device_add_disk() Zhong Jinghua
2023-10-25 10:06 ` Tetsuo Handa
2023-10-26  8:52   ` zhongjinghua
2023-10-30  9:26     ` Yu Kuai
2023-10-30  9:32       ` zhongjinghua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®