All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] ixgbe: Fix out-of-bounds warning in ixgbe_host_interface_command()
@ 2021-03-17  6:41 ` Gustavo A. R. Silva
  0 siblings, 0 replies; 14+ messages in thread
From: Gustavo A. R. Silva @ 2021-03-17  6:41 UTC (permalink / raw)
  To: Jesse Brandeburg, Tony Nguyen, David S. Miller, Jakub Kicinski
  Cc: intel-wired-lan, netdev, linux-kernel, Gustavo A. R. Silva,
	linux-hardening

Fix the following out-of-bounds warning by replacing the one-element
array in an anonymous union with a pointer:

  CC [M]  drivers/net/ethernet/intel/ixgbe/ixgbe_common.o
drivers/net/ethernet/intel/ixgbe/ixgbe_common.c: In function ‘ixgbe_host_interface_command’:
drivers/net/ethernet/intel/ixgbe/ixgbe_common.c:3729:13: warning: array subscript 1 is above array bounds of ‘u32[1]’ {aka ‘unsigned int[1]’} [-Warray-bounds]
 3729 |   bp->u32arr[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
      |   ~~~~~~~~~~^~~~
drivers/net/ethernet/intel/ixgbe/ixgbe_common.c:3682:7: note: while referencing ‘u32arr’
 3682 |   u32 u32arr[1];
      |       ^~~~~~

This helps with the ongoing efforts to globally enable -Warray-bounds.

Notice that, the usual approach to fix these sorts of issues is to
replace the one-element array with a flexible-array member. However,
flexible arrays should not be used in unions. That, together with the
fact that the array notation is not being affected in any ways, is why
the pointer approach was chosen in this case.

Link: https://github.com/KSPP/linux/issues/109
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
index 62ddb452f862..bff3dc1af702 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
@@ -3679,7 +3679,7 @@ s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, void *buffer,
 	u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
 	union {
 		struct ixgbe_hic_hdr hdr;
-		u32 u32arr[1];
+		u32 *u32arr;
 	} *bp = buffer;
 	u16 buf_len, dword_len;
 	s32 status;
-- 
2.27.0


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

end of thread, other threads:[~2021-03-17 21:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17  6:41 [PATCH][next] ixgbe: Fix out-of-bounds warning in ixgbe_host_interface_command() Gustavo A. R. Silva
2021-03-17  6:41 ` [Intel-wired-lan] " Gustavo A. R. Silva
2021-03-17 17:11 ` Jann Horn
2021-03-17 17:11   ` [Intel-wired-lan] " Jann Horn
2021-03-17 17:27   ` Gustavo A. R. Silva
2021-03-17 17:27     ` Gustavo A. R. Silva
2021-03-17 18:57     ` Jann Horn
2021-03-17 18:57       ` Jann Horn
2021-03-17 19:04       ` Gustavo A. R. Silva
2021-03-17 19:04         ` Gustavo A. R. Silva
2021-03-17 20:10         ` Jann Horn
2021-03-17 20:10           ` Jann Horn
2021-03-17 19:50           ` Gustavo A. R. Silva
2021-03-17 19:50             ` Gustavo A. R. Silva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.