All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zheng Wang <zyytlz.wz@163.com>
To: don.brace@microchip.com
Cc: jejb@linux.ibm.com, martin.petersen@oracle.com,
	storagedev@microchip.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org, hackerzheng666@gmail.com,
	1395428693sheep@gmail.com, alex000young@gmail.com,
	Zheng Wang <zyytlz.wz@163.com>
Subject: [PATCH] scsi: smartpqi: Fix use after free bug in pqi_pci_remove due to race condition
Date: Mon, 13 Mar 2023 00:48:06 +0800	[thread overview]
Message-ID: <20230312164806.2104140-1-zyytlz.wz@163.com> (raw)

In pqi_pci_probe, it calls pqi_alloc_ctrl_info and bound
&ctrl_info->event_work with pqi_event_worker.

When it calls pqi_irq_handler to handle IRQ, 
it will finally call schedule_work to start the work.

When we call pqi_pci_remove to remove the driver, there
may be a sequence as follows:

Fix it by finishing the work before cleanup in pqi_remove_ctrl.

CPU0                  CPU1

                    |pqi_event_worker
pqi_pci_remove      |
  pqi_remove_ctrl   |
pqi_free_ctrl_resources|
pqi_free_ctrl_info|
     kfree(ctrl_info)  |
//free ctrl_info   |
                    |pqi_ctrl_busy
                    |//use ctrl_info

Fixes: 6c223761eb54 ("smartpqi: initial commit of Microsemi smartpqi driver")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/scsi/smartpqi/smartpqi_init.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 49a8f91810b6..555f1af38f38 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -8939,6 +8939,7 @@ static void pqi_take_ctrl_offline_deferred(struct pqi_ctrl_info *ctrl_info)
 	pqi_perform_lockup_action();
 	pqi_stop_heartbeat_timer(ctrl_info);
 	pqi_free_interrupts(ctrl_info);
+	cancel_work_sync(&ctrl_info->event_work);
 	pqi_cancel_rescan_worker(ctrl_info);
 	pqi_cancel_update_time_worker(ctrl_info);
 	pqi_ctrl_wait_until_quiesced(ctrl_info);
-- 
2.25.1


                 reply	other threads:[~2023-03-12 16:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230312164806.2104140-1-zyytlz.wz@163.com \
    --to=zyytlz.wz@163.com \
    --cc=1395428693sheep@gmail.com \
    --cc=alex000young@gmail.com \
    --cc=don.brace@microchip.com \
    --cc=hackerzheng666@gmail.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=storagedev@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.