Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH] md/raid1: reject oversized raid_disks values
@ 2026-11-17 23:57 Aibing Chen
  2026-11-18  0:11 ` sashiko-bot
  2026-11-18  8:14 ` [PATCH v2] " Aibing Chen
  0 siblings, 2 replies; 3+ messages in thread
From: Aibing Chen @ 2026-11-17 23:57 UTC (permalink / raw)
  To: Song Liu, Yu Kuai; +Cc: Li Nan, Xiao Ni, linux-raid, linux-kernel

r1buf_pool_alloc() allocates an array of struct resync_pages with
conf->raid_disks * 2 entries.  raid_disks is set from the user through
the SET_ARRAY_INFO ioctl and is unbounded, so a large value makes that
allocation exceed KMALLOC_MAX_SIZE: kmalloc emits a WARN_ON_ONCE_GFP()
splat (syzbot: WARNING in r1buf_pool_alloc) and returns NULL, after
which the resync fails to start.

The same disk count is used to size the mirrors array and the r1bio
pool during setup_conf(), so reject it in raid1_run() before any of
those allocations happen.

Reported-by: syzbot+c0e700c08ee88f60e54d@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c0e700c08ee88f60e54d
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
 drivers/md/raid1.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 894efb50c..875c98552 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -3169,6 +3169,18 @@ static int raid1_run(struct mddev *mddev)
 		return -EIO;
 	}
 
+	/*
+	 * The resync and r1bio pools are sized from raid_disks * 2.  A
+	 * raid_disks value large enough to make those allocations exceed
+	 * KMALLOC_MAX_SIZE would only trigger a kmalloc WARN_ON() when the
+	 * resync starts, see r1buf_pool_alloc(), and the resync would not
+	 * run at all.  Reject such a value before anything is allocated.
+	 */
+	if (mddev->raid_disks <= 0 ||
+	    mddev->raid_disks > KMALLOC_MAX_SIZE /
+				(2 * sizeof(struct resync_pages)))
+		return -EINVAL;
+
 	/*
 	 * copy the already verified devices into our private RAID1
 	 * bookkeeping area. [whatever we allocate in run(),



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

end of thread, other threads:[~2026-11-18  8:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 23:57 [PATCH] md/raid1: reject oversized raid_disks values Aibing Chen
2026-11-18  0:11 ` sashiko-bot
2026-11-18  8:14 ` [PATCH v2] " Aibing Chen

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