]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
forcedeth: fix UAF of txrx_stats in nv_remove
authorChenguang Zhao <zhaochenguang@kylinos.cn>
Thu, 23 Jul 2026 09:26:37 +0000 (17:26 +0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 28 Jul 2026 00:52:50 +0000 (17:52 -0700)
nv_remove() frees the per-CPU txrx_stats before unregister_netdev().
Until unregister completes, ndo_get_stats64, the NAPI/xmit data path,
and nv_close()/drain may still access txrx_stats, leading to a
use-after-free.

Free the stats only after unregister_netdev().

Fixes: f4b633b911fd ("forcedeth: use per cpu to collect xmit/recv statistics")
Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Link: https://patch.msgid.link/20260723092637.2135095-1-chenguang.zhao@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/nvidia/forcedeth.c

index 5b0435d7bc395840ffef3e18c62857399bfd35cb..58d3e55def486b16c011c658e7a1491a2dccb744 100644 (file)
@@ -6187,10 +6187,10 @@ static void nv_remove(struct pci_dev *pci_dev)
        struct net_device *dev = pci_get_drvdata(pci_dev);
        struct fe_priv *np = netdev_priv(dev);
 
-       free_percpu(np->txrx_stats);
-
        unregister_netdev(dev);
 
+       free_percpu(np->txrx_stats);
+
        nv_restore_mac_addr(pci_dev);
 
        /* restore any phy related changes */