dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915/gem: Do not leak siblings[] on proto context error
@ 2026-07-01  7:30 Joonas Lahtinen
  2026-07-01  7:41 ` sashiko-bot
  2026-07-01 11:20 ` Maarten Lankhorst
  0 siblings, 2 replies; 4+ messages in thread
From: Joonas Lahtinen @ 2026-07-01  7:30 UTC (permalink / raw)
  To: Intel graphics driver community testing & development
  Cc: Direct Rendering Infrastructure - Development, Joonas Lahtinen,
	Martin Hodo, Faith Ekstrand, Simona Vetter, Tvrtko Ursulin,
	Maarten Lankhorst, stable

After a successful BALANCE/PARALLEL_SUBMIT extension on context
creation, error during processing of next user extension leaks
the siblings[] array. Fix that.

Discovered using AI-assisted static analysis confirmed by
Intel Product Security.

Reported-by: Martin Hodo <martin.hodo@intel.com>
Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle create parameters (v5)")
Cc: Faith Ekstrand <faith.ekstrand@collabora.com>
Cc: Simona Vetter <simona.vetter@ffwll.ch>
Cc: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: <stable@vger.kernel.org> # v5.15+
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 22 +++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index aeafe1742d30..87fce2adfeef 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -769,8 +769,8 @@ static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
 		struct intel_engine_cs *engine;
 
 		if (copy_from_user(&ci, &user->engines[n], sizeof(ci))) {
-			kfree(set.engines);
-			return -EFAULT;
+			err = -EFAULT;
+			goto err;
 		}
 
 		memset(&set.engines[n], 0, sizeof(set.engines[n]));
@@ -786,8 +786,8 @@ static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
 			drm_dbg(&i915->drm,
 				"Invalid engine[%d]: { class:%d, instance:%d }\n",
 				n, ci.engine_class, ci.engine_instance);
-			kfree(set.engines);
-			return -ENOENT;
+			err = -ENOENT;
+			goto err;
 		}
 
 		set.engines[n].type = I915_GEM_ENGINE_TYPE_PHYSICAL;
@@ -800,15 +800,21 @@ static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
 					   set_proto_ctx_engines_extensions,
 					   ARRAY_SIZE(set_proto_ctx_engines_extensions),
 					   &set);
-	if (err) {
-		kfree(set.engines);
-		return err;
-	}
+	if (err)
+		goto err_extensions;
 
 	pc->num_user_engines = set.num_engines;
 	pc->user_engines = set.engines;
 
 	return 0;
+
+err_extensions:
+	for (n = 0; n < set.num_engines; n++)
+		kfree(set.engines[n].siblings);
+err:
+	kfree(set.engines);
+
+	return err;
 }
 
 static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915/gem: Do not leak siblings[] on proto context error
  2026-07-01  7:30 [PATCH] drm/i915/gem: Do not leak siblings[] on proto context error Joonas Lahtinen
@ 2026-07-01  7:41 ` sashiko-bot
  2026-07-01  8:08   ` Joonas Lahtinen
  2026-07-01 11:20 ` Maarten Lankhorst
  1 sibling, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-07-01  7:41 UTC (permalink / raw)
  To: Joonas Lahtinen; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Unchecked NULL pointer dereference of `pe->engine` in `set_proto_ctx_sseu()`.
--

commit 65a99ba2c873d452c04e00448f3e025e69552b68
Author: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>

drm/i915/gem: Do not leak siblings[] on proto context error

This commit fixes a memory leak in the context creation error path.
It ensures the siblings[] array is properly freed if an error happens
while processing user extensions.

> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> index aeafe1742d308..87fce2adfeefb 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
[ ... ]
> @@ -800,15 +800,21 @@ static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
>  					   set_proto_ctx_engines_extensions,
>  					   ARRAY_SIZE(set_proto_ctx_engines_extensions),
>  					   &set);
[ ... ]
> +err_extensions:
> +	for (n = 0; n < set.num_engines; n++)
> +		kfree(set.engines[n].siblings);
> +err:
> +	kfree(set.engines);
> +
> +	return err;
>  }
>  
>  static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,

[Severity: Critical]
This is a pre-existing issue, but could this cause a NULL pointer
dereference later in set_proto_ctx_sseu()?

If a user creates a proto-context and uses I915_CONTEXT_PARAM_ENGINES to
set an engine array with an I915_ENGINE_CLASS_INVALID entry,
set_proto_ctx_engines() initializes the slot to 0 and skips setting
pe->engine.

If the user then calls I915_CONTEXT_PARAM_SSEU and specifies the index of
that invalid engine, set_proto_ctx_sseu() executes this:

    idx = array_index_nospec(idx, pc->num_user_engines);
    pe = &pc->user_engines[idx];

    /* Only render engine supports RPCS configuration. */
    if (pe->engine->class != RENDER_CLASS)
        return -EINVAL;

Does pe->engine need to be checked for NULL before dereferencing it here, to
prevent a panic?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260701073030.44850-1-joonas.lahtinen@linux.intel.com?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915/gem: Do not leak siblings[] on proto context error
  2026-07-01  7:41 ` sashiko-bot
