Re: [PATCH v2 1/2] drm/modeset_lock: add NULL check for ctx before WARN_ON
From: Ville Syrjälä
Date: Wed Apr 29 2026 - 07:09:43 EST
On Tue, Apr 28, 2026 at 11:04:30PM -0700, george.d.sworo@xxxxxxxxx wrote:
> From: George D Sworo <george.d.sworo@xxxxxxxxx>
>
> 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@xxxxxxxxx>
> ---
> 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
--
Ville Syrjälä
Intel