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>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAMuHMdWwj6t6Pw==HG+jHC8y6rooWROuQjxJZNUwcXjimai8Pg@mail.gmail.com>
Date:   Tue, 20 Nov 2018 09:17:26 +0100
From:   Geert Uytterhoeven <geert@...ux-m68k.org>
To:     huijin.park@...sung.com
Cc:     Boris Brezillon <boris.brezillon@...tlin.com>,
        Marek Vasut <marek.vasut@...il.com>,
        MTD Maling List <linux-mtd@...ts.infradead.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        bbanghj.park@...il.com
Subject: Re: [PATCH v2] mtd: spi-nor: cast to u64 to avoid uint overflows

Hi Huijin,

On Thu, Nov 15, 2018 at 6:08 AM Huijin Park <huijin.park@...sung.com> wrote:
> From: "huijin.park" <huijin.park@...sung.com>
>
> The "params->size" is defined as "u64".
> And "info->sector_size" and "info->n_sectors" are defined as
> unsigned int and u16.
> Thus, u64 data might have strange data(loss data) if the result
> overflows an unsigned int.
> This patch casts "info->sector_size" and "info->n_sectors" to an u64.
>
> Signed-off-by: huijin.park <huijin.park@...sung.com>
> ---
>  drivers/mtd/spi-nor/spi-nor.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index d9c368c..527f281 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -2459,7 +2459,7 @@ static int spi_nor_init_params(struct spi_nor *nor,
>         memset(params, 0, sizeof(*params));
>
>         /* Set SPI NOR sizes. */
> -       params->size = info->sector_size * info->n_sectors;
> +       params->size = (u64)info->sector_size * (u64)info->n_sectors;

Adding the cast to only the first operand should be sufficient, and may lead
to faster code, as only a 64x16 multiplication needs to be done, instead of
a 64x64.

>         params->page_size = info->page_size;
>
>         /* (Fast) Read settings. */

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@...ux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