public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl
@ 2023-03-28  9:36 Min Li
  2023-03-28 13:08 ` Tvrtko Ursulin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Min Li @ 2023-03-28  9:36 UTC (permalink / raw)
  To: jani.nikula
  Cc: joonas.lahtinen, rodrigo.vivi, tvrtko.ursulin, airlied, daniel,
	intel-gfx, dri-devel, linux-kernel

Userspace can guess the id value and try to race oa_config object creation
with config remove, resulting in a use-after-free if we dereference the
object after unlocking the metrics_lock.  For that reason, unlocking the
metrics_lock must be done after we are done dereferencing the object.

Signed-off-by: Min Li <lm0963hack@gmail.com>
---
 drivers/gpu/drm/i915/i915_perf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 824a34ec0b83..93748ca2c5da 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -4634,13 +4634,13 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
 		err = oa_config->id;
 		goto sysfs_err;
 	}
-
-	mutex_unlock(&perf->metrics_lock);
+	id = oa_config->id;
 
 	drm_dbg(&perf->i915->drm,
 		"Added config %s id=%i\n", oa_config->uuid, oa_config->id);
+	mutex_unlock(&perf->metrics_lock);
 
-	return oa_config->id;
+	return id;
 
 sysfs_err:
 	mutex_unlock(&perf->metrics_lock);
-- 
2.25.1


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

* Re: [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl
  2023-03-28  9:36 [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl Min Li
@ 2023-03-28 13:08 ` Tvrtko Ursulin
  2023-03-29  0:48   ` Umesh Nerlige Ramappa
  2023-03-28 20:57 ` [Intel-gfx] " Andi Shyti
  2023-03-28 21:08 ` Andi Shyti
  2 siblings, 1 reply; 6+ messages in thread
From: Tvrtko Ursulin @ 2023-03-28 13:08 UTC (permalink / raw)
  To: Min Li, jani.nikula, Umesh Nerlige Ramappa, Lionel Landwerlin
  Cc: joonas.lahtinen, rodrigo.vivi, airlied, daniel, intel-gfx,
	dri-devel, linux-kernel


On 28/03/2023 10:36, Min Li wrote:
> Userspace can guess the id value and try to race oa_config object creation
> with config remove, resulting in a use-after-free if we dereference the
> object after unlocking the metrics_lock.  For that reason, unlocking the
> metrics_lock must be done after we are done dereferencing the object.
> 
> Signed-off-by: Min Li <lm0963hack@gmail.com>

Fixes: f89823c21224 ("drm/i915/perf: Implement I915_PERF_ADD/REMOVE_CONFIG interface")
Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Cc: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Cc: <stable@vger.kernel.org> # v4.14+

> ---
>   drivers/gpu/drm/i915/i915_perf.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
> index 824a34ec0b83..93748ca2c5da 100644
> --- a/drivers/gpu/drm/i915/i915_perf.c
> +++ b/drivers/gpu/drm/i915/i915_perf.c
> @@ -4634,13 +4634,13 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
>   		err = oa_config->id;
>   		goto sysfs_err;
>   	}
> -
> -	mutex_unlock(&perf->metrics_lock);
> +	id = oa_config->id;
>   
>   	drm_dbg(&perf->i915->drm,
>   		"Added config %s id=%i\n", oa_config->uuid, oa_config->id);
> +	mutex_unlock(&perf->metrics_lock);
>   
> -	return oa_config->id;
> +	return id;
>   
>   sysfs_err:
>   	mutex_unlock(&perf->metrics_lock);

LGTM.

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Umesh or Lionel could you please double check? I can merge if confirmed okay.

Regards,

Tvrtko

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

* Re: [Intel-gfx] [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl
  2023-03-28  9:36 [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl Min Li
  2023-03-28 13:08 ` Tvrtko Ursulin
@ 2023-03-28 20:57 ` Andi Shyti
  2023-03-28 21:08 ` Andi Shyti
  2 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2023-03-28 20:57 UTC (permalink / raw)
  To: Min Li
  Cc: jani.nikula, intel-gfx, linux-kernel, dri-devel, daniel,
	rodrigo.vivi, airlied

Hi Min,

On Tue, Mar 28, 2023 at 05:36:27PM +0800, Min Li wrote:
> Userspace can guess the id value and try to race oa_config object creation
> with config remove, resulting in a use-after-free if we dereference the
> object after unlocking the metrics_lock.  For that reason, unlocking the
> metrics_lock must be done after we are done dereferencing the object.
> 
> Signed-off-by: Min Li <lm0963hack@gmail.com>

