On Fri, Oct 11, 2024 at 1:33 PM Mario Limonciello <mario.limonciello@xxxxxxx> wrote: > > If a BIOS provides bad data in response to an ATIF method call > this causes a NULL pointer dereference in the caller. > > ``` > ? show_regs (arch/x86/kernel/dumpstack.c:478 (discriminator 1)) > ? __die (arch/x86/kernel/dumpstack.c:423 arch/x86/kernel/dumpstack.c:434) > ? page_fault_oops (arch/x86/mm/fault.c:544 (discriminator 2) arch/x86/mm/fault.c:705 (discriminator 2)) > ? do_user_addr_fault (arch/x86/mm/fault.c:440 (discriminator 1) arch/x86/mm/fault.c:1232 (discriminator 1)) > ? acpi_ut_update_object_reference (drivers/acpi/acpica/utdelete.c:642) > ? exc_page_fault (arch/x86/mm/fault.c:1542) > ? asm_exc_page_fault (./arch/x86/include/asm/idtentry.h:623) > ? amdgpu_atif_query_backlight_caps.constprop.0 (drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c:387 (discriminator 2)) amdgpu > ? amdgpu_atif_query_backlight_caps.constprop.0 (drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c:386 (discriminator 1)) amdgpu > ``` > > It has been encountered on at least one system, so guard for it. > > Cc: stable@xxxxxxxxxxxxxxx > Fixes: d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)") > Signed-off-by: Mario Limonciello <mario.limonciello@xxxxxxx> Acked-by: Alex Deucher <alexander.deucher@xxxxxxx> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c > index f85ace0384d2..1f5a296f5ed2 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c > @@ -147,6 +147,7 @@ static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif, > struct acpi_buffer *params) > { > acpi_status status; > + union acpi_object *obj; > union acpi_object atif_arg_elements[2]; > struct acpi_object_list atif_arg; > struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; > @@ -169,16 +170,24 @@ static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif, > > status = acpi_evaluate_object(atif->handle, NULL, &atif_arg, > &buffer); > + obj = (union acpi_object *)buffer.pointer; > > - /* Fail only if calling the method fails and ATIF is supported */ > + /* Fail if calling the method fails and ATIF is supported */ > if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { > DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n", > acpi_format_exception(status)); > - kfree(buffer.pointer); > + kfree(obj); > return NULL; > } > > - return buffer.pointer; > + if (obj->type != ACPI_TYPE_BUFFER) { > + DRM_DEBUG_DRIVER("bad object returned from ATIF: %d\n", > + obj->type); > + kfree(obj); > + return NULL; > + } > + > + return obj; > } > > /** > -- > 2.43.0 >