Skip to contentSkip to conversation

ACPICA: Initialize parser_state.aml_end in acpi_install_method()

PATCH In review Yong Hu 2 participants 2 messages Oct 23 – Nov 9

Subsystems (2)
lore
Share & tools
lore

Yong Hu

author
#0 lore raw

PATCH 1/1 ACPICA: Initialize parser_state.aml_end in acpi_install_method()

In acpi_install_method(), the local parser_state is stack-allocated and only parser_state.aml was initialized. Parser helpers called by this path read parser_state.aml_end for bounds checking: acpi_ps_peek_opcode() reads it before validating the first AML opcode, and acpi_ps_get_next_package_end() reads it indirectly via acpi_ps_get_next_package_length(). The subsequent package-limit check also compares against parser_state.aml_end. Because aml_end was never set, these checks operated on an uninitialized value, which could lead to incorrect parser bounds decisions.

Initialize parser_state.aml_end to the end of the table (buffer + table->length) so the parser bounds checks operate on a valid limit.

Fixes bdc357540129 ("ACPICA: add boundary checks in two places")
---
 drivers/acpi/acpica/nsxfname.c | 1 +
 1 file changed, 1 insertion(+)
drivers/acpi/acpica/nsxfname.c +1 -0
index fabae9b08e31..b1234567890a 100644
@@ -503,6 +503,7 @@ acpi_status acpi_install_method(u8 *buffer)
 	/* First AML opcode in the table must be a control method */
 
 	parser_state.aml = buffer + sizeof(struct acpi_table_header);
+	parser_state.aml_end = buffer + table->length;
 	opcode = acpi_ps_peek_opcode(&parser_state);
 	if (opcode != AML_METHOD_OP) {
 		return (AE_BAD_PARAMETER);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 25 lines · Yong Hu

In acpi_install_method(), the local parser_state is stack-allocated and only parser_state.aml was initialized. Parser helpers called by this path read parser_state.aml_end for bounds checking: acpi_ps_peek_opcode() reads it before validating the first AML opcode, and acpi_ps_get_next_package_end() reads it indirectly via acpi_ps_get_next_package_length(). The subsequent package-limit check also compares against parser_state.aml_end. Because aml_end was never set, these checks operated on an uninitialized value, which could lead to incorrect parser bounds decisions.

Initialize parser_state.aml_end to the end of the table (buffer + table->length) so the parser bounds checks operate on a valid limit.

Fixes bdc357540129 ("ACPICA: add boundary checks in two places")
---
 drivers/acpi/acpica/nsxfname.c | 1 +
 1 file changed, 1 insertion(+)
drivers/acpi/acpica/nsxfname.c +0 -0
index fabae9b08e31..b1234567890a 100644

drivers/acpi/acpica/nsxfname.c acpi_status acpi_install_method(u8 *buffer)

Quoted 8 lines
drivers/acpi/acpica/nsxfname.c +1 -1
@@ -503,6 +503,7 @@ acpi_status acpi_install_method(u8 *buffer)
        /* First AML opcode in the table must be a control method */
 
        parser_state.aml = buffer + sizeof(struct acpi_table_header);
+       parser_state.aml_end = buffer + table->length;
        opcode = acpi_ps_peek_opcode(&parser_state);
        if (opcode != AML_METHOD_OP) {
                return (AE_BAD_PARAMETER);
--

This should be fixed by commit ec696f34774d ACPICA: Initialize parser_state.aml_end in acpi_install_method().

Thanks!