Skip to content

Commit adfab6b

Browse files
jlintonarmrafaeljw
authored andcommitted
ACPI: PPTT: Fix processor subtable walk
The original PPTT code had a bug where the processor subtable length was not correctly validated when encountering a truncated acpi_pptt_processor node. Commit 7ab4f0e ("ACPI PPTT: Fix coding mistakes in a couple of sizeof() calls") attempted to fix this by validating the size is as large as the acpi_pptt_processor node structure. This introduced a regression where the last processor node in the PPTT table is ignored if it doesn't contain any private resources. That results errors like: ACPI PPTT: PPTT table found, but unable to locate core XX (XX) ACPI: SPE must be homogeneous Furthermore, it fails in a common case where the node length isn't equal to the acpi_pptt_processor structure size, leaving the original bug in a modified form. Correct the regression by adjusting the loop termination conditions as suggested by the bug reporters. An additional check performed after the subtable node type is detected, validates the acpi_pptt_processor node is fully contained in the PPTT table. Repeating the check in acpi_pptt_leaf_node() is largely redundant as the node is already known to be fully contained in the table. The case where a final truncated node's parent property is accepted, but the node itself is rejected should not be considered a bug. Fixes: 7ab4f0e ("ACPI PPTT: Fix coding mistakes in a couple of sizeof() calls") Reported-by: Maximilian Heyne <mheyne@amazon.de> Closes: https://lore.kernel.org/linux-acpi/20250506-draco-taped-15f475cd@mheyne-amazon/ Reported-by: Yicong Yang <yangyicong@hisilicon.com> Closes: https://lore.kernel.org/linux-acpi/20250507035124.28071-1-yangyicong@huawei.com/ Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> Tested-by: Yicong Yang <yangyicong@hisilicon.com> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Tested-by: Maximilian Heyne <mheyne@amazon.de> Cc: All applicable <stable@vger.kernel.org> # 7ab4f0e: ACPI PPTT: Fix coding mistakes ... Link: https://patch.msgid.link/20250508023025.1301030-1-jeremy.linton@arm.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 92a09c4 commit adfab6b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/acpi/pptt.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,18 @@ static int acpi_pptt_leaf_node(struct acpi_table_header *table_hdr,
231231
sizeof(struct acpi_table_pptt));
232232
proc_sz = sizeof(struct acpi_pptt_processor);
233233

234-
while ((unsigned long)entry + proc_sz < table_end) {
234+
/* ignore subtable types that are smaller than a processor node */
235+
while ((unsigned long)entry + proc_sz <= table_end) {
235236
cpu_node = (struct acpi_pptt_processor *)entry;
237+
236238
if (entry->type == ACPI_PPTT_TYPE_PROCESSOR &&
237239
cpu_node->parent == node_entry)
238240
return 0;
239241
if (entry->length == 0)
240242
return 0;
243+
241244
entry = ACPI_ADD_PTR(struct acpi_subtable_header, entry,
242245
entry->length);
243-
244246
}
245247
return 1;
246248
}
@@ -273,15 +275,18 @@ static struct acpi_pptt_processor *acpi_find_processor_node(struct acpi_table_he
273275
proc_sz = sizeof(struct acpi_pptt_processor);
274276

275277
/* find the processor structure associated with this cpuid */
276-
while ((unsigned long)entry + proc_sz < table_end) {
278+
while ((unsigned long)entry + proc_sz <= table_end) {
277279
cpu_node = (struct acpi_pptt_processor *)entry;
278280

279281
if (entry->length == 0) {
280282
pr_warn("Invalid zero length subtable\n");
281283
break;
282284
}
285+
/* entry->length may not equal proc_sz, revalidate the processor structure length */
283286
if (entry->type == ACPI_PPTT_TYPE_PROCESSOR &&
284287
acpi_cpu_id == cpu_node->acpi_processor_id &&
288+
(unsigned long)entry + entry->length <= table_end &&
289+
entry->length == proc_sz + cpu_node->number_of_priv_resources * sizeof(u32) &&
285290
acpi_pptt_leaf_node(table_hdr, cpu_node)) {
286291
return (struct acpi_pptt_processor *)entry;
287292
}

0 commit comments

Comments
 (0)