From: Ashutosh Desai <ashutoshdesai993@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: mcanal@igalia.com, itoral@igalia.com, stable@vger.kernel.org,
Ashutosh Desai <ashutoshdesai993@gmail.com>
Subject: [PATCH v2] drm/v3d: Limit ioctl extension chain depth to prevent infinite loop
Date: Mon, 13 Apr 2026 05:52:30 +0000 [thread overview]
Message-ID: <20260413055230.3349114-1-ashutoshdesai993@gmail.com> (raw)
In-Reply-To: <cbcb794f-0d82-40b4-a9a5-6aca99e8c434@igalia.com>
v3d_get_extensions() walks a userspace-provided singly-linked list of
ioctl extensions without any bound on the chain length. A local user
can craft a self-referential extension (ext->next == &ext) with zero
in_sync_count and out_sync_count, which bypasses the existing duplicate-
extension guard:
if (se->in_sync_count || se->out_sync_count)
return -EINVAL;
The guard never fires because v3d_get_multisync_post_deps() returns
immediately when count is zero, leaving both fields at zero on every
iteration. The result is an infinite loop in kernel context, blocking
the calling thread and pegging a CPU core indefinitely.
Both i915 (stackdepth = 512) and xe (MAX_USER_EXTENSIONS = 16) impose
an explicit depth limit on the same pattern. Apply the same defence to
V3D by introducing V3D_MAX_EXTENSIONS and capping the walk at 7, which
matches the number of currently defined V3D extension types.
Cc: stable@vger.kernel.org
Signed-off-by: Ashutosh Desai <ashutoshdesai993@gmail.com>
---
drivers/gpu/drm/v3d/v3d_submit.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/gpu/drm/v3d/v3d_submit.c b/drivers/gpu/drm/v3d/v3d_submit.c
index 18f2bf1fe89f..8951909198c2 100644
--- a/drivers/gpu/drm/v3d/v3d_submit.c
+++ b/drivers/gpu/drm/v3d/v3d_submit.c
@@ -11,6 +11,8 @@
#include "v3d_regs.h"
#include "v3d_trace.h"
+#define V3D_MAX_EXTENSIONS 7
+
/* Takes the reservation lock on all the BOs being referenced, so that
* we can attach fences and update the reservations after pushing the job
* to the queue.
@@ -802,12 +804,18 @@ v3d_get_extensions(struct drm_file *file_priv,
struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
struct v3d_dev *v3d = v3d_priv->v3d;
struct drm_v3d_extension __user *user_ext;
+ unsigned int ext_count = 0;
int ret;
user_ext = u64_to_user_ptr(ext_handles);
while (user_ext) {
struct drm_v3d_extension ext;
+ if (ext_count++ >= V3D_MAX_EXTENSIONS) {
+ drm_dbg(&v3d->drm, "Too many V3D ioctl extensions\n");
+ return -E2BIG;
+ }
+
if (copy_from_user(&ext, user_ext, sizeof(ext))) {
drm_dbg(&v3d->drm, "Failed to copy submit extension\n");
return -EFAULT;
--
2.34.1
next prev parent reply other threads:[~2026-04-13 5:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-10 1:39 [PATCH] drm/v3d: Limit ioctl extension chain depth to prevent infinite loop Ashutosh Desai
2026-04-10 18:16 ` Maíra Canal
2026-04-13 5:52 ` Ashutosh Desai [this message]
2026-04-12 0:35 ` Claude review: " Claude Code Review Bot
2026-04-12 0:35 ` Claude Code Review 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=20260413055230.3349114-1-ashutoshdesai993@gmail.com \
--to=ashutoshdesai993@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=itoral@igalia.com \
--cc=mcanal@igalia.com \
--cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox