From patchwork Thu Apr 20 14:01:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duoming Zhou X-Patchwork-Id: 13218852 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A77EC77B73 for ; Thu, 20 Apr 2023 14:03:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231827AbjDTODL (ORCPT ); Thu, 20 Apr 2023 10:03:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbjDTODI (ORCPT ); Thu, 20 Apr 2023 10:03:08 -0400 Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [20.228.234.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A9BDA49DE for ; Thu, 20 Apr 2023 07:03:05 -0700 (PDT) Received: from ubuntu.localdomain (unknown [218.12.18.95]) by mail-app3 (Coremail) with SMTP id cC_KCgDn7w_XRUFkQSOLAA--.3844S2; Thu, 20 Apr 2023 22:02:12 +0800 (CST) From: Duoming Zhou To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, intel-wired-lan@lists.osuosl.org, Duoming Zhou Subject: [PATCH net] ethernet: ixgb: fix use after free bugs caused by circular dependency problem Date: Thu, 20 Apr 2023 22:01:57 +0800 Message-Id: <20230420140157.22416-1-duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cC_KCgDn7w_XRUFkQSOLAA--.3844S2 X-Corem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jiasttq6lmxovvfxof0/1tbiAwMLAWRAA1s8WwAwsh Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The watchdog_timer can schedule tx_timeout_task and tx_timeout_task can also arm watchdog_timer. The process is shown below: ----------- timer schedules work ------------ ixgb_watchdog() //timer handler schedule_work(&adapter->tx_timeout_task) ----------- work arms timer ------------ ixgb_tx_timeout_task() //workqueue callback function ixgb_up() mod_timer(&adapter->watchdog_timer,...) When ixgb device is detaching, the timer and workqueue could still be rearmed. The process is shown below: (cleanup routine) | (timer and workqueue routine) ixgb_remove() | | ixgb_tx_timeout_task() //workqueue | ixgb_up() | mod_timer() cancel_work_sync() | free_netdev(netdev) //FREE | ixgb_watchdog() //timer | netif_carrier_ok(netdev) //USE This patch adds timer_shutdown_sync() in ixgb_remove(), which could prevent rearming of the timer from the workqueue. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Duoming Zhou --- drivers/net/ethernet/intel/ixgb/ixgb_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/ethernet/intel/ixgb/ixgb_main.c b/drivers/net/ethernet/intel/ixgb/ixgb_main.c index b4d47e7a76c..6ce3601904b 100644 --- a/drivers/net/ethernet/intel/ixgb/ixgb_main.c +++ b/drivers/net/ethernet/intel/ixgb/ixgb_main.c @@ -516,6 +516,7 @@ ixgb_remove(struct pci_dev *pdev) struct net_device *netdev = pci_get_drvdata(pdev); struct ixgb_adapter *adapter = netdev_priv(netdev); + timer_shutdown_sync(&adapter->watchdog_timer); cancel_work_sync(&adapter->tx_timeout_task); unregister_netdev(netdev);