The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] accel/qaic: Synchronize access to dbc->bo_lists
@ 2026-11-29  6:57 Bilal Hashim
  2026-11-29  6:57 ` [PATCH] accel/qaic: Hold bo->lock when checking bo->sliced and bo->dbc in qaic_wait_bo_ioctl() Bilal Hashim
  0 siblings, 1 reply; 2+ messages in thread
From: Bilal Hashim @ 2026-11-29  6:57 UTC (permalink / raw)
  To: Jeff Hugo, Carl Vanderlip, Oded Gabbay
  Cc: linux-arm-msm, dri-devel, linux-kernel, Bilal Hashim

Each `struct dma_bridge_chan` maintains a `bo_lists` linked list of all
sliced BOs attached to that DBC, which is modified in
`qaic_attach_slice_bo_ioctl()` via `list_add_tail()` and in
`detach_slice_bo()` (called from `qaic_detach_slice_bo_ioctl()` and
`release_dbc()`) via `list_del()`.

However, `dbc->bo_lists` is not protected by any lock. Both
`qaic_attach_slice_bo_ioctl()` and `qaic_detach_slice_bo_ioctl()` only
hold the per-BO `bo->lock` mutex and shared SRCU read locks
(`usr->qddev_lock`, `qdev->dev_lock`, and `dbc->ch_lock`). Two threads
from the same user concurrently attaching or detaching different BOs on
the same DBC can race on `dbc->bo_lists`, causing linked-list corruption
and potential use-after-free when `release_dbc()` later iterates
`dbc->bo_lists`.

Add a dedicated `spinlock_t bo_lists_lock` to `struct dma_bridge_chan`,
initialize it in `create_qdev()`, and hold it around `list_add_tail()`
in `qaic_attach_slice_bo_ioctl()` and `list_del()` in
`detach_slice_bo()`.

Found by manual code inspection.

Signed-off-by: Bilal Hashim <AeeSec@126.com>
---
 drivers/accel/qaic/qaic.h      | 2 ++
 drivers/accel/qaic/qaic_data.c | 9 +++++++++
 drivers/accel/qaic/qaic_drv.c  | 1 +
 3 files changed, 12 insertions(+)

diff --git a/drivers/accel/qaic/qaic.h b/drivers/accel/qaic/qaic.h
index 111111111111..222222222222 100644
--- a/drivers/accel/qaic/qaic.h
+++ b/drivers/accel/qaic/qaic.h
@@ -125,6 +125,8 @@ struct dma_bridge_chan {
 	 * woken up
 	 */
 	wait_queue_head_t	dbc_release;
+	/* Synchronizes access to bo_lists */
+	spinlock_t		bo_lists_lock;
 	/* Head of list where each node is a bo associated with this DBC */
 	struct list_head	bo_lists;
 	/* The irq line for this DBC. Used for polling */
diff --git a/drivers/accel/qaic/qaic_data.c b/drivers/accel/qaic/qaic_data.c
index 333333333333..444444444444 100644
--- a/drivers/accel/qaic/qaic_data.c
+++ b/drivers/accel/qaic/qaic_data.c
@@ -1089,7 +1089,9 @@ int qaic_attach_slice_bo_ioctl(struct drm_device *dev, void *data, struct drm_fi
 		dma_sync_sgtable_for_cpu(&qdev->pdev->dev, bo->sgt, args->hdr.dir);
 
 	bo->sliced = true;
+	spin_lock(&dbc->bo_lists_lock);
 	list_add_tail(&bo->bo_list, &bo->dbc->bo_lists);
+	spin_unlock(&dbc->bo_lists_lock);
 	srcu_read_unlock(&dbc->ch_lock, rcu_id);
 	mutex_unlock(&bo->lock);
 	kfree(slice_ent);
@@ -1903,10 +1905,16 @@ int qaic_perf_stats_bo_ioctl(struct drm_device *dev, void *data, struct drm_file
 
 static void detach_slice_bo(struct qaic_device *qdev, struct qaic_bo *bo)
 {
+	struct dma_bridge_chan *dbc = bo->dbc;
+
 	qaic_free_slices_bo(bo);
 	qaic_unprepare_bo(qdev, bo);
 	qaic_init_bo(bo, true);
-	list_del(&bo->bo_list);
+	if (dbc) {
+		spin_lock(&dbc->bo_lists_lock);
+		list_del(&bo->bo_list);
+		spin_unlock(&dbc->bo_lists_lock);
+	}
 	drm_gem_object_put(&bo->base);
 }
 
diff --git a/drivers/accel/qaic/qaic_drv.c b/drivers/accel/qaic/qaic_drv.c
index 555555555555..666666666666 100644
--- a/drivers/accel/qaic/qaic_drv.c
+++ b/drivers/accel/qaic/qaic_drv.c
@@ -477,6 +477,7 @@ static struct qaic_device *create_qdev(struct pci_dev *pdev,
 		if (ret)
 			return NULL;
 		init_waitqueue_head(&qdev->dbc[i].dbc_release);
+		spin_lock_init(&qdev->dbc[i].bo_lists_lock);
 		INIT_LIST_HEAD(&qdev->dbc[i].bo_lists);
 		ret = drmm_mutex_init(drm, &qdev->dbc[i].req_lock);
 		if (ret)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29  6:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  6:57 [PATCH] accel/qaic: Synchronize access to dbc->bo_lists Bilal Hashim
2026-11-29  6:57 ` [PATCH] accel/qaic: Hold bo->lock when checking bo->sliced and bo->dbc in qaic_wait_bo_ioctl() Bilal Hashim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox