lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CAPhsuW7FOt7FJ_01i5NgaEoNRG7URAcNdAb=sKVxiMpdK_QfsQ@mail.gmail.com>
Date:   Fri, 8 Sep 2023 13:22:19 -0700
From:   Song Liu <song@...nel.org>
To:     Nigel Croxon <ncroxon@...hat.com>
Cc:     Zhang Shurong <zhang_shurong@...mail.com>, yukuai1@...weicloud.com,
        linux-raid@...r.kernel.org, linux-kernel@...r.kernel.org,
        yukuai3@...wei.com
Subject: Re: [PATCH v2] md: raid1: fix potential OOB in raid1_remove_disk()

On Fri, Sep 8, 2023 at 6:48 AM Nigel Croxon <ncroxon@...hat.com> wrote:
>
>
> On 7/22/23 3:53 AM, Zhang Shurong wrote:
>
> 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@...mail.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)
>
> When compiling this patch.. I get the following error
>
> drivers/md/raid1.c: In function 'raid1_remove_disk':
> drivers/md/raid1.c:1844:9: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
>  1844 |         struct raid1_info *p = conf->mirrors + number;
>       |         ^~~~~~
>
> And that's because the new code was inserted before the struct.
> Here is a fix:
>
>     raid1: fix error: ISO C90 forbids mixed declarations
>
>     There is a compile error when commit is added:
>     md: raid1: fix potential OOB in raid1_remove_disk()
>
>     drivers/md/raid1.c: In function 'raid1_remove_disk':
>     drivers/md/raid1.c:1844:9: error: ISO C90 forbids mixed declarations
>     and code [-Werror=declaration-after-statement]
>      1844 |         struct raid1_info *p = conf->mirrors + number;
>           |         ^~~~~~
>
>     And that's because the new code was inserted before the struct.
>     The change is move the struct command above the new commit.
>
>     Fixes: md: raid1: fix potential OOB in raid1_remove_disk()
>     commit 8b0472b50bcf
>
>     Signed-off-by: Nigel Croxon <ncroxon@...hat.com>

Thanks for catching this! Would you mind sending an official patch for it?

Song

>
> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
> index a5453b126aab..4f1483bb708b 100644
> --- a/drivers/md/raid1.c
> +++ b/drivers/md/raid1.c
> @@ -1846,11 +1846,11 @@ static int raid1_remove_disk(struct mddev *mddev, struct md_rdev *rdev)
>         int err = 0;
>         int number = rdev->raid_disk;
>
> +       struct raid1_info *p = conf->mirrors + number;
> +
>         if (unlikely(number >= conf->raid_disks))
>                 goto abort;
>
> -       struct raid1_info *p = conf->mirrors + number;
> -
>         if (rdev != p->rdev)
>                 p = conf->mirrors + conf->raid_disks + number;
>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