dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Fix potential spectre vulnerability
@ 2023-11-02 10:16 chentao
  2023-11-02 11:32 ` Tvrtko Ursulin
  0 siblings, 1 reply; 9+ messages in thread
From: chentao @ 2023-11-02 10:16 UTC (permalink / raw)
  To: jani.nikula, joonas.lahtinen, rodrigo.vivi, tvrtko.ursulin,
	airlied, daniel, andi.shyti, robdclark, jonathan.cavitt,
	andrzej.hajda, chris.p.wilson, alan.previn.teres.alexis
  Cc: chentao, intel-gfx, linux-kernel, dri-devel, kunwu.chan

Fix smatch warning:
drivers/gpu/drm/i915/gem/i915_gem_context.c:847 set_proto_ctx_sseu()
warn: potential spectre issue 'pc->user_engines' [r] (local cap)

Signed-off-by: chentao <chentao@kylinos.cn>
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index 9a9ff84c90d7..b2fdfc7ca4de 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -843,7 +843,7 @@ static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,
 
 		if (idx >= pc->num_user_engines)
 			return -EINVAL;
-
+		idx = array_index_nospec(idx, pc->num_user_engines);
 		pe = &pc->user_engines[idx];
 
 		/* Only render engine supports RPCS configuration. */
-- 
2.34.1


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

* Re: [PATCH] drm/i915: Fix potential spectre vulnerability
  2023-11-02 10:16 [PATCH] drm/i915: Fix potential spectre vulnerability chentao
@ 2023-11-02 11:32 ` Tvrtko Ursulin
  2023-11-03  0:07   ` Andi Shyti
                     ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Tvrtko Ursulin @ 2023-11-02 11:32 UTC (permalink / raw)
  To: chentao, jani.nikula, joonas.lahtinen, rodrigo.vivi, airlied,
	daniel, andi.shyti, robdclark, jonathan.cavitt, andrzej.hajda,
	chris.p.wilson, alan.previn.teres.alexis
  Cc: intel-gfx, linux-kernel, dri-devel, kunwu.chan


On 02/11/2023 10:16, chentao wrote:
> Fix smatch warning:
> drivers/gpu/drm/i915/gem/i915_gem_context.c:847 set_proto_ctx_sseu()
> warn: potential spectre issue 'pc->user_engines' [r] (local cap)
> 
> Signed-off-by: chentao <chentao@kylinos.cn>

I don't know if this is actually exploitable given the time deltas between the index is read from userspace and acted upon here, which is at least two ioctls apart. But I suppose no harm in fixing and for safety so we need to add:

Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle create parameters (v5)")
Cc: <stable@vger.kernel.org> # v5.15+

> ---
>   drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> index 9a9ff84c90d7..b2fdfc7ca4de 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> @@ -843,7 +843,7 @@ static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,
>   
>   		if (idx >= pc->num_user_engines)
>   			return -EINVAL;
> -

Just please refrain from random whitespace modifications like this blank line removal. If you resend without that you can add my r-b.

Regards,

Tvrtko

> +		idx = array_index_nospec(idx, pc->num_user_engines);
>   		pe = &pc->user_engines[idx];
>   
>   		/* Only render engine supports RPCS configuration. */

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

* Re: [PATCH] drm/i915: Fix potential spectre vulnerability
  2023-11-02 11:32 ` Tvrtko Ursulin
