Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2065086rwl; Thu, 13 Apr 2023 00:50:04 -0700 (PDT) X-Google-Smtp-Source: AKy350b1m5LQw0IXqarvM9uRbOypObsZ2PiXG5FDrgx65OOdnq8UPQ8uthwi88W3oZxbSP/8nbyd X-Received: by 2002:a17:906:355a:b0:94e:1611:e378 with SMTP id s26-20020a170906355a00b0094e1611e378mr1857360eja.21.1681372204029; Thu, 13 Apr 2023 00:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681372204; cv=none; d=google.com; s=arc-20160816; b=Xvd5lpmj8Di+oIpAtiHVGlnD21Xu0L1i01i4fEVe7EREWXDCcTfj66l3jFwXXmS4ef RLonFujGYo5pdDtCDDKbBzGVvqaLyKon6dvj4XIh4mORz09j0gwBI49cYTtR5gcei78r JXlIhRjXvicGrHcz0a/FMQBDFmdsarTW7EDGUv2ygiWPy6jWN1O1D6x5VUQwqcvioh9/ nJO6jfoSkX0pNg5GZ0o4NxQJi4VN96+CFAhTEQSa5+rbJIBEPjsQTHwmlehRLswJ0HR/ ykl73SIX3vyl85ezCFq+gbtlT3/4GWA9af4lGIR6ZSzeY81JvZ5bO7Oeot1I2BXSZwE5 bkBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=4ZscuiQPwnHKfbAbpvcHFmQ/w/W3FQBM8Le/KlBVmX8=; b=yT6z7+fkDAizBUI/TXJVEbS6dqfALul5FGjqv7hgjcSKA3OrMUD3BPu/57XnbZji6I TrG7+sXW3d/2s4j9PFIbmdLmMubgDgorQYm6UxslIESoiGdwwK1W3pyWRgS0MGT1q7Hx 1vGY7xTTLz4NsN/GTqdboOZTcdbzkZyAfEjZfKjWtSkV6r8jAcQ3yO+pjysfzbXirug2 QqUHFktRDMYRsh23+16psCn3X+vDI/HYF5nNlu2rHOKauM+zbdaTWadkdON2O5VKchT7 vNYKWJ4hD9WERBnxo0SN9KfjRrCoPgPu3x4Ct04JYeo0d3pw7R+0KxwIz3t8AjHoGnIz 5psw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=OqoNaQIY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a1709061c4900b0094e4d3d0f62si1425918ejg.888.2023.04.13.00.49.39; Thu, 13 Apr 2023 00:50:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=OqoNaQIY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230182AbjDMHtA (ORCPT + 99 others); Thu, 13 Apr 2023 03:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230233AbjDMHs4 (ORCPT ); Thu, 13 Apr 2023 03:48:56 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9699083FA; Thu, 13 Apr 2023 00:48:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=4Zscu iQPwnHKfbAbpvcHFmQ/w/W3FQBM8Le/KlBVmX8=; b=OqoNaQIYuk9GQjrKGTqFb y40Lu2Tr6qvWr7iLUmFWo/K0o8h6ReWDgrmcn7w85RPfGUPzQlEKMbis1A5SHFAz JzW3w3RaLCxd0PtcBUQC8HGlSwlB+zLJxF/MOsUwJ0ZINmrlghJBDLSXQ/iZmvqv X+Ie+SZ3728uGNA5Ohxv2M= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g3-3 (Coremail) with SMTP id _____wA3nmaFszdkGDBrBQ--.49914S2; Thu, 13 Apr 2023 15:47:17 +0800 (CST) From: Zheng Wang To: sathya.prakash@broadcom.com Cc: sreekanth.reddy@broadcom.com, suganath-prabu.subramani@broadcom.com, MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang Subject: [PATCH RESEND] scsi: message: mptlan: Fix use after free bug in mptlan_remove due to race condition Date: Thu, 13 Apr 2023 15:47:15 +0800 Message-Id: <20230413074715.237471-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wA3nmaFszdkGDBrBQ--.49914S2 X-Coremail-Antispam: 1Uf129KBjvJXoWrurykGF4Dur1fWry5Wr13CFg_yoW8Jry7pr ZFka48CrZ5Jw1Iy3WDtFy8AFyrC3WIgrWkKrWSg342vr1FkFyYq340kFy2kw1xXFs5Ga13 Zr4DJFs7GayDKFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziYFAtUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiQgdQU1aEE+PxogAAs3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In mptlan_probe, it called mpt_register_lan_device and bound &priv->post_buckets_task with mpt_lan_post_receive_buckets_work. When it calls lan_reply, it will finally call mpt_lan_wake_post_buckets_task to start the work. When we call mptlan_remove to remove the driver, there may be a sequence as follows: Fix it by finishing the work before cleanup in mptlan_remove CPU0 CPU1 |mpt_lan_post_receive_buckets_work mptlan_remove | free_netdev | kfree(dev); | | | dev->mtu | //use Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Zheng Wang --- drivers/message/fusion/mptlan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c index 142eb5d5d9df..de2e7bcf4784 100644 --- a/drivers/message/fusion/mptlan.c +++ b/drivers/message/fusion/mptlan.c @@ -1433,7 +1433,9 @@ mptlan_remove(struct pci_dev *pdev) { MPT_ADAPTER *ioc = pci_get_drvdata(pdev); struct net_device *dev = ioc->netdev; + struct mpt_lan_priv *priv = netdev_priv(dev); + cancel_delayed_work_sync(&priv->post_buckets_task); if(dev != NULL) { unregister_netdev(dev); free_netdev(dev); -- 2.25.1