netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND net-next] alx: fix OOB-read compiler warning
@ 2023-08-21  1:32 GONG, Ruiqi
  2023-08-21  7:03 ` Simon Horman
  2023-08-22 10:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: GONG, Ruiqi @ 2023-08-21  1:32 UTC (permalink / raw)
  To: Chris Snook, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Sabrina Dubroca
  Cc: netdev, linux-kernel, Kees Cook, Gustavo A . R . Silva,
	gongruiqi1

From: "GONG, Ruiqi" <gongruiqi1@huawei.com>

The following message shows up when compiling with W=1:

In function ‘fortify_memcpy_chk’,
    inlined from ‘alx_get_ethtool_stats’ at drivers/net/ethernet/atheros/alx/ethtool.c:297:2:
./include/linux/fortify-string.h:592:4: error: call to ‘__read_overflow2_field’
declared with attribute warning: detected read beyond size of field (2nd parameter);
maybe use struct_group()? [-Werror=attribute-warning]
  592 |    __read_overflow2_field(q_size_field, size);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to get alx stats altogether, alx_get_ethtool_stats() reads
beyond hw->stats.rx_ok. Fix this warning by directly copying hw->stats,
and refactor the unnecessarily complicated BUILD_BUG_ON btw.

Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
---

RESEND: forget to cc netdev mail list

 drivers/net/ethernet/atheros/alx/ethtool.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/atheros/alx/ethtool.c b/drivers/net/ethernet/atheros/alx/ethtool.c
index b716adacd815..7f6b69a52367 100644
--- a/drivers/net/ethernet/atheros/alx/ethtool.c
+++ b/drivers/net/ethernet/atheros/alx/ethtool.c
@@ -292,9 +292,8 @@ static void alx_get_ethtool_stats(struct net_device *netdev,
 	spin_lock(&alx->stats_lock);
 
 	alx_update_hw_stats(hw);
-	BUILD_BUG_ON(sizeof(hw->stats) - offsetof(struct alx_hw_stats, rx_ok) <
-		     ALX_NUM_STATS * sizeof(u64));
-	memcpy(data, &hw->stats.rx_ok, ALX_NUM_STATS * sizeof(u64));
+	BUILD_BUG_ON(sizeof(hw->stats) != ALX_NUM_STATS * sizeof(u64));
+	memcpy(data, &hw->stats, sizeof(hw->stats));
 
 	spin_unlock(&alx->stats_lock);
 }
-- 
2.25.1


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

* Re: [PATCH RESEND net-next] alx: fix OOB-read compiler warning
  2023-08-21  1:32 [PATCH RESEND net-next] alx: fix OOB-read compiler warning GONG, Ruiqi
@ 2023-08-21  7:03 ` Simon Horman
  2023-08-22 10:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2023-08-21  7:03 UTC (permalink / raw)
  To: GONG, Ruiqi
  Cc: Chris Snook, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Sabrina Dubroca, netdev, linux-kernel, Kees Cook,
	Gustavo A . R . Silva, gongruiqi1

On Mon, Aug 21, 2023 at 09:32:18AM +0800, GONG, Ruiqi wrote:
> From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
> 
> The following message shows up when compiling with W=1:
> 
> In function ‘fortify_memcpy_chk’,
>     inlined from ‘alx_get_ethtool_stats’ at drivers/net/ethernet/atheros/alx/ethtool.c:297:2:
> ./include/linux/fortify-string.h:592:4: error: call to ‘__read_overflow2_field’
> declared with attribute warning: detected read beyond size of field (2nd parameter);
> maybe use struct_group()? [-Werror=attribute-warning]
>   592 |    __read_overflow2_field(q_size_field, size);
>       |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> In order to get alx stats altogether, alx_get_ethtool_stats() reads
> beyond hw->stats.rx_ok. Fix this warning by directly copying hw->stats,
> and refactor the unnecessarily complicated BUILD_BUG_ON btw.
> 
> Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>

Reviewed-by: Simon Horman <horms@kernel.org>


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

* Re: [PATCH RESEND net-next] alx: fix OOB-read compiler warning
  2023-08-21  1:32 [PATCH RESEND net-next] alx: fix OOB-read compiler warning GONG, Ruiqi
  2023-08-21  7:03 ` Simon Horman
@ 2023-08-22 10:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-22 10:50 UTC (permalink / raw)
  To: GONG, Ruiqi
  Cc: chris.snook, davem, edumazet, kuba, pabeni, sd, netdev,
	linux-kernel, keescook, gustavoars, gongruiqi1

Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Mon, 21 Aug 2023 09:32:18 +0800 you wrote:
> From: "GONG, Ruiqi" <gongruiqi1@huawei.com>
> 
> The following message shows up when compiling with W=1:
> 
> In function ‘fortify_memcpy_chk’,
>     inlined from ‘alx_get_ethtool_stats’ at drivers/net/ethernet/atheros/alx/ethtool.c:297:2:
> ./include/linux/fortify-string.h:592:4: error: call to ‘__read_overflow2_field’
> declared with attribute warning: detected read beyond size of field (2nd parameter);
> maybe use struct_group()? [-Werror=attribute-warning]
>   592 |    __read_overflow2_field(q_size_field, size);
>       |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> [...]

Here is the summary with links:
  - [RESEND,net-next] alx: fix OOB-read compiler warning
    https://git.kernel.org/netdev/net-next/c/3a198c95c95d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-08-22 10:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-21  1:32 [PATCH RESEND net-next] alx: fix OOB-read compiler warning GONG, Ruiqi
2023-08-21  7:03 ` Simon Horman
2023-08-22 10:50 ` patchwork-bot+netdevbpf

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).