linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: etas_es58x: Replace 0-element raw_msg array
@ 2021-08-18  3:40 Kees Cook
  2021-08-18  5:13 ` Vincent MAILHOL
  0 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2021-08-18  3:40 UTC (permalink / raw)
  To: Wolfgang Grandegger
  Cc: Kees Cook, Marc Kleine-Budde, David S. Miller, Jakub Kicinski,
	Arunachalam Santhanam, Vincent Mailhol, linux-can, netdev,
	linux-kernel, linux-hardening

While raw_msg isn't a fixed size, it does have a maximum size. Adjust the
struct to represent this and avoid the following warning when building
with -Wzero-length-bounds:

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:35: 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:231:6: note: while referencing 'raw_msg'
  231 |   u8 raw_msg[0];
      |      ^~~~~~~

Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Arunachalam Santhanam <arunachalam.santhanam@in.bosch.com>
Cc: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: linux-can@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/can/usb/etas_es58x/es581_4.h  | 2 +-
 drivers/net/can/usb/etas_es58x/es58x_fd.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/etas_es58x/es581_4.h b/drivers/net/can/usb/etas_es58x/es581_4.h
index 4bc60a6df697..af38c4938859 100644
--- a/drivers/net/can/usb/etas_es58x/es581_4.h
+++ b/drivers/net/can/usb/etas_es58x/es581_4.h
@@ -192,7 +192,7 @@ struct es581_4_urb_cmd {
 		struct es581_4_rx_cmd_ret rx_cmd_ret;
 		__le64 timestamp;
 		u8 rx_cmd_ret_u8;
-		u8 raw_msg[0];
+		u8 raw_msg[USHRT_MAX];
 	} __packed;
 
 	__le16 reserved_for_crc16_do_not_use;
diff --git a/drivers/net/can/usb/etas_es58x/es58x_fd.h b/drivers/net/can/usb/etas_es58x/es58x_fd.h
index ee18a87e40c0..e0319b8358ef 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_fd.h
+++ b/drivers/net/can/usb/etas_es58x/es58x_fd.h
@@ -228,7 +228,7 @@ struct es58x_fd_urb_cmd {
 		struct es58x_fd_tx_ack_msg tx_ack_msg;
 		__le64 timestamp;
 		__le32 rx_cmd_ret_le32;
-		u8 raw_msg[0];
+		u8 raw_msg[USHRT_MAX];
 	} __packed;
 
 	__le16 reserved_for_crc16_do_not_use;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-19  0:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18  3:40 [PATCH] can: etas_es58x: Replace 0-element raw_msg array Kees Cook
2021-08-18  5:13 ` Vincent MAILHOL
2021-08-18  6:48   ` Kees Cook
2021-08-18  7:55     ` Vincent MAILHOL
2021-08-18  9:03       ` Kees Cook
2021-08-18  9:33         ` Vincent MAILHOL
2021-08-19  0:02           ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).