@ 2026-07-01  8:08   ` Joonas Lahtinen
  0 siblings, 0 replies; 4+ messages in thread
From: Joonas Lahtinen @ 2026-07-01  8:08 UTC (permalink / raw)
  To: sashiko-bot, sashiko-reviews; +Cc: dri-devel, intel-gfx

Quoting sashiko-bot@kernel.org (2026-07-01 10:41:36)
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [Critical] Unchecked NULL pointer dereference of `pe->engine` in `set_proto_ctx_sseu()`.
> --
> 
> commit 65a99ba2c873d452c04e00448f3e025e69552b68
> Author: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> 
> drm/i915/gem: Do not leak siblings[] on proto context error
> 
> This commit fixes a memory leak in the context creation error path.
> It ensures the siblings[] array is properly freed if an error happens
> while processing user extensions.
> 
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > index aeafe1742d308..87fce2adfeefb 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> [ ... ]
> > @@ -800,15 +800,21 @@ static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
> >                                          set_proto_ctx_engines_extensions,
> >                                          ARRAY_SIZE(set_proto_ctx_engines_extensions),
> >                                          &set);
> [ ... ]
> > +err_extensions:
> > +     for (n = 0; n < set.num_engines; n++)
> > +             kfree(set.engines[n].siblings);
> > +err:
> > +     kfree(set.engines);
> > +
> > +     return err;
> >  }
> >  
> >  static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,
> 
> [Severity: Critical]
> This is a pre-existing issue, but could this cause a NULL pointer
> dereference later in set_proto_ctx_sseu()?
> 
> If a user creates a proto-context and uses I915_CONTEXT_PARAM_ENGINES to
> set an engine array with an I915_ENGINE_CLASS_INVALID entry,
> set_proto_ctx_engines() initializes the slot to 0 and skips setting
> pe->engine.
> 
> If the user then calls I915_CONTEXT_PARAM_SSEU and specifies the index of
> that invalid engine, set_proto_ctx_sseu() executes this:
> 
>     idx = array_index_nospec(idx, pc->num_user_engines);
>     pe = &pc->user_engines[idx];
> 
>     /* Only render engine supports RPCS configuration. */
>     if (pe->engine->class != RENDER_CLASS)
>         return -EINVAL;
> 
> Does pe->engine need to be checked for NULL before dereferencing it here, to
> prevent a panic?

There is a fix submitted for this already at [1] given the issue was
already taken note of.

Regards, Joonas

[1] https://lore.kernel.org/intel-gfx/20260701075555.52142-1-joonas.lahtinen@linux.intel.com/

> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260701073030.44850-1-joonas.lahtinen@linux.intel.com?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/i915/gem: Do not leak siblings[] on proto context error
  2026-07-01  7:30 [PATCH] drm/i915/gem: Do not leak siblings[] on proto context error Joonas Lahtinen
  2026-07-01  7:41 ` sashiko-bot
@ 2026-07-01 11:20 ` Maarten Lankhorst
  1 sibling, 0 replies; 4+ messages in thread
From: Maarten Lankhorst @ 2026-07-01 11:20 UTC (permalink / raw)
  To: Joonas Lahtinen,
	Intel graphics driver community testing & development
  Cc: Direct Rendering Infrastructure - Development, Martin Hodo,
	Faith Ekstrand, Simona Vetter, Tvrtko Ursulin, stable

Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>

On 7/1/26 09:30, Joonas Lahtinen wrote:
> After a successful BALANCE/PARALLEL_SUBMIT extension on context
> creation, error during processing of next user extension leaks
> the siblings[] array. Fix that.
> 
> Discovered using AI-assisted static analysis confirmed by
> Intel Product Security.
> 
> Reported-by: Martin Hodo <martin.hodo@intel.com>
> Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle create parameters (v5)")
> Cc: Faith Ekstrand <faith.ekstrand@collabora.com>
> Cc: Simona Vetter <simona.vetter@ffwll.ch>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: <stable@vger.kernel.org> # v5.15+
> Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_context.c | 22 +++++++++++++--------
>  1 file changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> index aeafe1742d30..87fce2adfeef 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> @@ -769,8 +769,8 @@ static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
>  		struct intel_engine_cs *engine;
>  
>  		if (copy_from_user(&ci, &user->engines[n], sizeof(ci))) {
> -			kfree(set.engines);
> -			return -EFAULT;
> +			err = -EFAULT;
> +			goto err;
>  		}
>  
>  		memset(&set.engines[n], 0, sizeof(set.engines[n]));
> @@ -786,8 +786,8 @@ static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
>  			drm_dbg(&i915->drm,
>  				"Invalid engine[%d]: { class:%d, instance:%d }\n",
>  				n, ci.engine_class, ci.engine_instance);
> -			kfree(set.engines);
> -			return -ENOENT;
> +			err = -ENOENT;
> +			goto err;
>  		}
>  
>  		set.engines[n].type = I915_GEM_ENGINE_TYPE_PHYSICAL;
> @@ -800,15 +800,21 @@ static int set_proto_ctx_engines(struct drm_i915_file_private *fpriv,
>  					   set_proto_ctx_engines_extensions,
>  					   ARRAY_SIZE(set_proto_ctx_engines_extensions),
>  					   &set);
> -	if (err) {
> -		kfree(set.engines);
> -		return err;
> -	}
> +	if (err)
> +		goto err_extensions;
>  
>  	pc->num_user_engines = set.num_engines;
>  	pc->user_engines = set.engines;
>  
>  	return 0;
> +
> +err_extensions:
> +	for (n = 0; n < set.num_engines; n++)
> +		kfree(set.engines[n].siblings);
> +err:
> +	kfree(set.engines);
> +
> +	return err;
>  }
>  
>  static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-01 11:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01  7:30 [PATCH] drm/i915/gem: Do not leak siblings[] on proto context error Joonas Lahtinen
2026-07-01  7:41 ` sashiko-bot
2026-07-01  8:08   ` Joonas Lahtinen
2026-07-01 11:20 ` Maarten Lankhorst

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox