Skip to content

Commit 1beeec4

Browse files
rchatrevinodkoul
authored andcommitted
dmaengine: idxd: Prevent use after free on completion memory
On driver unload any pending descriptors are flushed at the time the interrupt is freed: idxd_dmaengine_drv_remove() -> drv_disable_wq() -> idxd_wq_free_irq() -> idxd_flush_pending_descs(). If there are any descriptors present that need to be flushed this flow triggers a "not present" page fault as below: BUG: unable to handle page fault for address: ff391c97c70c9040 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page The address that triggers the fault is the address of the descriptor that was freed moments earlier via: drv_disable_wq()->idxd_wq_free_resources() Fix the use after free by freeing the descriptors after any possible usage. This is done after idxd_wq_reset() to ensure that the memory remains accessible during possible completion writes by the device. Fixes: 63c14ae ("dmaengine: idxd: refactor wq driver enable/disable operations") Suggested-by: Dave Jiang <[email protected]> Signed-off-by: Reinette Chatre <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Fenghua Yu <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/6c4657d9cff0a0a00501a7b928297ac966e9ec9d.1670452419.git.reinette.chatre@intel.com Signed-off-by: Vinod Koul <[email protected]>
1 parent b51b75f commit 1beeec4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/dma/idxd/device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,11 +1407,11 @@ void drv_disable_wq(struct idxd_wq *wq)
14071407
dev_warn(dev, "Clients has claim on wq %d: %d\n",
14081408
wq->id, idxd_wq_refcount(wq));
14091409

1410-
idxd_wq_free_resources(wq);
14111410
idxd_wq_unmap_portal(wq);
14121411
idxd_wq_drain(wq);
14131412
idxd_wq_free_irq(wq);
14141413
idxd_wq_reset(wq);
1414+
idxd_wq_free_resources(wq);
14151415
percpu_ref_exit(&wq->wq_active);
14161416
wq->type = IDXD_WQT_NONE;
14171417
wq->client_count = 0;

0 commit comments

Comments
 (0)