[PATCH v2 29/42] ACPICA: parser: Fix parse tree memory leak on AML execution error unwind

From: Maciej Wieczor-Retman

Date: Fri Nov 20 2026 - 12:22:45 EST


From: Iurii Trukhin <yuri@xxxxxxxxxxx>

AcpiPsCompleteThisOp() checks WalkState->OpInfo->Class when deciding
whether to defer deletion of an AML_CLASS_ARGUMENT parse object to its
parent. During error unwind, however, WalkState->OpInfo can still refer
to the child that failed while Op refers to an enclosing scope.

If that child is an AML_INT_NAMEPATH_OP, the enclosing parse subtrees
are skipped as well. A nested control method has RootOp = NULL, so an
unattached top-level If subtree can leak on every failed evaluation.

Look up the opcode class of Op directly and only defer argument-object
deletion when Op has a parent. Preserve WalkState->Opcode, which the
parser still uses when skipping failed module-level scopes. Remove the
extra region-error AcpiPsDeleteParseTree() call now that completion owns
that deletion, and return discarded control states through
AcpiUtDeleteGenericState() instead of freeing cached objects directly.

Tested with native iASL and acpiexec using a nested _GPE._L6F method
whose If predicate calls a missing external _STA method. The unpatched
interpreter leaves 64 parse objects after 32 evaluations; the patched
interpreter leaves none. Both retain the expected AE_NOT_FOUND result.
Normal If/Return evaluations continue to return 0 and 42.

Link: https://github.com/acpica/acpica/commit/2627fccee606
Link: https://bugzilla.kernel.org/show_bug.cgi?id=221241
Link: https://lore.kernel.org/all/CAOx7e9+Vv8Pdyks=AbE5XG0ZyDgtKToKyBLTnt+H5RPn6VymVg@xxxxxxxxxxxxxx/
Signed-off-by: Iurii Trukhin <yuri@xxxxxxxxxxx>
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@xxxxxxxxx>
---
drivers/acpi/acpica/psloop.c | 5 +++--
drivers/acpi/acpica/psobject.c | 1 -
drivers/acpi/acpica/psparse.c | 16 ++++++++++++----
3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/acpi/acpica/psloop.c b/drivers/acpi/acpica/psloop.c
index 24a57f971c96..f67bc2f3dc42 100644
--- a/drivers/acpi/acpica/psloop.c
+++ b/drivers/acpi/acpica/psloop.c
@@ -464,8 +464,9 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
walk_state->aml =
parser_state->aml;
}
- ACPI_FREE(acpi_ut_pop_generic_state
- (&walk_state->control_state));
+ acpi_ut_delete_generic_state(
+ acpi_ut_pop_generic_state(
+ &walk_state->control_state));
}
op = NULL;
continue;
diff --git a/drivers/acpi/acpica/psobject.c b/drivers/acpi/acpica/psobject.c
index 629cafab1930..f1425b98087b 100644
--- a/drivers/acpi/acpica/psobject.c
+++ b/drivers/acpi/acpica/psobject.c
@@ -559,7 +559,6 @@ acpi_ps_complete_op(struct acpi_walk_state *walk_state,
node);
acpi_ns_remove_node((*op)->common.node);
(*op)->common.node = NULL;
- acpi_ps_delete_parse_tree(*op);
}

status2 =
diff --git a/drivers/acpi/acpica/psparse.c b/drivers/acpi/acpica/psparse.c
index 42ec8abef626..aa89bad57647 100644
--- a/drivers/acpi/acpica/psparse.c
+++ b/drivers/acpi/acpica/psparse.c
@@ -108,6 +108,7 @@ acpi_ps_complete_this_op(struct acpi_walk_state *walk_state,
{
union acpi_parse_object *prev;
union acpi_parse_object *next;
+ const struct acpi_opcode_info *op_info;
const struct acpi_opcode_info *parent_info;
union acpi_parse_object *replacement_op = NULL;
acpi_status status = AE_OK;
@@ -122,11 +123,18 @@ acpi_ps_complete_this_op(struct acpi_walk_state *walk_state,

acpi_ex_stop_trace_opcode(op, walk_state);

- /* Delete this op and the subtree below it if asked to */
-
+ /*
+ * Delete this op and the subtree below it if asked to
+ *
+ * Derive op_info from Op instead of using walk_state->op_info. While they are
+ * often synonymous it is different during error unwind (in acpi_ps_complete_op).
+ * Then the latter can describe a failed child object instead of the enclosing
+ * operation that we want to handle here.
+ */
+ op_info = acpi_ps_get_opcode_info(op->common.aml_opcode);
if (((walk_state->parse_flags & ACPI_PARSE_TREE_MASK) !=
- ACPI_PARSE_DELETE_TREE)
- || (walk_state->op_info->class == AML_CLASS_ARGUMENT)) {
+ ACPI_PARSE_DELETE_TREE) ||
+ ((op_info->class == AML_CLASS_ARGUMENT) && op->common.parent)) {
return_ACPI_STATUS(AE_OK);
}

--
2.56.0