Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1687754 > unrolled thread

[PATCH for v4.9 LTS 64/87] tg3: Fix race condition in tg3_get_stats64().

Started by"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
First post2017-07-15 03:30 +0200
Last post2017-07-15 03:30 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH for v4.9 LTS 64/87] tg3: Fix race condition in  tg3_get_stats64(). "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com> - 2017-07-15 03:30 +0200

#1687754 — [PATCH for v4.9 LTS 64/87] tg3: Fix race condition in tg3_get_stats64().

From"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Date2017-07-15 03:30 +0200
Subject[PATCH for v4.9 LTS 64/87] tg3: Fix race condition in tg3_get_stats64().
Message-ID<u3k4b-3a5-37@gated-at.bofh.it>
From: Michael Chan <michael.chan@broadcom.com>

[ Upstream commit f5992b72ebe0dde488fa8f706b887194020c66fc ]

The driver's ndo_get_stats64() method is not always called under RTNL.
So it can race with driver close or ethtool reconfigurations.  Fix the
race condition by taking tp->lock spinlock in tg3_free_consistent()
when freeing the tp->hw_stats memory block.  tg3_get_stats64() is
already taking tp->lock.

Reported-by: Wang Yufen <wangyufen@huawei.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
---
 drivers/net/ethernet/broadcom/tg3.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index a927a730da10..edae2dcc4927 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -8720,11 +8720,14 @@ static void tg3_free_consistent(struct tg3 *tp)
 	tg3_mem_rx_release(tp);
 	tg3_mem_tx_release(tp);
 
+	/* Protect tg3_get_stats64() from reading freed tp->hw_stats. */
+	tg3_full_lock(tp, 0);
 	if (tp->hw_stats) {
 		dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats),
 				  tp->hw_stats, tp->stats_mapping);
 		tp->hw_stats = NULL;
 	}
+	tg3_full_unlock(tp);
 }
 
 /*
-- 
2.11.0

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web