[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240609045419.240265-3-mailhol.vincent@wanadoo.fr>
Date: Sun, 9 Jun 2024 13:54:19 +0900
From: Vincent Mailhol <mailhol.vincent@...adoo.fr>
To: Marc Kleine-Budde <mkl@...gutronix.de>,
linux-can@...r.kernel.org
Cc: Thomas Kopp <thomas.kopp@...rochip.com>,
Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>,
"Gustavo A . R . Silva" <gustavoars@...nel.org>,
netdev@...r.kernel.org,
linux-hardening@...r.kernel.org,
Vincent Mailhol <mailhol.vincent@...adoo.fr>,
Kees Cook <kees@...nel.org>
Subject: [PATCH 2/2] can: mcp251xfd: decorate mcp251xfd_rx_ring.obj with __counted_by()
A new __counted_by() attribute was introduced in [1]. It makes the
compiler's sanitizer aware of the actual size of a flexible array
member, allowing for additional runtime checks.
Apply the __counted_by() attribute to the obj flexible array member of
struct mcp251xfd_rx_ring.
Note that the mcp251xfd_rx_ring.obj member is polymorphic: it can be
either of:
* an array of struct mcp251xfd_hw_rx_obj_can
* an array of struct mcp251xfd_hw_rx_obj_canfd
The canfd type was chosen in the declaration by the original author to
reflect the upper bound. We pursue the same logic here: the sanitizer
will only see the accurate size of canfd frames. For classical can
frames, it will see a size bigger than the reality, making the check
incorrect but silent (false negative).
[1] commit dd06e72e68bc ("Compiler Attributes: Add __counted_by macro")
Link: https://git.kernel.org/torvalds/c/dd06e72e68bc
CC: Kees Cook <kees@...nel.org>
Signed-off-by: Vincent Mailhol <mailhol.vincent@...adoo.fr>
---
drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
index 24510b3b8020..b7579fba9457 100644
--- a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
+++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
@@ -565,7 +565,7 @@ struct mcp251xfd_rx_ring {
union mcp251xfd_write_reg_buf uinc_buf;
union mcp251xfd_write_reg_buf uinc_irq_disable_buf;
struct spi_transfer uinc_xfer[MCP251XFD_FIFO_DEPTH];
- struct mcp251xfd_hw_rx_obj_canfd obj[];
+ struct mcp251xfd_hw_rx_obj_canfd obj[] __counted_by(obj_num);
};
struct __packed mcp251xfd_map_buf_nocrc {
--
2.43.0
Powered by blists - more mailing lists