Skip to content

Commit 5bbc660

Browse files
Tom St Denisalexdeucher
authored andcommitted
drm/amd/amdgpu: Fix GPR read from debugfs (v2)
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 <[email protected]> Acked-by: Christian König <[email protected]> Reviewed-by: Alex Deucher <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Cc: [email protected]
1 parent b55dbe5 commit 5bbc660

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,11 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
781781
ssize_t result = 0;
782782
uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
783783

784-
if (size & 3 || *pos & 3)
784+
if (size > 4096 || size & 3 || *pos & 3)
785785
return -EINVAL;
786786

787787
/* decode offset */
788-
offset = *pos & GENMASK_ULL(11, 0);
788+
offset = (*pos & GENMASK_ULL(11, 0)) >> 2;
789789
se = (*pos & GENMASK_ULL(19, 12)) >> 12;
790790
sh = (*pos & GENMASK_ULL(27, 20)) >> 20;
791791
cu = (*pos & GENMASK_ULL(35, 28)) >> 28;
@@ -823,7 +823,7 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
823823
while (size) {
824824
uint32_t value;
825825

826-
value = data[offset++];
826+
value = data[result >> 2];
827827
r = put_user(value, (uint32_t *)buf);
828828
if (r) {
829829
result = r;

0 commit comments

Comments
 (0)