[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210818062657.6hvn75kf5o5cgey2@pengutronix.de>
Date: Wed, 18 Aug 2021 08:26:57 +0200
From: Marc Kleine-Budde <mkl@...gutronix.de>
To: Kees Cook <keescook@...omium.org>
Cc: linux-kernel@...r.kernel.org,
Wolfgang Grandegger <wg@...ndegger.com>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>, linux-can@...r.kernel.org,
netdev@...r.kernel.org,
"Gustavo A. R. Silva" <gustavoars@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-wireless@...r.kernel.org, dri-devel@...ts.freedesktop.org,
linux-staging@...ts.linux.dev, linux-block@...r.kernel.org,
linux-kbuild@...r.kernel.org, clang-built-linux@...glegroups.com,
Rasmus Villemoes <linux@...musvillemoes.dk>,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH v2 59/63] can: flexcan: Use struct_group() to zero struct
flexcan_regs regions
On 17.08.2021 23:05:29, Kees Cook wrote:
> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memset(), avoid intentionally writing across
> neighboring fields.
>
> Add struct_group() to mark both regions of struct flexcan_regs that get
> initialized to zero. Avoid the future warnings:
>
> In function 'fortify_memset_chk',
> inlined from 'memset_io' at ./include/asm-generic/io.h:1169:2,
> inlined from 'flexcan_ram_init' at drivers/net/can/flexcan.c:1403:2:
> ./include/linux/fortify-string.h:199:4: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
> 199 | __write_overflow_field(p_size_field, size);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In function 'fortify_memset_chk',
> inlined from 'memset_io' at ./include/asm-generic/io.h:1169:2,
> inlined from 'flexcan_ram_init' at drivers/net/can/flexcan.c:1408:3:
> ./include/linux/fortify-string.h:199:4: warning: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning]
> 199 | __write_overflow_field(p_size_field, size);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Cc: Wolfgang Grandegger <wg@...ndegger.com>
> Cc: Marc Kleine-Budde <mkl@...gutronix.de>
> Cc: "David S. Miller" <davem@...emloft.net>
> Cc: Jakub Kicinski <kuba@...nel.org>
> Cc: linux-can@...r.kernel.org
> Cc: netdev@...r.kernel.org
> Signed-off-by: Kees Cook <keescook@...omium.org>
Acked-by: Marc Kleine-Budde <mkl@...gutronix.de>
> - memset_io(®s->mb[0][0], 0,
> - offsetof(struct flexcan_regs, rx_smb1[3]) -
> - offsetof(struct flexcan_regs, mb[0][0]) + 0x4);
> + memset_io(®s->init, 0, sizeof(regs->init));
This even makes the code more readable! \o/
> if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
> - memset_io(®s->tx_smb_fd[0], 0,
> - offsetof(struct flexcan_regs, rx_smb1_fd[17]) -
> - offsetof(struct flexcan_regs, tx_smb_fd[0]) + 0x4);
> + memset_io(®s->init_fd, 0, sizeof(regs->init_fd));
>
> reg_ctrl2 &= ~FLEXCAN_CTRL2_WRMFRZ;
> priv->write(reg_ctrl2, ®s->ctrl2);
regards,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists