Thread (3 messages) 3 messages, 3 authors, 2023-09-12

Re: [PATCH AUTOSEL 4.14 2/3] md: raid1: fix potential OOB in raid1_remove_disk()

From: Song Liu <song@kernel.org>
Date: 2023-09-12 02:28:40
Also in: lkml, stable

On Mon, Sep 11, 2023 at 2:49 AM Pavel Machek [off-list ref] wrote:
Hi!
quoted
From: Zhang Shurong <redacted>

[ Upstream commit 8b0472b50bcf0f19a5119b00a53b63579c8e1e4d ]

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.
quoted
+++ b/drivers/md/raid1.c
@@ -1775,6 +1775,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)
Wow. Mixing declarations and code. I'm pretty sure that's not ok
according to our coding style, and I'd be actually surprised if all
our compiler configurations allowed this.
We have a fix queued for this:

https://git.kernel.org/pub/scm/linux/kernel/git/song/md.git/commit/?h=md-fixes&id=df203da47f4428bc286fc99318936416253a321c

Thanks,
Song
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help