* [PATCH][next] gve: Use size_add() in call to struct_size()
@ 2023-09-15 18:17 Gustavo A. R. Silva
2023-09-15 18:44 ` Kees Cook
2023-09-17 18:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-15 18:17 UTC (permalink / raw)
To: Jeroen de Borst, Praveen Kaligineedi, Shailend Chand,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Gustavo A. R. Silva
Cc: netdev, linux-kernel, Gustavo A. R. Silva, linux-hardening
If, for any reason, `tx_stats_num + rx_stats_num` wraps around, the
protection that struct_size() adds against potential integer overflows
is defeated. Fix this by hardening call to struct_size() with size_add().
Fixes: 691f4077d560 ("gve: Replace zero-length array with flexible-array member")
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/ethernet/google/gve/gve_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c
index 5704b5f57cd0..83b09dcfafc4 100644
--- a/drivers/net/ethernet/google/gve/gve_main.c
+++ b/drivers/net/ethernet/google/gve/gve_main.c
@@ -190,7 +190,7 @@ static int gve_alloc_stats_report(struct gve_priv *priv)
rx_stats_num = (GVE_RX_STATS_REPORT_NUM + NIC_RX_STATS_REPORT_NUM) *
priv->rx_cfg.num_queues;
priv->stats_report_len = struct_size(priv->stats_report, stats,
- tx_stats_num + rx_stats_num);
+ size_add(tx_stats_num, rx_stats_num));
priv->stats_report =
dma_alloc_coherent(&priv->pdev->dev, priv->stats_report_len,
&priv->stats_report_bus, GFP_KERNEL);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH][next] gve: Use size_add() in call to struct_size()
2023-09-15 18:17 [PATCH][next] gve: Use size_add() in call to struct_size() Gustavo A. R. Silva
@ 2023-09-15 18:44 ` Kees Cook
2023-09-17 18:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-09-15 18:44 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Jeroen de Borst, Praveen Kaligineedi, Shailend Chand,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel, linux-hardening
On Fri, Sep 15, 2023 at 12:17:49PM -0600, Gustavo A. R. Silva wrote:
> If, for any reason, `tx_stats_num + rx_stats_num` wraps around, the
> protection that struct_size() adds against potential integer overflows
> is defeated. Fix this by hardening call to struct_size() with size_add().
>
> Fixes: 691f4077d560 ("gve: Replace zero-length array with flexible-array member")
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks, yes, this will maintain SIZE_MAX saturation if it happens.
Reviewed-by: Kees Cook <keescook@chromium.org>
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH][next] gve: Use size_add() in call to struct_size()
2023-09-15 18:17 [PATCH][next] gve: Use size_add() in call to struct_size() Gustavo A. R. Silva
2023-09-15 18:44 ` Kees Cook
@ 2023-09-17 18:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-09-17 18:00 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: jeroendb, pkaligineedi, shailend, davem, edumazet, kuba, pabeni,
netdev, linux-kernel, linux-hardening
Hello:
This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Fri, 15 Sep 2023 12:17:49 -0600 you wrote:
> If, for any reason, `tx_stats_num + rx_stats_num` wraps around, the
> protection that struct_size() adds against potential integer overflows
> is defeated. Fix this by hardening call to struct_size() with size_add().
>
> Fixes: 691f4077d560 ("gve: Replace zero-length array with flexible-array member")
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>
> [...]
Here is the summary with links:
- [next] gve: Use size_add() in call to struct_size()
https://git.kernel.org/netdev/net-next/c/d692873cbe86
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-09-17 18:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-15 18:17 [PATCH][next] gve: Use size_add() in call to struct_size() Gustavo A. R. Silva
2023-09-15 18:44 ` Kees Cook
2023-09-17 18:00 ` 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).