Skip to contentSkip to conversation

ACPI: Prevent acpi_table_entries from falling into a infinite loop

PATCH In review Malcolm Crossley 2 participants 2 messages Jun 3, 2014 – Jun 4, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ACPI: Prevent acpi_table_entries from falling into a infinite loop

If a buggy BIOS programs an ACPI table with entry length 0 then acpi_table_entries gets stuck in an infinite loop.

To aid debugging, report the error and exit the loop.

Based on Linux kernel commit 369d913b242cae2205471b11b6e33ac368ed33ec

xen/drivers/acpi/tables.c +6 -0
diff -r 4708591d8aa8 -r 144fabe8dcb7 xen/drivers/acpi/tables.c
@@ -233,6 +233,12 @@ acpi_table_parse_entries(char *id,
 
 	while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
 	       table_end) {
+		if (entry->length <= sizeof(*entry)) {
+			printk(KERN_ERR PREFIX "[%4.4s:0x%02x] Invalid length\n",
+			       id, entry_id);
+			return -EINVAL;
+		}
+
 		if (entry->type == entry_id
 		    && (!max_entries || count++ < max_entries))
 			if (handler(entry, table_end))
#1 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 03.06.14 at 18:44, <[email protected]> wrote:

If a buggy BIOS programs an ACPI table with entry length 0 then acpi_table_entries gets stuck in an infinite loop.

I'll re-word this to "with to small an entry length" to match actual code.

Quoted 10 lines

To aid debugging, report the error and exit the loop.

Based on Linux kernel commit 369d913b242cae2205471b11b6e33ac368ed33ec

diff -r 4708591d8aa8 -r 144fabe8dcb7 xen/drivers/acpi/tables.c

xen/drivers/acpi/tables.c acpi_table_parse_entries(char *id, · line 236

Quoted 4 lines
xen/drivers/acpi/tables.c +1 -0
@@ -233,6 +233,12 @@ acpi_table_parse_entries(char *id,
 
 	while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
 	       table_end) {
+		if (entry->length <= sizeof(*entry)) {

I realize I (wrongly) recommended <= here; I'll correct this to <.

xen/drivers/acpi/tables.c acpi_table_parse_entries(char *id, · line 238

Quoted 2 lines
xen/drivers/acpi/tables.c +2 -0
+			printk(KERN_ERR PREFIX "[%4.4s:0x%02x] Invalid length\n",
+			       id, entry_id);

I also wonder whether printing the requested entry ID here isn't going to be confusing (as the error isn't necessarily being found on that entry), but I'll leave that as is for now (since with ->length being invalid there's no basis to trust ->type).

xen/drivers/acpi/tables.c acpi_table_parse_entries(char *id, · line 239

Quoted 1 line
xen/drivers/acpi/tables.c +1 -0
+			return -EINVAL;

And I'll make this -ENODATA.

Jan

Quoted 5 lines
xen/drivers/acpi/tables.c +2 -0
+		}
+
 		if (entry->type == entry_id
 		    && (!max_entries || count++ < max_entries))
 			if (handler(entry, table_end))