diff mbox series

[RESEND] scsi: message: mptlan: Fix use after free bug in mptlan_remove due to race condition

Message ID 20230413074715.237471-1-zyytlz.wz@163.com
State New
Headers show
Series [RESEND] scsi: message: mptlan: Fix use after free bug in mptlan_remove due to race condition | expand

Commit Message

Zheng Wang April 13, 2023, 7:47 a.m. UTC
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 <zyytlz.wz@163.com>
---
 drivers/message/fusion/mptlan.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

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);