From: Yu Kuai <yukuai1@huaweicloud.com>
To: Song Liu <song@kernel.org>, Yu Kuai <yukuai1@huaweicloud.com>
Cc: Zhang Shurong <zhang_shurong@foxmail.com>,
linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org,
"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH v2] md: raid1: fix potential OOB in raid1_remove_disk()
Date: Mon, 31 Jul 2023 09:07:57 +0800 [thread overview]
Message-ID: <52ddb065-e778-53d0-9679-7a6879e8a8e9@huaweicloud.com> (raw)
In-Reply-To: <CAPhsuW6UnqTowo0CZVZXcb_Z=OjV5xFwYqD1O6FO3CLqiKx2DQ@mail.gmail.com>
Hi,
在 2023/07/29 18:49, Song Liu 写道:
> On Mon, Jul 24, 2023 at 10:12 AM Yu Kuai <yukuai1@huaweicloud.com> wrote:
>>
>> 在 2023/07/22 15:53, 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.
>>
>> LGTM
>>
>> Reviewed-by: Yu Kuai <yukuai3@huawei.com>
>>>
>>> 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;
>
> We need err = -EINVAL here.
I think return 0 is right here, so that caller can remove this rdev
from array successfully, this only need to return error for the case
-EBUSY.
Thanks,
Kuai
>
>>> +
>>> struct raid1_info *p = conf->mirrors + number;
>>>
>>> if (rdev != p->rdev)
>>>
>>
> .
>
next prev parent reply other threads:[~2023-07-31 1:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-22 7:53 Zhang Shurong
2023-07-24 2:11 ` Yu Kuai
2023-07-29 10:49 ` Song Liu
2023-07-31 1:07 ` Yu Kuai [this message]
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=52ddb065-e778-53d0-9679-7a6879e8a8e9@huaweicloud.com \
--to=yukuai1@huaweicloud.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=song@kernel.org \
--cc=yukuai3@huawei.com \
--cc=zhang_shurong@foxmail.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 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®