diff options
author | Zhang Shurong <zhang_shurong@foxmail.com> | 2023-07-22 10:53:53 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-09-23 12:14:26 +0300 |
commit | 4bdb92eaf645e312975357adc3c4e9523b6e67f1 (patch) | |
tree | 08dfc606eab732034192aa259b87befd42b5198e /drivers/md | |
parent | 617c10c6ee33578652b4cb4f81e652db554e96c1 (diff) | |
download | linux-4bdb92eaf645e312975357adc3c4e9523b6e67f1.tar.xz |
md: raid1: fix potential OOB in raid1_remove_disk()
[ 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.
Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/tencent_0D24426FAC6A21B69AC0C03CE4143A508F09@qq.com
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/raid1.c | 4 |
1 files changed, 4 insertions, 0 deletions
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) |