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]
Date:   Tue, 21 Sep 2021 11:53:22 +0900
From:   Vincent MAILHOL <mailhol.vincent@...adoo.fr>
To:     Arnd Bergmann <arnd@...nel.org>
Cc:     Wolfgang Grandegger <wg@...ndegger.com>,
        Marc Kleine-Budde <mkl@...gutronix.de>,
        "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Arnd Bergmann <arnd@...db.de>,
        Arunachalam Santhanam <arunachalam.santhanam@...bosch.com>,
        linux-can <linux-can@...r.kernel.org>,
        netdev <netdev@...r.kernel.org>,
        open list <linux-kernel@...r.kernel.org>,
        Kees Cook <keescook@...omium.org>
Subject: Re: [PATCH] can: etas_es58x: avoid -Wzero-length-bounds warning

Hi Arnd,
+CC: Kees Cook

On Mon. 20 Sep 2021 at 21:30, Arnd Bergmann <arnd@...nel.org> wrote:
> From: Arnd Bergmann <arnd@...db.de>
>
> gcc complains when writing into a zero-length array:
>
> drivers/net/can/usb/etas_es58x/es581_4.c: In function 'es581_4_tx_can_msg':
> drivers/net/can/usb/etas_es58x/es581_4.c:374:42: warning: array subscript 65535 is outside the bounds of an interior zero-length array 'u8[0]' {aka 'unsigned char[]'} [-Wzero-length-bounds]
>   374 |         tx_can_msg = (typeof(tx_can_msg))&es581_4_urb_cmd->raw_msg[msg_len];
>       |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In file included from drivers/net/can/usb/etas_es58x/es58x_core.h:21,
>                  from drivers/net/can/usb/etas_es58x/es581_4.c:15:
> drivers/net/can/usb/etas_es58x/es581_4.h:195:20: note: while referencing 'raw_msg'
>   195 |                 u8 raw_msg[0];
>       |                    ^~~~~~~
>   CC [M]  drivers/net/can/usb/etas_es58x/es58x_fd.o
> drivers/net/can/usb/etas_es58x/es58x_fd.c: In function 'es58x_fd_tx_can_msg':
> drivers/net/can/usb/etas_es58x/es58x_fd.c:360:42: warning: array subscript 65535 is outside the bounds of an interior zero-length array 'u8[0]' {aka 'unsigned char[]'} [-Wzero-length-bounds]
>   360 |         tx_can_msg = (typeof(tx_can_msg))&es58x_fd_urb_cmd->raw_msg[msg_len];
>       |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In file included from drivers/net/can/usb/etas_es58x/es58x_core.h:22,
>                  from drivers/net/can/usb/etas_es58x/es58x_fd.c:17:
> drivers/net/can/usb/etas_es58x/es58x_fd.h:222:20: note: while referencing 'raw_msg'
>   222 |                 u8 raw_msg[0];
>       |                    ^~~~~~~
>
> The solution is usually to use a flexible-array member the struct, but
> we can't directly have that inside of a union, nor can it be the only
> member of a struct, so add a dummy struct with another zero-length
> member to get the intended behavior.
>
> If someone has a better workaround, let me know and I can send a new
> patch, as this version is rather ugly.

Actually, there is one. Kees Cook introduced a new macro,
DECLARE_FLEX_ARRAY(), to do this in a more elegant way:
https://lkml.org/lkml/2021/8/27/524

The same series also fixes the warning in the etas_es58x driver:
https://lkml.org/lkml/2021/8/27/523

So we only need to wait for Kees's series to get merged :)


Yours sincerely,
Vincent Mailhol

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