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 <[email protected]>
---
--- 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:

Reply via email to