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 <[email protected]>
---
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
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 <[email protected]>
Fixes: f89823c21224 ("drm/i915/perf: Implement I915_PERF_ADD/REMOVE_CONFIG interface")
Cc: Lionel Landwerlin <[email protected]>
Cc: Umesh Nerlige Ramappa <[email protected]>
Cc: <[email protected]> # 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 <[email protected]>
Umesh or Lionel could you please double check? I can merge if confirmed okay.
Regards,
Tvrtko
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 <[email protected]>
Thank you for your patch!
Reviewed-by: Andi Shyti <[email protected]>
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
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 <[email protected]>
I think we should also add
Fixes: f89823c21224 ("drm/i915/perf: Implement I915_PERF_ADD/REMOVE_CONFIG interface")
Cc: <[email protected]> # 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
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 <[email protected]>
>
>Fixes: f89823c21224 ("drm/i915/perf: Implement I915_PERF_ADD/REMOVE_CONFIG interface")
>Cc: Lionel Landwerlin <[email protected]>
>Cc: Umesh Nerlige Ramappa <[email protected]>
>Cc: <[email protected]> # 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 <[email protected]>
>
>Umesh or Lionel could you please double check? I can merge if confirmed okay.
LGTM,
Reviewed-by: Umesh Nerlige Ramappa <[email protected]>
Thanks,
Umesh
>
>Regards,
>
>Tvrtko
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 <[email protected]>
>>
>> Fixes: f89823c21224 ("drm/i915/perf: Implement
>> I915_PERF_ADD/REMOVE_CONFIG interface")
>> Cc: Lionel Landwerlin <[email protected]>
>> Cc: Umesh Nerlige Ramappa <[email protected]>
>> Cc: <[email protected]> # 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 <[email protected]>
>>
>> Umesh or Lionel could you please double check? I can merge if
>> confirmed okay.
>
> LGTM,
>
> Reviewed-by: Umesh Nerlige Ramappa <[email protected]>
Pushed to drm-intel-gt-next, thanks for the fix and reviews!
Regards,
Tvrtko