All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Shurong <zhang_shurong@foxmail.com>
To: song@kernel.org, yukuai1@huaweicloud.com
Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
	yukuai3@huawei.com, Zhang Shurong <zhang_shurong@foxmail.com>
Subject: [PATCH v2] md: raid1: fix potential OOB in raid1_remove_disk()
Date: Sat, 22 Jul 2023 15:53:53 +0800	[thread overview]
Message-ID: <tencent_0D24426FAC6A21B69AC0C03CE4143A508F09@qq.com> (raw)

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


             reply	other threads:[~2023-07-22  7:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-22  7:53 Zhang Shurong [this message]
2023-07-24  2:11 ` [PATCH v2] md: raid1: fix potential OOB in raid1_remove_disk() 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_0D24426FAC6A21B69AC0C03CE4143A508F09@qq.com \
    --to=zhang_shurong@foxmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    --cc=yukuai1@huaweicloud.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.