@ 2023-11-03  0:07   ` Andi Shyti
  2023-11-03  2:31   ` Kunwu Chan
  2023-11-03  2:32   ` [PATCH v2] " Kunwu Chan
  2 siblings, 0 replies; 9+ messages in thread
From: Andi Shyti @ 2023-11-03  0:07 UTC (permalink / raw)
  To: Tvrtko Ursulin
  Cc: robdclark, dri-devel, andi.shyti, chentao, kunwu.chan, intel-gfx,
	jonathan.cavitt, linux-kernel, alan.previn.teres.alexis,
	andrzej.hajda, chris.p.wilson, rodrigo.vivi

Hi,

On Thu, Nov 02, 2023 at 11:32:43AM +0000, Tvrtko Ursulin wrote:
> On 02/11/2023 10:16, chentao wrote:
> > Fix smatch warning:
> > drivers/gpu/drm/i915/gem/i915_gem_context.c:847 set_proto_ctx_sseu()
> > warn: potential spectre issue 'pc->user_engines' [r] (local cap)
> > 
> > Signed-off-by: chentao <chentao@kylinos.cn>
> 
> I don't know if this is actually exploitable given the time deltas between the index is read from userspace and acted upon here, which is at least two ioctls apart. But I suppose no harm in fixing and for safety so we need to add:
> 
> Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle create parameters (v5)")
> Cc: <stable@vger.kernel.org> # v5.15+

Is this a real fix? I don't mind adding it, though.

> > ---
> >   drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > index 9a9ff84c90d7..b2fdfc7ca4de 100644
> > --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> > @@ -843,7 +843,7 @@ static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,
> >   		if (idx >= pc->num_user_engines)
> >   			return -EINVAL;
> > -
> 
> Just please refrain from random whitespace modifications like this blank line removal. If you resend without that you can add my r-b.
> 
> Regards,
> 
> Tvrtko
> 
> > +		idx = array_index_nospec(idx, pc->num_user_engines);

idx has been assigned earlier, can we make it one single
assignment at the declaration?

Andi

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

* Re: [PATCH] drm/i915: Fix potential spectre vulnerability
  2023-11-02 11:32 ` Tvrtko Ursulin
  2023-11-03  0:07   ` Andi Shyti
@ 2023-11-03  2:31   ` Kunwu Chan
  2023-11-03  2:32   ` [PATCH v2] " Kunwu Chan
  2 siblings, 0 replies; 9+ messages in thread
From: Kunwu Chan @ 2023-11-03  2:31 UTC (permalink / raw)
  To: Tvrtko Ursulin, jani.nikula, joonas.lahtinen, rodrigo.vivi,
	airlied, daniel, andi.shyti, robdclark, jonathan.cavitt,
	andrzej.hajda, chris.p.wilson, alan.previn.teres.alexis
  Cc: intel-gfx, linux-kernel, dri-devel, kunwu.chan

Hi Tvrtko,
Thank you very much for your kind suggestion, I have modified it in 
accordance with your suggestion.

On 2023/11/2 19:32, Tvrtko Ursulin wrote:
> 
> On 02/11/2023 10:16, chentao wrote:
>> Fix smatch warning:
>> drivers/gpu/drm/i915/gem/i915_gem_context.c:847 set_proto_ctx_sseu()
>> warn: potential spectre issue 'pc->user_engines' [r] (local cap)
>>
>> Signed-off-by: chentao <chentao@kylinos.cn>
> 
> I don't know if this is actually exploitable given the time deltas 
> between the index is read from userspace and acted upon here, which is 
> at least two ioctls apart. But I suppose no harm in fixing and for 
> safety so we need to add:
> 
> Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle 
> create parameters (v5)")
> Cc: <stable@vger.kernel.org> # v5.15+
> 
>> ---
>>   drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c 
>> b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> index 9a9ff84c90d7..b2fdfc7ca4de 100644
>> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> @@ -843,7 +843,7 @@ static int set_proto_ctx_sseu(struct 
>> drm_i915_file_private *fpriv,
>>           if (idx >= pc->num_user_engines)
>>               return -EINVAL;
>> -
> 
> Just please refrain from random whitespace modifications like this blank 
> line removal. If you resend without that you can add my r-b.
> 
> Regards,
> 
> Tvrtko
> 
>> +        idx = array_index_nospec(idx, pc->num_user_engines);
>>           pe = &pc->user_engines[idx];
>>           /* Only render engine supports RPCS configuration. */

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

* [PATCH v2] drm/i915: Fix potential spectre vulnerability
  2023-11-02 11:32 ` Tvrtko Ursulin
  2023-11-03  0:07   ` Andi Shyti
  2023-11-03  2:31   ` Kunwu Chan
