* [PATCH net] tg3: Fix race condition in tg3_get_stats64().
@ 2017-01-06 21:18 Michael Chan
2017-01-08 2:35 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Michael Chan @ 2017-01-06 21:18 UTC (permalink / raw)
To: davem; +Cc: netdev, wangyufen
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>
---
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 185e9e0..ae42de4 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);
}
/*
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] tg3: Fix race condition in tg3_get_stats64().
2017-01-06 21:18 [PATCH net] tg3: Fix race condition in tg3_get_stats64() Michael Chan
@ 2017-01-08 2:35 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2017-01-08 2:35 UTC (permalink / raw)
To: michael.chan; +Cc: netdev, wangyufen
From: Michael Chan <michael.chan@broadcom.com>
Date: Fri, 6 Jan 2017 16:18:53 -0500
> 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>
Applied, thanks Michael.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-01-08 2:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-06 21:18 [PATCH net] tg3: Fix race condition in tg3_get_stats64() Michael Chan
2017-01-08 2:35 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).