e1000_remove() skips cancel_work_sync() on the reset task while __E1000_RESETTING is set. The check was needed when the cancel was in e1000_down_and_stop(), which the reset task reaches through e1000_down(), and it stayed when commit b4a8085ceefb ("e1000: Move cancel_work_sync to avoid deadlock") moved the cancel after unregister_netdev() in e1000_remove(). Every other path that sets __E1000_RESETTING runs under RTNL on the registered netdev, so after unregister_netdev() only the reset task can hold it. The check therefore skips the cancel while the task holds the bit, and free_netdev() can free the adapter before the task clears it. With __E1000_DOWN already set the task holds the bit only briefly, so this needs the task to be preempted there. e1000_remove() does not hold RTNL there, so cancelling the task, which takes RTNL, cannot deadlock. e1000e also cancels its reset task unconditionally in its remove path. Fixes: b4a8085ceefb ("e1000: Move cancel_work_sync to avoid deadlock") Signed-off-by: Joseph Telaak <jose…@telaak.dev> --- Sashiko pointed this out while reviewing an unrelated e1000 series: https://lore.kernel.org/r/sash…@kernel.org I know of no field reports, and I could only hit the window with the test hooks below. Tested on a CE5300 board with KASAN and lockdep, using test-only hooks that queue the reset task in e1000_remove() and hold __E1000_RESETTING in it for a second. Without this patch KASAN reports a slab use-after-free in e1000_reinit_locked() from the reset task, with the netdev freed by e1000_remove(). With it, e1000_remove() waits for the task, and unbind and rebind work with no reports. --- drivers/net/ethernet/intel/e1000/e1000_main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c index a52fff0259a1..d79e7ca69792 100644 --- a/drivers/net/ethernet/intel/e1000/e1000_main.c +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c @@ -1270,9 +1270,7 @@ static void e1000_remove(struct pci_dev *pdev) unregister_netdev(netdev); - /* Only kill reset task if adapter is not resetting */ - if (!test_bit(__E1000_RESETTING, &adapter->flags)) - cancel_work_sync(&adapter->reset_task); + cancel_work_sync(&adapter->reset_task); e1000_phy_hw_reset(hw); --- base-commit: 68be40d53028e490d37ff7e754dac4afae2ef421 change-id: 20261202-e1000-remove-reset-task-f2c8d8518822 Best regards, -- Joseph Telaak <jose…@telaak.dev>