All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Use copy_from_user() in fence copying
@ 2017-12-06 20:28 ` Kees Cook
  0 siblings, 0 replies; 8+ messages in thread
From: Kees Cook @ 2017-12-06 20:28 UTC (permalink / raw)
  To: Jason Ekstrand; +Cc: Chris Wilson, intel-gfx, dri-devel, linux-kernel

There's no good reason to separate the access_ok() from the copy,
especially since the access_ok() size is hard-coded instead of using
sizeof(). Instead, just use copy_from_user() directly.

Fixes: cf6e7bac6357 ("drm/i915: Add support for drm syncobjs")
Cc: Jason Ekstrand <jason@jlekstrand.net>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 435ed95df144..1da703213b17 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -2087,8 +2087,6 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
 		return ERR_PTR(-EINVAL);
 
 	user = u64_to_user_ptr(args->cliprects_ptr);
-	if (!access_ok(VERIFY_READ, user, nfences * 2 * sizeof(u32)))
-		return ERR_PTR(-EFAULT);
 
 	fences = kvmalloc_array(args->num_cliprects, sizeof(*fences),
 				__GFP_NOWARN | GFP_KERNEL);
@@ -2099,7 +2097,7 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
 		struct drm_i915_gem_exec_fence fence;
 		struct drm_syncobj *syncobj;
 
-		if (__copy_from_user(&fence, user++, sizeof(fence))) {
+		if (copy_from_user(&fence, user++, sizeof(fence))) {
 			err = -EFAULT;
 			goto err;
 		}
-- 
2.7.4


-- 
Kees Cook
Pixel Security

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

* [PATCH] drm/i915: Use copy_from_user() in fence copying
@ 2017-12-06 20:28 ` Kees Cook
  0 siblings, 0 replies; 8+ messages in thread
From: Kees Cook @ 2017-12-06 20:28 UTC (permalink / raw)
  To: Jason Ekstrand; +Cc: intel-gfx, linux-kernel, dri-devel

There's no good reason to separate the access_ok() from the copy,
especially since the access_ok() size is hard-coded instead of using
sizeof(). Instead, just use copy_from_user() directly.

Fixes: cf6e7bac6357 ("drm/i915: Add support for drm syncobjs")
Cc: Jason Ekstrand <jason@jlekstrand.net>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 435ed95df144..1da703213b17 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -2087,8 +2087,6 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
 		return ERR_PTR(-EINVAL);
 
 	user = u64_to_user_ptr(args->cliprects_ptr);
-	if (!access_ok(VERIFY_READ, user, nfences * 2 * sizeof(u32)))
-		return ERR_PTR(-EFAULT);
 
 	fences = kvmalloc_array(args->num_cliprects, sizeof(*fences),
 				__GFP_NOWARN | GFP_KERNEL);
@@ -2099,7 +2097,7 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
 		struct drm_i915_gem_exec_fence fence;
 		struct drm_syncobj *syncobj;
 
