drm/radeon: validate ATRM return buffer type and length
Subsystems (3)
PATCH 1/1 drm/radeon: validate ATRM return buffer type and length
From: Tristan Madani <[email protected]>
radeon_atrm_call() copies the ACPI ATRM method return data without checking that the returned object is actually a buffer or that its length fits within the caller-provided size. If the ATRM method returns a non-buffer object type or an oversized buffer, the memcpy writes past the destination bounds.
Add a NULL pointer check and ACPI_TYPE_BUFFER type validation before accessing the buffer fields, and clamp the copy length to the requested size. This matches the validation already present in the amdgpu counterpart amdgpu_atrm_call().
--- drivers/gpu/drm/radeon/radeon_bios.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_bios.c +7 -2
@@ -183,8 +183,13 @@ static int radeon_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 ) { +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.47.3
Reviewed and applied. Thanks!
Quoted 44 lines · Tristan Madani
From: Tristan Madani <[email protected]>
radeon_atrm_call()copies the ACPI ATRM method return data without checking that the returned object is actually a buffer or that its length fits within the caller-provided size. If the ATRM method returns a non-buffer object type or an oversized buffer, the memcpy writes past the destination bounds.Add a NULL pointer check and
ACPI_TYPE_BUFFERtype validation before accessing the buffer fields, and clamp the copy length to the requested size. This matches the validation already present in the amdgpu counterpartamdgpu_atrm_call().Fixes c61e2775873f ("drm/radeon: split ATRM support out from the ATPX handler (v3)")Signed-off-by Tristan Madani <[email protected]>--- drivers/gpu/drm/radeon/radeon_bios.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/radeon/radeon_bios.c +7
-3@@ -183,8 +183,13 @@ static int radeon_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 ) { +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.47.3