]> git.baikalelectronics.ru Git - kernel.git/commitdiff
scsi: message: mptlan: Fix use after free bug in mptlan_remove() due to race condition
authorZheng Wang <zyytlz.wz@163.com>
Sat, 18 Mar 2023 08:16:35 +0000 (16:16 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 24 May 2023 16:32:37 +0000 (17:32 +0100)
[ Upstream commit f486893288f3e9b171b836f43853a6426515d800 ]

mptlan_probe() calls mpt_register_lan_device() which initializes the
&priv->post_buckets_task workqueue. A call to
mpt_lan_wake_post_buckets_task() will subsequently start the work.

During driver unload in mptlan_remove() the following race may occur:

CPU0                  CPU1

                    |mpt_lan_post_receive_buckets_work()
mptlan_remove()     |
  free_netdev()     |
    kfree(dev);     |
                    |
                    | dev->mtu
                    |   //use

Fix this by finishing the work prior to cleaning up in mptlan_remove().

[mkp: we really should remove mptlan instead of attempting to fix it]

Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
Link: https://lore.kernel.org/r/20230318081635.796479-1-zyytlz.wz@163.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/message/fusion/mptlan.c

index 142eb5d5d9df69e8c974112b2a649acb8194635b..de2e7bcf4784706d834d44f72741d5efada657f2 100644 (file)
@@ -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);