-		if (__copy_from_user(&fence, user++, sizeof(fence))) {
+		if (copy_from_user(&fence, user++, sizeof(fence))) {
 			err = -EFAULT;
 			goto err;
 		}
-- 
2.7.4


-- 
Kees Cook
Pixel Security
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* RE: [PATCH] drm/i915: Use copy_from_user() in fence copying
  2017-12-06 20:28 ` Kees Cook
  (?)
@ 2017-12-08 10:17 ` David Laight
  2017-12-08 21:10     ` Kees Cook
  -1 siblings, 1 reply; 8+ messages in thread
From: David Laight @ 2017-12-08 10:17 UTC (permalink / raw)
  To: 'Kees Cook', Jason Ekstrand
  Cc: Chris Wilson, intel-gfx, dri-devel, linux-kernel

From: Kees Cook
> Sent: 06 December 2017 20:29
>
> There's no good reason to separate the access_ok() from the copy,
> especially since the access_ok() size is hard-coded instead of using
> sizeof(). Instead, just use copy_from_user() directly.

Looks like an optimisation to save doing the access_ok() check
for every 'fence'.

OTOH 'user copy hardening' probably makes a much larger performance
degradation on this kind of code.
(Might be ok here because &fence probably refers to something in the
current stack frame.)

	David

> Fixes: cf6e7bac6357 ("drm/i915: Add support for drm syncobjs")
> Cc: Jason Ekstrand <jason@jlekstrand.net>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> index 435ed95df144..1da703213b17 100644
> --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> @@ -2087,8 +2087,6 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
>  		return ERR_PTR(-EINVAL);
> 
>  	user = u64_to_user_ptr(args->cliprects_ptr);
> -	if (!access_ok(VERIFY_READ, user, nfences * 2 * sizeof(u32)))
> -		return ERR_PTR(-EFAULT);
> 
>  	fences = kvmalloc_array(args->num_cliprects, sizeof(*fences),
>  				__GFP_NOWARN | GFP_KERNEL);
> @@ -2099,7 +2097,7 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
>  		struct drm_i915_gem_exec_fence fence;
>  		struct drm_syncobj *syncobj;
> 
> -		if (__copy_from_user(&fence, user++, sizeof(fence))) {
> +		if (copy_from_user(&fence, user++, sizeof(fence))) {
>  			err = -EFAULT;
>  			goto err;
>  		}
> --
> 2.7.4
> 
> 
> --
> Kees Cook
> Pixel Security

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

* Re: [PATCH] drm/i915: Use copy_from_user() in fence copying
  2017-12-08 10:17 ` David Laight
@ 2017-12-08 21:10     ` Kees Cook
  0 siblings, 0 replies; 8+ messages in thread
From: Kees Cook @ 2017-12-08 21:10 UTC (permalink / raw)
  To: David Laight
  Cc: Jason Ekstrand, Chris Wilson, intel-gfx, dri-devel, linux-kernel

On Fri, Dec 8, 2017 at 2:17 AM, David Laight <David.Laight@aculab.com> wrote:
> From: Kees Cook
>> Sent: 06 December 2017 20:29
>>
>> There's no good reason to separate the access_ok() from the copy,
>> especially since the access_ok() size is hard-coded instead of using
>> sizeof(). Instead, just use copy_from_user() directly.
>
> Looks like an optimisation to save doing the access_ok() check
> for every 'fence'.

If it really makes a difference, okay, but access_ok() checks are fast. :P

> OTOH 'user copy hardening' probably makes a much larger performance
> degradation on this kind of code.
> (Might be ok here because &fence probably refers to something in the
> current stack frame.)

Well, the good news there is that it's using sizeof(fence), so no
hardening check is done (it's not a size that changes at runtime).
What I didn't like is that the access_ok() doesn't use sizeof(fence)
(it is currently correct: 2 u32s == sizeof(fence)) but that kind of
fragility keeps me up at night. ;)

So, fixing either would be fine, but if we're going to touch it, it
seems best to just do away with the __copy_*() usage instead.

-Kees


>
>         David
>
>> Fixes: cf6e7bac6357 ("drm/i915: Add support for drm syncobjs")
>> Cc: Jason Ekstrand <jason@jlekstrand.net>
>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>>  drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 +---
>>  1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
>> index 435ed95df144..1da703213b17 100644
>> --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
>> +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
>> @@ -2087,8 +2087,6 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
>>               return ERR_PTR(-EINVAL);
>>
>>       user = u64_to_user_ptr(args->cliprects_ptr);
>> -     if (!access_ok(VERIFY_READ, user, nfences * 2 * sizeof(u32)))
>> -             return ERR_PTR(-EFAULT);
>>
>>       fences = kvmalloc_array(args->num_cliprects, sizeof(*fences),
>>                               __GFP_NOWARN | GFP_KERNEL);
>> @@ -2099,7 +2097,7 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
>>               struct drm_i915_gem_exec_fence fence;
>>               struct drm_syncobj *syncobj;
>>
>> -             if (__copy_from_user(&fence, user++, sizeof(fence))) {
>> +             if (copy_from_user(&fence, user++, sizeof(fence))) {
>>                       err = -EFAULT;
>>                       goto err;
>>               }
>> --
>> 2.7.4
>>
>>
>> --
>> Kees Cook
>> Pixel Security



-- 
Kees Cook
Pixel Security

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

* Re: [PATCH] drm/i915: Use copy_from_user() in fence copying
@ 2017-12-08 21:10     ` Kees Cook
  0 siblings, 0 replies; 8+ messages in thread
From: Kees Cook @ 2017-12-08 21:10 UTC (permalink / raw)
  To: David Laight; +Cc: linux-kernel, intel-gfx, dri-devel

On Fri, Dec 8, 2017 at 2:17 AM, David Laight <David.Laight@aculab.com> wrote:
> From: Kees Cook
>> Sent: 06 December 2017 20:29
>>
>> There's no good reason to separate the access_ok() from the copy,
>> especially since the access_ok() size is hard-coded instead of using
>> sizeof(). Instead, just use copy_from_user() directly.
>
> Looks like an optimisation to save doing the access_ok() check
> for every 'fence'.

If it really makes a difference, okay, but access_ok() checks are fast. :P

> OTOH 'user copy hardening' probably makes a much larger performance
> degradation on this kind of code.
> (Might be ok here because &fence probably refers to something in the
> current stack frame.)

Well, the good news there is that it's using sizeof(fence), so no
hardening check is done (it's not a size that changes at runtime).
What I didn't like is that the access_ok() doesn't use sizeof(fence)
(it is currently correct: 2 u32s == sizeof(fence)) but that kind of
fragility keeps me up at night. ;)

So, fixing either would be fine, but if we're going to touch it, it
seems best to just do away with the __copy_*() usage instead.

-Kees


>
>         David
>
>> Fixes: cf6e7bac6357 ("drm/i915: Add support for drm syncobjs")
>> Cc: Jason Ekstrand <jason@jlekstrand.net>
>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>>  drivers/gpu/drm/i915/i915_gem_execbuffer.c | 4 +---
>>  1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
>> index 435ed95df144..1da703213b17 100644
>> --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
>> +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
>> @@ -2087,8 +2087,6 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
>>               return ERR_PTR(-EINVAL);
>>
>>       user = u64_to_user_ptr(args->cliprects_ptr);
>> -     if (!access_ok(VERIFY_READ, user, nfences * 2 * sizeof(u32)))
>> -             return ERR_PTR(-EFAULT);
>>
>>       fences = kvmalloc_array(args->num_cliprects, sizeof(*fences),
>>                               __GFP_NOWARN | GFP_KERNEL);
>> @@ -2099,7 +2097,7 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
>>               struct drm_i915_gem_exec_fence fence;
>>               struct drm_syncobj *syncobj;
>>
>> -             if (__copy_from_user(&fence, user++, sizeof(fence))) {
>> +             if (copy_from_user(&fence, user++, sizeof(fence))) {
>>                       err = -EFAULT;
>>                       goto err;
>>               }
>> --
>> 2.7.4
>>
>>
>> --
>> Kees Cook
>> Pixel Security



-- 
Kees Cook
Pixel Security
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* Re: [Intel-gfx] [PATCH] drm/i915: Use copy_from_user() in fence copying
  2017-12-06 20:28 ` Kees Cook
@ 2017-12-11  9:34   ` Joonas Lahtinen
  -1 siblings, 0 replies; 8+ messages in thread
From: Joonas Lahtinen @ 2017-12-11  9:34 UTC (permalink / raw)
  To: Kees Cook, Jason Ekstrand; +Cc: intel-gfx, linux-kernel, dri-devel

On Wed, 2017-12-06 at 12:28 -0800, Kees Cook wrote:
> There's no good reason to separate the access_ok() from the copy,
> especially since the access_ok() size is hard-coded instead of using
> sizeof(). Instead, just use copy_from_user() directly.
> 
> Fixes: cf6e7bac6357 ("drm/i915: Add support for drm syncobjs")

There's been request to reduce the amount of Fixes: tags that are not
actually fixing bugs. This seems more like an optimization.

References: has been suggested for these cases instead.

Regards, Joonas
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation

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

* Re: [PATCH] drm/i915: Use copy_from_user() in fence copying
@ 2017-12-11  9:34   ` Joonas Lahtinen
  0 siblings, 0 replies; 8+ messages in thread
From: Joonas Lahtinen @ 2017-12-11  9:34 UTC (permalink / raw)
  To: Kees Cook, Jason Ekstrand; +Cc: intel-gfx, linux-kernel, dri-devel

On Wed, 2017-12-06 at 12:28 -0800, Kees Cook wrote:
> There's no good reason to separate the access_ok() from the copy,
> especially since the access_ok() size is hard-coded instead of using
> sizeof(). Instead, just use copy_from_user() directly.
> 
> Fixes: cf6e7bac6357 ("drm/i915: Add support for drm syncobjs")

There's been request to reduce the amount of Fixes: tags that are not
actually fixing bugs. This seems more like an optimization.

References: has been suggested for these cases instead.

Regards, Joonas
-- 
Joonas Lahtinen
Open Source Technology Center
Intel Corporation
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* RE: [PATCH] drm/i915: Use copy_from_user() in fence copying
  2017-12-08 21:10     ` Kees Cook
  (?)
@ 2017-12-11  9:41     ` David Laight
  -1 siblings, 0 replies; 8+ messages in thread
From: David Laight @ 2017-12-11  9:41 UTC (permalink / raw)
  To: 'Kees Cook'
  Cc: Jason Ekstrand, Chris Wilson, intel-gfx, dri-devel, linux-kernel

From: Kees Cook
> Sent: 08 December 2017 21:10
> >> There's no good reason to separate the access_ok() from the copy,
> >> especially since the access_ok() size is hard-coded instead of using
> >> sizeof(). Instead, just use copy_from_user() directly.
> >
> > Looks like an optimisation to save doing the access_ok() check
> > for every 'fence'.
> 
> If it really makes a difference, okay, but access_ok() checks are fast. :P

Not compared to get_user() :-)

	David

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

end of thread, other threads:[~2017-12-11  9:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-06 20:28 [PATCH] drm/i915: Use copy_from_user() in fence copying Kees Cook
2017-12-06 20:28 ` Kees Cook
2017-12-08 10:17 ` David Laight
2017-12-08 21:10   ` Kees Cook
2017-12-08 21:10     ` Kees Cook
2017-12-11  9:41     ` David Laight
2017-12-11  9:34 ` [Intel-gfx] " Joonas Lahtinen
2017-12-11  9:34   ` Joonas Lahtinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.