All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Saeed Mahameed <saeedm@dev.mellanox.co.il>,
	David Miller <davem@davemloft.net>,
	netdev <netdev@vger.kernel.org>,
	Tariq Toukan <tariqt@mellanox.com>
Subject: [PATCH net-next] mlx4: fix use-after-free in mlx4_en_fold_software_stats()
Date: Thu, 01 Dec 2016 05:02:06 -0800	[thread overview]
Message-ID: <1480597326.18162.276.camel@edumazet-glaptop3.roam.corp.google.com> (raw)
In-Reply-To: <20161201133706.316428e9@redhat.com>

From: Eric Dumazet <edumazet@google.com>

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: 40931b85113d ("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>
---
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c |    4 ++++
 drivers/net/ethernet/mellanox/mlx4/en_port.c   |    2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index 12ea3405f442717478bf0e8882edaf0de77986cb..091b904262bc7932d3edf99cf850affb23b9ce6e 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -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 */
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_port.c b/drivers/net/ethernet/mellanox/mlx4/en_port.c
index c6c4f1238923e09eced547454b86c68720292859..9166d90e732858610b1407fe85cbf6cbe27f5e0b 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_port.c
@@ -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;

  reply	other threads:[~2016-12-01 13:02 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-25 15:46 [PATCH] mlx4: give precise rx/tx bytes/packets counters Eric Dumazet
2016-11-25 16:03 ` David Laight
2016-11-25 16:16   ` Eric Dumazet
2016-11-25 16:30     ` Aw: " Lino Sanfilippo
2016-11-25 19:19       ` Eric Dumazet
2016-11-28 22:02         ` Lino Sanfilippo
2016-11-29  0:19           ` Eric Dumazet
2016-11-30 15:28             ` David Laight
2016-11-30 15:47               ` Eric Dumazet
2016-11-26 22:47 ` Saeed Mahameed
2016-11-27  2:16   ` Eric Dumazet
2016-11-28 20:40     ` David Miller
2016-11-28 21:55       ` Saeed Mahameed
2016-11-28 22:57         ` Eric Dumazet
2016-11-29 18:37 ` David Miller
2016-11-30 14:08 ` Regression: " Jesper Dangaard Brouer
2016-11-30 15:58   ` Eric Dumazet
2016-11-30 16:46     ` Saeed Mahameed
2016-11-30 17:35       ` Eric Dumazet
2016-11-30 20:42         ` Saeed Mahameed
2016-11-30 21:00           ` Eric Dumazet
2016-12-01 12:37             ` Jesper Dangaard Brouer
2016-12-01 13:02               ` Eric Dumazet [this message]
2016-12-01 15:23                 ` [PATCH net-next] mlx4: fix use-after-free in mlx4_en_fold_software_stats() Saeed Mahameed
2016-12-02 18:36                 ` David Miller
2016-12-01 15:38             ` Regression: [PATCH] mlx4: give precise rx/tx bytes/packets counters Saeed Mahameed
2016-12-01 15:55               ` Eric Dumazet
2016-12-01 16:08                 ` Eric Dumazet
2016-12-01 17:36                   ` Eric Dumazet
2016-12-04 13:23                     ` Saeed Mahameed
2016-12-01 16:33                 ` Saeed Mahameed
2016-12-01 17:08                   ` Eric Dumazet
2016-12-04 13:21                     ` Saeed Mahameed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480597326.18162.276.camel@edumazet-glaptop3.roam.corp.google.com \
    --to=eric.dumazet@gmail.com \
    --cc=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@dev.mellanox.co.il \
    --cc=tariqt@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.