mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] md: raid1: fix potential OOB in raid1_remove_disk()
@ 2023-07-22  7:53 Zhang Shurong
  2023-07-24  2:11 ` Yu Kuai
       [not found] ` <bd46efce-07ee-4cb3-a5d0-f133a1e79fd9@redhat.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Zhang Shurong @ 2023-07-22  7:53 UTC (permalink / raw)
  To: song, yukuai1; +Cc: linux-raid, linux-kernel, yukuai3, Zhang Shurong

If rddev->raid_disk is greater than mddev->raid_disks, there will be
an out-of-bounds in raid1_remove_disk(). We have already found
similar reports as follows:

1) commit d17f744e883b ("md-raid10: fix KASAN warning")
2) commit 1ebc2cec0b7d ("dm raid: fix KASAN warning in raid5_remove_disk")

Fix this bug by checking whether the "number" variable is
valid.

Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
Changes in v2:
 - Using conf->raid_disks instead of mddev->raid_disks.

 drivers/md/raid1.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index dd25832eb045..80aeee63dfb7 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1829,6 +1829,10 @@ static int raid1_remove_disk(struct mddev *mddev, struct md_rdev *rdev)
 	struct r1conf *conf = mddev->private;
 	int err = 0;
 	int number = rdev->raid_disk;
+
+	if (unlikely(number >= conf->raid_disks))
+		goto abort;
+
 	struct raid1_info *p = conf->mirrors + number;
 
 	if (rdev != p->rdev)
-- 
2.41.0


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

end of thread, other threads:[~2023-09-08 20:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-22  7:53 [PATCH v2] md: raid1: fix potential OOB in raid1_remove_disk() Zhang Shurong
2023-07-24  2:11 ` Yu Kuai
2023-07-29 10:49   ` Song Liu
2023-07-31  1:07     ` Yu Kuai
2023-08-13 16:13       ` Song Liu
     [not found] ` <bd46efce-07ee-4cb3-a5d0-f133a1e79fd9@redhat.com>
2023-09-08 20:22   ` Song Liu

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®