Skip to content

Commit

Permalink
mlx4: fix use-after-free in mlx4_en_fold_software_stats()
Browse files Browse the repository at this point in the history
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 <edumazet@google.com>
Reported-and-bisected-by: Jesper Dangaard Brouer <brouer@redhat.com>
Tested-by: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Tariq Toukan <tariqt@mellanox.com>
Cc: Saeed Mahameed <saeedm@dev.mellanox.co.il>
Acked-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Dec 2, 2016
1 parent bd3ad7d commit 7f7bf16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions drivers/net/ethernet/mellanox/mlx4/en_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1809,8 +1809,12 @@ void mlx4_en_stop_port(struct net_device *dev, int detach)

netif_tx_disable(dev);

spin_lock_bh(&priv->stats_lock);
mlx4_en_fold_software_stats(dev);
/* Set port as not active */
priv->port_up = false;
spin_unlock_bh(&priv->stats_lock);

priv->counter_index = MLX4_SINK_COUNTER_INDEX(mdev->dev);

/* Promsicuous mode */
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx4/en_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void mlx4_en_fold_software_stats(struct net_device *dev)
unsigned long packets, bytes;
int i;

if (mlx4_is_master(mdev->dev))
if (!priv->port_up || mlx4_is_master(mdev->dev))
return;

packets = 0;
Expand Down

0 comments on commit 7f7bf16

Please sign in to comment.