Skip to content

Commit 032422c

Browse files
Michael Changregkh
authored andcommitted
tg3: Fix race condition in tg3_get_stats64().
[ 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 93585e8 commit 032422c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

  • drivers/net/ethernet/broadcom

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8722,11 +8722,14 @@ static void tg3_free_consistent(struct tg3 *tp)
87228722
tg3_mem_rx_release(tp);
87238723
tg3_mem_tx_release(tp);
87248724

8725+
/* Protect tg3_get_stats64() from reading freed tp->hw_stats. */
8726+
tg3_full_lock(tp, 0);
87258727
if (tp->hw_stats) {
87268728
dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats),
87278729
tp->hw_stats, tp->stats_mapping);
87288730
tp->hw_stats = NULL;
87298731
}
8732+
tg3_full_unlock(tp);
87308733
}
87318734

87328735
/*

0 commit comments

Comments
 (0)