All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amd/amdgpu: Fix GPR read from debugfs (v2)
@ 2020-03-11 20:33 Tom St Denis
  2020-03-11 21:16 ` Alex Deucher
  0 siblings, 1 reply; 2+ messages in thread
From: Tom St Denis @ 2020-03-11 20:33 UTC (permalink / raw)
  To: amd-gfx; +Cc: Tom St Denis, Christian König

The offset into the array was specified in bytes but should
be in terms of 32-bit words.  Also prevent large reads that
would also cause a buffer overread.

v2:  Read from correct offset from internal storage buffer.

Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
Acked-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
index 00942afc4e13..02bb1be11ffe 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -784,11 +784,11 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
 	ssize_t result = 0;
 	uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
 
-	if (size & 3 || *pos & 3)
+	if (size > 4096 || size & 3 || *pos & 3)
 		return -EINVAL;
 
 	/* decode offset */
-	offset = *pos & GENMASK_ULL(11, 0);
+	offset = (*pos & GENMASK_ULL(11, 0)) >> 2;
 	se = (*pos & GENMASK_ULL(19, 12)) >> 12;
 	sh = (*pos & GENMASK_ULL(27, 20)) >> 20;
 	cu = (*pos & GENMASK_ULL(35, 28)) >> 28;
@@ -826,7 +826,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
 	while (size) {
 		uint32_t value;
 
-		value = data[offset++];
+		value = data[result >> 2];
 		r = put_user(value, (uint32_t *)buf);
 		if (r) {
 			result = r;
-- 
2.24.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

* Re: [PATCH] drm/amd/amdgpu: Fix GPR read from debugfs (v2)
  2020-03-11 20:33 [PATCH] drm/amd/amdgpu: Fix GPR read from debugfs (v2) Tom St Denis
@ 2020-03-11 21:16 ` Alex Deucher
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Deucher @ 2020-03-11 21:16 UTC (permalink / raw)
  To: Tom St Denis; +Cc: Christian König, amd-gfx list

On Wed, Mar 11, 2020 at 4:33 PM Tom St Denis <tom.stdenis@amd.com> wrote:
>
> The offset into the array was specified in bytes but should
> be in terms of 32-bit words.  Also prevent large reads that
> would also cause a buffer overread.
>
> v2:  Read from correct offset from internal storage buffer.
>
> Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
> Acked-by: Christian König <christian.koenig@amd.com>

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> index 00942afc4e13..02bb1be11ffe 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
> @@ -784,11 +784,11 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
>         ssize_t result = 0;
>         uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
>
> -       if (size & 3 || *pos & 3)
> +       if (size > 4096 || size & 3 || *pos & 3)
>                 return -EINVAL;
>
>         /* decode offset */
> -       offset = *pos & GENMASK_ULL(11, 0);
> +       offset = (*pos & GENMASK_ULL(11, 0)) >> 2;
>         se = (*pos & GENMASK_ULL(19, 12)) >> 12;
>         sh = (*pos & GENMASK_ULL(27, 20)) >> 20;
>         cu = (*pos & GENMASK_ULL(35, 28)) >> 28;
> @@ -826,7 +826,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
>         while (size) {
>                 uint32_t value;
>
> -               value = data[offset++];
> +               value = data[result >> 2];
>                 r = put_user(value, (uint32_t *)buf);
>                 if (r) {
>                         result = r;
> --
> 2.24.1
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

end of thread, other threads:[~2020-03-11 21:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 20:33 [PATCH] drm/amd/amdgpu: Fix GPR read from debugfs (v2) Tom St Denis
2020-03-11 21:16 ` Alex Deucher

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.