From: george.d.sworo@intel.com
To: maarten.lankhorst@linux.intel.com
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
George D Sworo <george.d.sworo@intel.com>
Subject: [PATCH v2 2/2] drm/modeset: harden modeset_lock() against NULL ctx
Date: Tue, 28 Apr 2026 23:04:31 -0700 [thread overview]
Message-ID: <20260429060431.1462589-3-george.d.sworo@intel.com> (raw)
In-Reply-To: <20260429060431.1462589-1-george.d.sworo@intel.com>
From: George D Sworo <george.d.sworo@intel.com>
modeset_lock() dereferences ctx unconditionally. Add a defensive NULL
guard to avoid NULL dereference if a buggy internal caller passes a NULL
acquire context.
For NULL ctx, fall back to plain ww_mutex locking semantics:
- interruptible path uses ww_mutex_lock_interruptible(..., NULL)
- non-interruptible path uses ww_mutex_lock(..., NULL)
This keeps wait behavior consistent with the helper arguments.
Signed-off-by: George D Sworo <george.d.sworo@intel.com>
---
drivers/gpu/drm/drm_modeset_lock.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/gpu/drm/drm_modeset_lock.c b/drivers/gpu/drm/drm_modeset_lock.c
index 2052bb9bb9e5..5bee424805c3 100644
--- a/drivers/gpu/drm/drm_modeset_lock.c
+++ b/drivers/gpu/drm/drm_modeset_lock.c
@@ -294,6 +294,18 @@ static inline int modeset_lock(struct drm_modeset_lock *lock,
bool interruptible, bool slow)
{
int ret;
+ /*
+ * Defensive fallback: this helper is expected to be called with a
+ * valid acquire context, but if a NULL ctx slips through, preserve
+ * the lock wait semantics and avoid NULL dereference.
+ */
+ if (unlikely(!ctx)) {
+ if (interruptible)
+ return ww_mutex_lock_interruptible(&lock->mutex, NULL);
+
+ ww_mutex_lock(&lock->mutex, NULL);
+ return 0;
+ }
if (ctx && WARN_ON(ctx->contended))
__drm_stack_depot_print(ctx->stack_depot);
--
2.34.1
next prev parent reply other threads:[~2026-04-29 6:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 2:59 [PATCH] drm/modeset_lock: add NULL check for ctx before WARN_ON george.d.sworo
2026-04-29 6:04 ` [PATCH v2 0/2] drm/i915/modeset: fix NULL/ctx handling in lock paths george.d.sworo
2026-04-29 6:04 ` [PATCH v2 1/2] drm/modeset_lock: add NULL check for ctx before WARN_ON george.d.sworo
2026-04-29 11:09 ` Ville Syrjälä
2026-04-30 4:12 ` Sworo, George D
2026-04-29 6:04 ` george.d.sworo [this message]
2026-05-05 1:50 ` Claude review: drm/modeset: harden modeset_lock() against NULL ctx Claude Code Review Bot
2026-05-05 1:50 ` Claude review: drm/i915/modeset: fix NULL/ctx handling in lock paths Claude Code Review Bot
2026-05-05 1:50 ` Claude review: drm/modeset_lock: add NULL check for ctx before WARN_ON 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=20260429060431.1462589-3-george.d.sworo@intel.com \
--to=george.d.sworo@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
/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