public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Sworo, George D" <george.d.sworo@intel.com>
To: "ville.syrjala@linux.intel.com" <ville.syrjala@linux.intel.com>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] drm/modeset_lock: add NULL check for ctx before WARN_ON
Date: Thu, 30 Apr 2026 04:12:05 +0000	[thread overview]
Message-ID: <4f569465fd754399b5cd0a1029538249015fce43.camel@intel.com> (raw)
In-Reply-To: <afHm1k0K0mDRPmJM@intel.com>

Thanks Ville for the review!
Fair point. Ideally, we shouldn't be calling modeset_lock() with NULL
ctx but during a recent debug we uncovered an issue where the system
kept printing the calltrace and I figured this was one instance where
ctx is being dereferenced without a guard

03-26 11:33:03.261     0     0 F BUG     : kernel NULL pointer
dereference, address: 0000000000000069
03-26 11:33:03.261     0     0 F #PF     : supervisor read access in
kernel mode
03-26 11:33:03.261     0     0 F #PF     : error_code(0x0000) - not-
present page
03-26 11:33:03.261     0     0 I         : PGD 0 P4D 0
03-26 11:33:03.261     0     0 W Oops    : Oops: 0000 [#1] PREEMPT SMP
NOPTI
03-26 11:33:03.261     0     0 W Tainted : [U]=USER, [W]=WARN,
[O]=OOT_MODULE
03-26 11:33:03.261     0     0 W Workqueue: i915_flip
intel_atomic_commit_work [xe]
03-26 11:33:03.262     0     0 W RIP     : 0010:modeset_lock+0x74/0xd0



On Wed, 2026-04-29 at 14:09 +0300, Ville Syrjälä wrote:
> On Tue, Apr 28, 2026 at 11:04:30PM -0700,
> george.d.sworo@intel.com wrote:
> > From: George D Sworo <george.d.sworo@intel.com>
> > 
> > modeset_lock() and drm_modeset_drop_locks() do not validate
> > the ctx pointer before dereferencing it in WARN_ON(ctx->contended),
> > which can lead to a NULL pointer dereference if ctx is NULL.
> > 
> > Add a NULL check to prevent this.
> 
> Why are you trying to pass garbage into the function?
> 
> > 
> > Signed-off-by: George D Sworo <george.d.sworo@intel.com>
> > ---
> >  drivers/gpu/drm/drm_modeset_lock.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_modeset_lock.c
> > b/drivers/gpu/drm/drm_modeset_lock.c
> > index beb91a13a312..2052bb9bb9e5 100644
> > --- a/drivers/gpu/drm/drm_modeset_lock.c
> > +++ b/drivers/gpu/drm/drm_modeset_lock.c
> > @@ -295,7 +295,7 @@ static inline int modeset_lock(struct
> > drm_modeset_lock *lock,
> >  {
> >  	int ret;
> >  
> > -	if (WARN_ON(ctx->contended))
> > +	if (ctx && WARN_ON(ctx->contended))
> >  		__drm_stack_depot_print(ctx->stack_depot);
> >  
> >  	if (ctx->trylock_only) {
> > -- 
> > 2.34.1
> 


  reply	other threads:[~2026-04-30  4:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260429025952.1202080-1-george.d.sworo@intel.com>
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 [this message]
2026-04-29  6:04   ` [PATCH v2 2/2] drm/modeset: harden modeset_lock() against NULL ctx george.d.sworo

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=4f569465fd754399b5cd0a1029538249015fce43.camel@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 \
    --cc=ville.syrjala@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