ACPI: utils: Fix error path in acpi_evaluate_reference()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 7 Dec 2023 18:28:10 +0000 (19:28 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 7 Dec 2023 20:38:21 +0000 (21:38 +0100)
If a pointer to an uninitialized struct acpi_handle_list is passed to
acpi_evaluate_reference() and it decides to bail out early, either
because acpi_evaluate_object() fails, or because it produces invalid
data, the handles pointer from the struct acpi_handle_list will be
passed to kfree() and if it is not NULL, the kernel will crash on an
attempt to free unallocated memory.

Address this by moving the "end" label in acpi_evaluate_reference() to
the end of the function, which is sufficient, because no cleanup is
needed in that case.

Fixes: 2e57d10a6591 ("ACPI: utils: Dynamically determine acpi_handle_list size")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Woody Suwalski <terraluna977@gmail.com>
drivers/acpi/utils.c

index 28c75242fca9c456afb53ffa7b77758cd088ec6b..62944e35fcee2980446a743c0099c8bfc26cbf6e 100644 (file)
@@ -399,13 +399,13 @@ acpi_evaluate_reference(acpi_handle handle,
                acpi_handle_debug(list->handles[i], "Found in reference list\n");
        }
 
-end:
        if (ACPI_FAILURE(status)) {
                list->count = 0;
                kfree(list->handles);
                list->handles = NULL;
        }
 
+end:
        kfree(buffer.pointer);
 
        return status;