[v2] drm/i915: Fix potential spectre vulnerability

Message ID 20231103023257.58199-1-chentao@kylinos.cn
State New
Headers
Series [v2] drm/i915: Fix potential spectre vulnerability |

Commit Message

Kunwu Chan Nov. 3, 2023, 2:32 a.m. UTC
  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(+)
  

Comments

Krzysztof Kozlowski Nov. 3, 2023, 6:56 a.m. UTC | #1
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
  
Tvrtko Ursulin Nov. 3, 2023, 8:23 a.m. UTC | #2
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
  
Andi Shyti Nov. 6, 2023, 9:57 a.m. UTC | #3
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
  
Tvrtko Ursulin Nov. 6, 2023, 10:15 a.m. UTC | #4
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
  

Patch

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. */