Skip to contentSkip to conversation

drm/amdgpu: Add checks to vbios fetch through ATRM

PATCH In review Lijo Lazar 2 participants 2 messages Jun 15

Subsystems (2)
lore
Share & tools
lore

Lijo Lazar

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Add checks to vbios fetch through ATRM

Check if a valid buffer object is returned after ATRM call. Also, match the buffer length against requested size before copying.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +8 -2
index aa039e148a5e..3ebdd792feec 100644
@@ -296,8 +296,14 @@ static int amdgpu_atrm_call(acpi_handle atrm_handle, uint8_t *bios,
 	}
 
 	obj = (union acpi_object *)buffer.pointer;
-	memcpy(bios+offset, obj->buffer.pointer, obj->buffer.length);
-	len = obj->buffer.length;
+	if (!obj || obj->type != ACPI_TYPE_BUFFER) {
+		DRM_ERROR("ATRM returned an invalid object\n");
+		kfree(buffer.pointer);
+		return -EINVAL;
+	}
+
+	len = min_t(size_t, obj->buffer.length, len);
+	memcpy(bios+offset, obj->buffer.pointer, len);
 	kfree(buffer.pointer);
 	return len;
 }
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Lijo Lazar

Check if a valid buffer object is returned after ATRM call. Also, match the buffer length against requested size before copying.

Quoted 28 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +8 -3
index aa039e148a5e..3ebdd792feec 100644
@@ -296,8 +296,14 @@ static int amdgpu_atrm_call(acpi_handle atrm_handle, uint8_t *bios,
        }
 
        obj = (union acpi_object *)buffer.pointer;
-       memcpy(bios+offset, obj->buffer.pointer, obj->buffer.length);
-       len = obj->buffer.length;
+       if (!obj || obj->type != ACPI_TYPE_BUFFER) {
+               DRM_ERROR("ATRM returned an invalid object\n");
+               kfree(buffer.pointer);
+               return -EINVAL;
+       }
+
+       len = min_t(size_t, obj->buffer.length, len);
+       memcpy(bios+offset, obj->buffer.pointer, len);
        kfree(buffer.pointer);
        return len;
 }
--

2.49.0