@ 2023-11-03  2:32   ` Kunwu Chan
  2023-11-03  6:56     ` Krzysztof Kozlowski
  2023-11-06  9:57     ` Andi Shyti
  2 siblings, 2 replies; 9+ messages in thread
From: Kunwu Chan @ 2023-11-03  2:32 UTC (permalink / raw)
  To: tvrtko.ursulin
  Cc: robdclark, andi.shyti, chentao, kunwu.chan, jonathan.cavitt,
	intel-gfx, alan.previn.teres.alexis, linux-kernel,
	chris.p.wilson, dri-devel, andrzej.hajda, rodrigo.vivi, stable

Fix smatch warning:
drivers/gpu/drm/i915/gem/i915_gem_context.c:847 set_proto_ctx_sseu()
warn: potential spectre issue 'pc->user_engines' [r] (local cap)

Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle create parameters (v5)")
Cc: <stable@vger.kernel.org> # v5.15+
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Suggested-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Link: https://lore.kernel.org/all/20231102101642.52988-1-chentao@kylinos.cn
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index 9a9ff84c90d7..e38f06a6e56e 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -844,6 +844,7 @@ static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,
 		if (idx >= pc->num_user_engines)
 			return -EINVAL;
 
+		idx = array_index_nospec(idx, pc->num_user_engines);
 		pe = &pc->user_engines[idx];
 
 		/* Only render engine supports RPCS configuration. */
-- 
2.34.1


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

* Re: [PATCH v2] drm/i915: Fix potential spectre vulnerability
  2023-11-03  2:32   ` [PATCH v2] " Kunwu Chan
@ 2023-11-03  6:56     ` Krzysztof Kozlowski
  2023-11-03  8:23       ` Tvrtko Ursulin
  2023-11-06  9:57     ` Andi Shyti
  1 sibling, 1 reply; 9+ messages in thread
From: Krzysztof Kozlowski @ 2023-11-03  6:56 UTC (permalink / raw)
  To: Kunwu Chan, tvrtko.ursulin
  Cc: robdclark, andrzej.hajda, alan.previn.teres.alexis, kunwu.chan,
	intel-gfx, jonathan.cavitt, linux-kernel, chris.p.wilson,
	rodrigo.vivi, dri-devel, andi.shyti, stable

On 03/11/2023 03:32, Kunwu Chan wrote:
> Fix smatch warning:
> drivers/gpu/drm/i915/gem/i915_gem_context.c:847 set_proto_ctx_sseu()
> warn: potential spectre issue 'pc->user_engines' [r] (local cap)
> 
> Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle create parameters (v5)")
> Cc: <stable@vger.kernel.org> # v5.15+
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> Suggested-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>

Where did you receive this tag? There is nothing under link below.
> Link: https://lore.kernel.org/all/20231102101642.52988-1-chentao@kylinos.cn



Best regards,
Krzysztof


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

* Re: [PATCH v2] drm/i915: Fix potential spectre vulnerability
  2023-11-03  6:56     ` Krzysztof Kozlowski
@ 2023-11-03  8:23       ` Tvrtko Ursulin
  0 siblings, 0 replies; 9+ messages in thread
From: Tvrtko Ursulin @ 2023-11-03  8:23 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Kunwu Chan
  Cc: robdclark, andrzej.hajda, alan.previn.teres.alexis, kunwu.chan,
	intel-gfx, jonathan.cavitt, linux-kernel, chris.p.wilson,
	rodrigo.vivi, dri-devel, andi.shyti, stable


On 03/11/2023 06:56, Krzysztof Kozlowski wrote:
> On 03/11/2023 03:32, Kunwu Chan wrote:
>> Fix smatch warning:
>> drivers/gpu/drm/i915/gem/i915_gem_context.c:847 set_proto_ctx_sseu()
>> warn: potential spectre issue 'pc->user_engines' [r] (local cap)
>>
>> Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle create parameters (v5)")
>> Cc: <stable@vger.kernel.org> # v5.15+
>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>> Suggested-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
>> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> 
> Where did you receive this tag? There is nothing under link below.
>> Link: https://lore.kernel.org/all/20231102101642.52988-1-chentao@kylinos.cn

It is fine, I gave the conditional r-b in 
https://lore.kernel.org/all/d300506c-ab82-4cc1-b750-61e54ec2ad9e@linux.intel.com/.

Suggested-by I did not and it is not true so I can drop it while applying.

Regards,

Tvrtko

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

* Re: [PATCH v2] drm/i915: Fix potential spectre vulnerability
  2023-11-03  2:32   ` [PATCH v2] " Kunwu Chan
  2023-11-03  6:56     ` Krzysztof Kozlowski
@ 2023-11-06  9:57     ` Andi Shyti
  2023-11-06 10:15       ` Tvrtko Ursulin
  1 sibling, 1 reply; 9+ messages in thread
From: Andi Shyti @ 2023-11-06  9:57 UTC (permalink / raw)
  To: Kunwu Chan
  Cc: tvrtko.ursulin, andi.shyti, alan.previn.teres.alexis, kunwu.chan,
	intel-gfx, jonathan.cavitt, linux-kernel, chris.p.wilson,
	dri-devel, andrzej.hajda, rodrigo.vivi, stable, robdclark

Hi Kunwu,

On Fri, Nov 03, 2023 at 10:32:57AM +0800, Kunwu Chan wrote:
> Fix smatch warning:
> drivers/gpu/drm/i915/gem/i915_gem_context.c:847 set_proto_ctx_sseu()
> warn: potential spectre issue 'pc->user_engines' [r] (local cap)
> 
> Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle create parameters (v5)")
> Cc: <stable@vger.kernel.org> # v5.15+
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> Suggested-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Link: https://lore.kernel.org/all/20231102101642.52988-1-chentao@kylinos.cn
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_context.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> index 9a9ff84c90d7..e38f06a6e56e 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
> @@ -844,6 +844,7 @@ static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,
>  		if (idx >= pc->num_user_engines)
>  			return -EINVAL;
>  
> +		idx = array_index_nospec(idx, pc->num_user_engines);

you ignored my comment, though.

Andi

>  		pe = &pc->user_engines[idx];
>  
>  		/* Only render engine supports RPCS configuration. */
> -- 
> 2.34.1

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

* Re: [PATCH v2] drm/i915: Fix potential spectre vulnerability
  2023-11-06  9:57     ` Andi Shyti
