All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bilal Hashim <AeeSec@126.com>
To: Jeff Hugo <jeff.hugo@oss.qualcomm.com>,
	Carl Vanderlip <carl.vanderlip@oss.qualcomm.com>,
	Oded Gabbay <ogabbay@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, Bilal Hashim <AeeSec@126.com>
Subject: [PATCH] accel/qaic: Synchronize access to dbc->bo_lists
Date: Sun, 29 Nov 2026 14:57:38 +0800	[thread overview]
Message-ID: <20261129065740.864-1-AeeSec@126.com> (raw)

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


             reply	other threads:[~2026-11-29  6:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  6:57 Bilal Hashim [this message]
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
2026-11-29  7:04   ` sashiko-bot
2026-11-29  7:10 ` [PATCH] accel/qaic: Synchronize access to dbc->bo_lists sashiko-bot

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=20261129065740.864-1-AeeSec@126.com \
    --to=aeesec@126.com \
    --cc=carl.vanderlip@oss.qualcomm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jeff.hugo@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ogabbay@kernel.org \
    /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.