Skip to content

Commit d692873

Browse files
GustavoARSilvadavem330
authored andcommitted
gve: Use size_add() in call to struct_size()
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: 691f407 ("gve: Replace zero-length array with flexible-array member") Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ebdada9 commit d692873

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/net/ethernet/google/gve/gve_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static int gve_alloc_stats_report(struct gve_priv *priv)
190190
rx_stats_num = (GVE_RX_STATS_REPORT_NUM + NIC_RX_STATS_REPORT_NUM) *
191191
priv->rx_cfg.num_queues;
192192
priv->stats_report_len = struct_size(priv->stats_report, stats,
193-
tx_stats_num + rx_stats_num);
193+
size_add(tx_stats_num, rx_stats_num));
194194
priv->stats_report =
195195
dma_alloc_coherent(&priv->pdev->dev, priv->stats_report_len,
196196
&priv->stats_report_bus, GFP_KERNEL);

0 commit comments

Comments
 (0)