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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdXSLBARbtc91F=cWqTdL+UcT4wJbr0_m5+iz_6BXA4Acw@mail.gmail.com>
Date: Thu, 11 Jan 2024 10:05:00 +0100
From: Geert Uytterhoeven <geert@...ux-m68k.org>
To: Prabhakar <prabhakar.csengg@...il.com>
Cc: Vinod Koul <vkoul@...nel.org>, Uwe Kleine-König <u.kleine-koenig@...gutronix.de>, 
	Tudor Ambarus <tudor.ambarus@...aro.org>, Kees Cook <keescook@...omium.org>, 
	dmaengine@...r.kernel.org, linux-kernel@...r.kernel.org, 
	linux-renesas-soc@...r.kernel.org, 
	Claudiu Beznea <claudiu.beznea.uj@...renesas.com>, 
	Lad Prabhakar <prabhakar.mahadev-lad.rj@...renesas.com>
Subject: Re: [PATCH] dmaengine: usb-dmac: Avoid format-overflow warning

Hi Prabhakar,

On Wed, Jan 10, 2024 at 11:23 PM Prabhakar <prabhakar.csengg@...il.com> wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@...renesas.com>
>
> gcc points out that the fix-byte buffer might be too small:
> drivers/dma/sh/usb-dmac.c: In function 'usb_dmac_probe':
> drivers/dma/sh/usb-dmac.c:720:34: warning: '%u' directive writing between 1 and 10 bytes into a region of size 3 [-Wformat-overflow=]
>   720 |         sprintf(pdev_irqname, "ch%u", index);
>       |                                  ^~
> In function 'usb_dmac_chan_probe',
>     inlined from 'usb_dmac_probe' at drivers/dma/sh/usb-dmac.c:814:9:
> drivers/dma/sh/usb-dmac.c:720:31: note: directive argument in the range [0, 4294967294]
>   720 |         sprintf(pdev_irqname, "ch%u", index);
>       |                               ^~~~~~
> drivers/dma/sh/usb-dmac.c:720:9: note: 'sprintf' output between 4 and 13 bytes into a destination of size 5
>   720 |         sprintf(pdev_irqname, "ch%u", index);
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Maximum number of channels for USB-DMAC as per the driver is 1-99 so use
> u8 instead of unsigned int/int for DMAC channel indexing and make the
> pdev_irqname string long enough to avoid the warning.
>
> While at it use scnprintf() instead of sprintf() to make the code more
> robust.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@...renesas.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@...der.be>

One nit below.

> --- a/drivers/dma/sh/usb-dmac.c
> +++ b/drivers/dma/sh/usb-dmac.c

> @@ -768,8 +768,8 @@ static int usb_dmac_probe(struct platform_device *pdev)
>         const enum dma_slave_buswidth widths = USB_DMAC_SLAVE_BUSWIDTH;
>         struct dma_device *engine;
>         struct usb_dmac *dmac;
> -       unsigned int i;
>         int ret;
> +       u8 i;

Personally, I'm not much a fan of making loop counters smaller than
(unsigned) int.  If you do go this way, there are more loops over all
channels still using int.

Gr{oetje,eeting}s,

                        Geert

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

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