@ 2023-11-06 10:15       ` Tvrtko Ursulin
  0 siblings, 0 replies; 9+ messages in thread
From: Tvrtko Ursulin @ 2023-11-06 10:15 UTC (permalink / raw)
  To: Andi Shyti, Kunwu Chan
  Cc: robdclark, andrzej.hajda, alan.previn.teres.alexis, kunwu.chan,
	intel-gfx, jonathan.cavitt, linux-kernel, dri-devel,
	chris.p.wilson, rodrigo.vivi, stable


On 06/11/2023 09:57, Andi Shyti wrote:
> Hi Kunwu,
> 
> On Fri, Nov 03, 2023 at 10:32:57AM +0800, Kunwu Chan wrote:
>> Fix smatch warning:
>> drivers/gpu/drm/i915/gem/i915_gem_context.c:847 set_proto_ctx_sseu()
>> warn: potential spectre issue 'pc->user_engines' [r] (local cap)
>>
>> Fixes: d4433c7600f7 ("drm/i915/gem: Use the proto-context to handle create parameters (v5)")
>> Cc: <stable@vger.kernel.org> # v5.15+
>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>> Suggested-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
>> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
>> Link: https://lore.kernel.org/all/20231102101642.52988-1-chentao@kylinos.cn
>> ---
>>   drivers/gpu/drm/i915/gem/i915_gem_context.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> index 9a9ff84c90d7..e38f06a6e56e 100644
>> --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
>> @@ -844,6 +844,7 @@ static int set_proto_ctx_sseu(struct drm_i915_file_private *fpriv,
>>   		if (idx >= pc->num_user_engines)
>>   			return -EINVAL;
>>   
>> +		idx = array_index_nospec(idx, pc->num_user_engines);
> 
> you ignored my comment, though.

Sorry it was me, I considered it fine as is given it is the same pattern 
as elsewhere in the file. I've merged the patch btw.

Regards,

Tvrtko

> 
> Andi
> 
>>   		pe = &pc->user_engines[idx];
>>   
>>   		/* Only render engine supports RPCS configuration. */
>> -- 
>> 2.34.1

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

end of thread, other threads:[~2023-11-06 10:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-02 10:16 [PATCH] drm/i915: Fix potential spectre vulnerability chentao
2023-11-02 11:32 ` Tvrtko Ursulin
2023-11-03  0:07   ` Andi Shyti
2023-11-03  2:31   ` Kunwu Chan
2023-11-03  2:32   ` [PATCH v2] " Kunwu Chan
2023-11-03  6:56     ` Krzysztof Kozlowski
2023-11-03  8:23       ` Tvrtko Ursulin
2023-11-06  9:57     ` Andi Shyti
2023-11-06 10:15       ` Tvrtko Ursulin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).