mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
Merge branch 'pds_core-fix-use-after-free-on-workqueue-during-remove'
Nikhil P. Rao says: ==================== pds_core: fix use-after-free on workqueue during remove This series fixes a use-after-free on the workqueue during driver remove. Patch 1 fixes a pre-existing deadlock between the PCI reset worker and pdsc_remove() that was identified during review of v1. Patch 2 is the reworked UAF fix that moves destroy_workqueue() after pdsc_teardown() and adds proper work synchronization. ==================== Link: https://patch.msgid.link/20260714180223.1642792-1-nikhil.rao@amd.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
commit
df282a9db8
|
|
@ -110,7 +110,6 @@ static void pdsc_qcq_intr_free(struct pdsc *pdsc, struct pdsc_qcq *qcq)
|
|||
return;
|
||||
|
||||
pdsc_intr_free(pdsc, qcq->intx);
|
||||
qcq->intx = PDS_CORE_INTR_INDEX_NOT_ASSIGNED;
|
||||
}
|
||||
|
||||
static int pdsc_qcq_intr_alloc(struct pdsc *pdsc, struct pdsc_qcq *qcq)
|
||||
|
|
@ -145,6 +144,12 @@ void pdsc_qcq_free(struct pdsc *pdsc, struct pdsc_qcq *qcq)
|
|||
|
||||
pdsc_qcq_intr_free(pdsc, qcq);
|
||||
|
||||
/* Drain any work queued by ISR before it was freed above */
|
||||
if (qcq->work.func)
|
||||
cancel_work_sync(&qcq->work);
|
||||
|
||||
qcq->intx = PDS_CORE_INTR_INDEX_NOT_ASSIGNED;
|
||||
|
||||
if (qcq->q_base)
|
||||
dma_free_coherent(dev, qcq->q_size,
|
||||
qcq->q_base, qcq->q_base_pa);
|
||||
|
|
@ -304,8 +309,11 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index,
|
|||
|
||||
static void pdsc_core_uninit(struct pdsc *pdsc)
|
||||
{
|
||||
pdsc_qcq_free(pdsc, &pdsc->notifyqcq);
|
||||
/* Free adminqcq first: its work accesses notifyqcq, so we must
|
||||
* disable its IRQ and drain its work before freeing notifyqcq.
|
||||
*/
|
||||
pdsc_qcq_free(pdsc, &pdsc->adminqcq);
|
||||
pdsc_qcq_free(pdsc, &pdsc->notifyqcq);
|
||||
|
||||
if (pdsc->kern_dbpage) {
|
||||
iounmap(pdsc->kern_dbpage);
|
||||
|
|
@ -479,8 +487,6 @@ void pdsc_teardown(struct pdsc *pdsc, bool removing)
|
|||
{
|
||||
if (!pdsc->pdev->is_virtfn)
|
||||
pdsc_devcmd_reset(pdsc);
|
||||
if (pdsc->adminqcq.work.func)
|
||||
cancel_work_sync(&pdsc->adminqcq.work);
|
||||
|
||||
pci_clear_master(pdsc->pdev);
|
||||
|
||||
|
|
@ -606,9 +612,10 @@ void pdsc_pci_reset_thread(struct work_struct *work)
|
|||
struct pdsc *pdsc = container_of(work, struct pdsc, pci_reset_work);
|
||||
struct pci_dev *pdev = pdsc->pdev;
|
||||
|
||||
pci_dev_get(pdev);
|
||||
pci_reset_function(pdev);
|
||||
pci_dev_put(pdev);
|
||||
/* Use try variant to avoid deadlock with pdsc_remove().
|
||||
* If lock is contended, the watchdog timer will retry.
|
||||
*/
|
||||
pci_try_reset_function(pdev);
|
||||
}
|
||||
|
||||
static void pdsc_check_pci_health(struct pdsc *pdsc)
|
||||
|
|
|
|||
|
|
@ -435,8 +435,6 @@ static void pdsc_remove(struct pci_dev *pdev)
|
|||
pdsc_auxbus_dev_del(pdsc, pdsc, &pdsc->padev);
|
||||
|
||||
timer_shutdown_sync(&pdsc->wdtimer);
|
||||
if (pdsc->wq)
|
||||
destroy_workqueue(pdsc->wq);
|
||||
|
||||
mutex_lock(&pdsc->config_lock);
|
||||
set_bit(PDSC_S_STOPPING_DRIVER, &pdsc->state);
|
||||
|
|
@ -444,6 +442,9 @@ static void pdsc_remove(struct pci_dev *pdev)
|
|||
pdsc_stop(pdsc);
|
||||
pdsc_teardown(pdsc, PDSC_TEARDOWN_REMOVING);
|
||||
mutex_unlock(&pdsc->config_lock);
|
||||
|
||||
if (pdsc->wq)
|
||||
destroy_workqueue(pdsc->wq);
|
||||
mutex_destroy(&pdsc->config_lock);
|
||||
mutex_destroy(&pdsc->devcmd_lock);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user