Skip to content

Commit 7f7bf16

Browse files
Eric Dumazetdavem330
authored andcommitted
mlx4: fix use-after-free in mlx4_en_fold_software_stats()
My recent commit to get more precise rx/tx counters in ndo_get_stats64() can lead to crashes at device dismantle, as Jesper found out. We must prevent mlx4_en_fold_software_stats() trying to access tx/rx rings if they are deleted. Fix this by adding a test against priv->port_up in mlx4_en_fold_software_stats() Calling mlx4_en_fold_software_stats() from mlx4_en_stop_port() allows us to eventually broadcast the latest/current counters to rtnetlink monitors. Fixes: 40931b8 ("mlx4: give precise rx/tx bytes/packets counters") Signed-off-by: Eric Dumazet <[email protected]> Reported-and-bisected-by: Jesper Dangaard Brouer <[email protected]> Tested-by: Jesper Dangaard Brouer <[email protected]> Cc: Tariq Toukan <[email protected]> Cc: Saeed Mahameed <[email protected]> Acked-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bd3ad7d commit 7f7bf16

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

drivers/net/ethernet/mellanox/mlx4/en_netdev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,8 +1809,12 @@ void mlx4_en_stop_port(struct net_device *dev, int detach)
18091809

18101810
netif_tx_disable(dev);
18111811

1812+
spin_lock_bh(&priv->stats_lock);
1813+
mlx4_en_fold_software_stats(dev);
18121814
/* Set port as not active */
18131815
priv->port_up = false;
1816+
spin_unlock_bh(&priv->stats_lock);
1817+
18141818
priv->counter_index = MLX4_SINK_COUNTER_INDEX(mdev->dev);
18151819

18161820
/* Promsicuous mode */

drivers/net/ethernet/mellanox/mlx4/en_port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void mlx4_en_fold_software_stats(struct net_device *dev)
154154
unsigned long packets, bytes;
155155
int i;
156156

157-
if (mlx4_is_master(mdev->dev))
157+
if (!priv->port_up || mlx4_is_master(mdev->dev))
158158
return;
159159

160160
packets = 0;

0 commit comments

Comments
 (0)