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: Hold bo->lock when checking bo->sliced and bo->dbc in qaic_wait_bo_ioctl()
Date: Sun, 29 Nov 2026 14:57:39 +0800 [thread overview]
Message-ID: <20261129065740.864-2-AeeSec@126.com> (raw)
In-Reply-To: <20261129065740.864-1-AeeSec@126.com>
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:
next prev parent 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 [PATCH] accel/qaic: Synchronize access to dbc->bo_lists Bilal Hashim
2026-11-29 6:57 ` Bilal Hashim [this message]
2026-11-29 7:04 ` [PATCH] accel/qaic: Hold bo->lock when checking bo->sliced and bo->dbc in qaic_wait_bo_ioctl() 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-2-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.