[SRU][M][PATCH v5 2/2] ACPI: utils: Fix error path in acpi_evaluate_reference()

Ivan Hu ivan.hu at canonical.com
Fri Mar 1 07:51:22 UTC 2024


From: "Rafael J. Wysocki" <rafael.j.wysocki at intel.com>

BugLink: https://bugs.launchpad.net/bugs/2049733

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 at intel.com>
Tested-by: Woody Suwalski <terraluna977 at gmail.com>
(backported from commit 8f0b960a42badda7a2781e8a33564624200debc9)
[Ivan Hu: change spaces]
Signed-off-by: Ivan Hu <ivan.hu at canonical.com>
---
 drivers/acpi/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index c6f83c21bb2a..7c8af9c14981 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -400,13 +400,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;
-- 
2.34.1




More information about the kernel-team mailing list