* [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 [flat|nested] 2+ messages in thread
* [PATCH] accel/qaic: Hold bo->lock when checking bo->sliced and bo->dbc in qaic_wait_bo_ioctl()
2026-11-29 6:57 [PATCH] accel/qaic: Synchronize access to dbc->bo_lists Bilal Hashim
@ 2026-11-29 6:57 ` Bilal Hashim
0 siblings, 0 replies; 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
In `qaic_wait_bo_ioctl()`, `bo->sliced` and `bo->dbc->id` are read
without holding `bo->lock`.
Concurrently, `qaic_detach_slice_bo_ioctl()` calls `detach_slice_bo()`,
which invokes `qaic_unprepare_bo()` (setting `bo->dbc = NULL`) before
`qaic_init_bo(bo, true)` clears `bo->sliced = false`. A thread in
`qaic_wait_bo_ioctl()` can observe `bo->sliced == true` and then
dereference `bo->dbc->id` after `bo->dbc` has been cleared to `NULL`,
triggering a NULL pointer dereference.
Look up the GEM object and validate `bo->sliced` and `bo->dbc->id` under
`bo->lock` before acquiring `dbc->ch_lock` (preserving lock ordering
with `qaic_attach_slice_bo_ioctl()` and `qaic_detach_slice_bo_ioctl()`),
then release `bo->lock` before sleeping in
`wait_for_completion_interruptible_timeout()`.
Found by manual code inspection.
Signed-off-by: Bilal Hashim <AeeSec@126.com>
---
--- a/drivers/accel/qaic/qaic_data.c 2026-11-29 14:54:02.057387256 +0800
+++ b/drivers/accel/qaic/qaic_data.c 2026-11-29 14:54:02.347387185 +0800
@@ -1754,6 +1754,23 @@ int qaic_wait_bo_ioctl(struct drm_device
goto unlock_dev_srcu;
}
+ obj = drm_gem_object_lookup(file_priv, args->handle);
+ if (!obj) {
+ ret = -ENOENT;
+ goto unlock_dev_srcu;
+ }
+
+ bo = to_qaic_bo(obj);
+ ret = mutex_lock_interruptible(&bo->lock);
+ if (ret)
+ goto put_obj;
+ if (!bo->sliced || bo->dbc->id != args->dbc_id) {
+ mutex_unlock(&bo->lock);
+ ret = -EINVAL;
+ goto put_obj;
+ }
+ mutex_unlock(&bo->lock);
+
dbc = &qdev->dbc[args->dbc_id];
rcu_id = srcu_read_lock(&dbc->ch_lock);
@@ -1767,30 +1784,12 @@ int qaic_wait_bo_ioctl(struct drm_device
goto unlock_ch_srcu;
}
- obj = drm_gem_object_lookup(file_priv, args->handle);
- if (!obj) {
- ret = -ENOENT;
- goto unlock_ch_srcu;
- }
-
- bo = to_qaic_bo(obj);
-
- if (!bo->sliced) {
- ret = -EINVAL;
- goto put_obj;
- }
-
- if (bo->dbc->id != dbc->id) {
- ret = -EINVAL;
- goto put_obj;
- }
-
timeout = args->timeout ? args->timeout : wait_exec_default_timeout_ms;
timeout = msecs_to_jiffies(timeout);
ret = wait_for_completion_interruptible_timeout(&bo->xfer_done, timeout);
if (!ret) {
ret = -ETIMEDOUT;
- goto put_obj;
+ goto unlock_ch_srcu;
}
if (ret > 0)
ret = 0;
@@ -1801,10 +1800,10 @@ int qaic_wait_bo_ioctl(struct drm_device
if (dbc->id == qdev->ssr_dbc)
ret = -EPIPE;
-put_obj:
- drm_gem_object_put(obj);
unlock_ch_srcu:
srcu_read_unlock(&dbc->ch_lock, rcu_id);
+put_obj:
+ drm_gem_object_put(obj);
unlock_dev_srcu:
srcu_read_unlock(&qdev->dev_lock, qdev_rcu_id);
unlock_usr_srcu:
^ permalink raw reply [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
all inboxes | Powered by JetHome®