Thank you for your patch!

Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>

Andi

> ---
>  drivers/gpu/drm/i915/i915_perf.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
> index 824a34ec0b83..93748ca2c5da 100644
> --- a/drivers/gpu/drm/i915/i915_perf.c
> +++ b/drivers/gpu/drm/i915/i915_perf.c
> @@ -4634,13 +4634,13 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
>  		err = oa_config->id;
>  		goto sysfs_err;
>  	}
> -
> -	mutex_unlock(&perf->metrics_lock);
> +	id = oa_config->id;
>  
>  	drm_dbg(&perf->i915->drm,
>  		"Added config %s id=%i\n", oa_config->uuid, oa_config->id);
> +	mutex_unlock(&perf->metrics_lock);
>  
> -	return oa_config->id;
> +	return id;
>  
>  sysfs_err:
>  	mutex_unlock(&perf->metrics_lock);
> -- 
> 2.25.1

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

* Re: [Intel-gfx] [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl
  2023-03-28  9:36 [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl Min Li
  2023-03-28 13:08 ` Tvrtko Ursulin
  2023-03-28 20:57 ` [Intel-gfx] " Andi Shyti
@ 2023-03-28 21:08 ` Andi Shyti
  2 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2023-03-28 21:08 UTC (permalink / raw)
  To: Min Li
  Cc: jani.nikula, intel-gfx, linux-kernel, dri-devel, daniel,
	rodrigo.vivi, airlied, stable

On Tue, Mar 28, 2023 at 05:36:27PM +0800, Min Li wrote:
> Userspace can guess the id value and try to race oa_config object creation
> with config remove, resulting in a use-after-free if we dereference the
> object after unlocking the metrics_lock.  For that reason, unlocking the
> metrics_lock must be done after we are done dereferencing the object.
> 
> Signed-off-by: Min Li <lm0963hack@gmail.com>

I think we should also add

Fixes: f89823c21224 ("drm/i915/perf: Implement I915_PERF_ADD/REMOVE_CONFIG interface")
Cc: <stable@vger.kernel.org> # v4.14+

Andi

> ---
>  drivers/gpu/drm/i915/i915_perf.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
> index 824a34ec0b83..93748ca2c5da 100644
> --- a/drivers/gpu/drm/i915/i915_perf.c
> +++ b/drivers/gpu/drm/i915/i915_perf.c
> @@ -4634,13 +4634,13 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
>  		err = oa_config->id;
>  		goto sysfs_err;
>  	}
> -
> -	mutex_unlock(&perf->metrics_lock);
> +	id = oa_config->id;
>  
>  	drm_dbg(&perf->i915->drm,
>  		"Added config %s id=%i\n", oa_config->uuid, oa_config->id);
> +	mutex_unlock(&perf->metrics_lock);
>  
> -	return oa_config->id;
> +	return id;
>  
>  sysfs_err:
>  	mutex_unlock(&perf->metrics_lock);
> -- 
> 2.25.1

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

* Re: [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl
  2023-03-28 13:08 ` Tvrtko Ursulin
@ 2023-03-29  0:48   ` Umesh Nerlige Ramappa
  2023-03-29  9:20     ` Tvrtko Ursulin
  0 siblings, 1 reply; 6+ messages in thread
From: Umesh Nerlige Ramappa @ 2023-03-29  0:48 UTC (permalink / raw)
  To: Tvrtko Ursulin
  Cc: Min Li, jani.nikula, Lionel Landwerlin, joonas.lahtinen,
	rodrigo.vivi, airlied, daniel, intel-gfx, dri-devel, linux-kernel

On Tue, Mar 28, 2023 at 02:08:47PM +0100, Tvrtko Ursulin wrote:
>
>On 28/03/2023 10:36, Min Li wrote:
>>Userspace can guess the id value and try to race oa_config object creation
>>with config remove, resulting in a use-after-free if we dereference the
>>object after unlocking the metrics_lock.  For that reason, unlocking the
>>metrics_lock must be done after we are done dereferencing the object.
>>
>>Signed-off-by: Min Li <lm0963hack@gmail.com>
>
>Fixes: f89823c21224 ("drm/i915/perf: Implement I915_PERF_ADD/REMOVE_CONFIG interface")
>Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
>Cc: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
>Cc: <stable@vger.kernel.org> # v4.14+
>
>>---
>>  drivers/gpu/drm/i915/i915_perf.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>>diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
>>index 824a34ec0b83..93748ca2c5da 100644
>>--- a/drivers/gpu/drm/i915/i915_perf.c
>>+++ b/drivers/gpu/drm/i915/i915_perf.c
>>@@ -4634,13 +4634,13 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
>>  		err = oa_config->id;
>>  		goto sysfs_err;
>>  	}
>>-
>>-	mutex_unlock(&perf->metrics_lock);
>>+	id = oa_config->id;
>>  	drm_dbg(&perf->i915->drm,
>>  		"Added config %s id=%i\n", oa_config->uuid, oa_config->id);
>>+	mutex_unlock(&perf->metrics_lock);
>>-	return oa_config->id;
>>+	return id;
>>  sysfs_err:
>>  	mutex_unlock(&perf->metrics_lock);
>
>LGTM.
>
>Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>
>Umesh or Lionel could you please double check? I can merge if confirmed okay.

LGTM,

Reviewed-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>

Thanks,
Umesh

>
>Regards,
>
>Tvrtko

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

* Re: [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl
  2023-03-29  0:48   ` Umesh Nerlige Ramappa
@ 2023-03-29  9:20     ` Tvrtko Ursulin
  0 siblings, 0 replies; 6+ messages in thread
From: Tvrtko Ursulin @ 2023-03-29  9:20 UTC (permalink / raw)
  To: Umesh Nerlige Ramappa
  Cc: Min Li, jani.nikula, Lionel Landwerlin, joonas.lahtinen,
	rodrigo.vivi, airlied, daniel, intel-gfx, dri-devel, linux-kernel


On 29/03/2023 01:48, Umesh Nerlige Ramappa wrote:
> On Tue, Mar 28, 2023 at 02:08:47PM +0100, Tvrtko Ursulin wrote:
>>
>> On 28/03/2023 10:36, Min Li wrote:
>>> Userspace can guess the id value and try to race oa_config object 
>>> creation
>>> with config remove, resulting in a use-after-free if we dereference the
>>> object after unlocking the metrics_lock.  For that reason, unlocking the
>>> metrics_lock must be done after we are done dereferencing the object.
>>>
>>> Signed-off-by: Min Li <lm0963hack@gmail.com>
>>
>> Fixes: f89823c21224 ("drm/i915/perf: Implement 
>> I915_PERF_ADD/REMOVE_CONFIG interface")
>> Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
>> Cc: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
>> Cc: <stable@vger.kernel.org> # v4.14+
>>
>>> ---
>>>  drivers/gpu/drm/i915/i915_perf.c | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/i915/i915_perf.c 
>>> b/drivers/gpu/drm/i915/i915_perf.c
>>> index 824a34ec0b83..93748ca2c5da 100644
>>> --- a/drivers/gpu/drm/i915/i915_perf.c
>>> +++ b/drivers/gpu/drm/i915/i915_perf.c
>>> @@ -4634,13 +4634,13 @@ int i915_perf_add_config_ioctl(struct 
>>> drm_device *dev, void *data,
>>>          err = oa_config->id;
>>>          goto sysfs_err;
>>>      }
>>> -
>>> -    mutex_unlock(&perf->metrics_lock);
>>> +    id = oa_config->id;
>>>      drm_dbg(&perf->i915->drm,
>>>          "Added config %s id=%i\n", oa_config->uuid, oa_config->id);
>>> +    mutex_unlock(&perf->metrics_lock);
>>> -    return oa_config->id;
>>> +    return id;
>>>  sysfs_err:
>>>      mutex_unlock(&perf->metrics_lock);
>>
>> LGTM.
>>
>> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>
>> Umesh or Lionel could you please double check? I can merge if 
>> confirmed okay.
> 
> LGTM,
> 
> Reviewed-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>

Pushed to drm-intel-gt-next, thanks for the fix and reviews!

Regards,

Tvrtko

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

end of thread, other threads:[~2023-03-29  9:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-28  9:36 [PATCH 1/1] drm/i915: fix race condition UAF in i915_perf_add_config_ioctl Min Li
2023-03-28 13:08 ` Tvrtko Ursulin
2023-03-29  0:48   ` Umesh Nerlige Ramappa
2023-03-29  9:20     ` Tvrtko Ursulin
2023-03-28 20:57 ` [Intel-gfx] " Andi Shyti
2023-03-28 21:08 ` Andi Shyti

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