Skip to contentSkip to conversation

acpi/tables.c: Harden acpi_table_parse_entries

PATCH Applied Fenghua Yu 2 participants 2 messages Sep 25, 2012 – Oct 6, 2012 ACPI

lore
Share & tools
lore

Fenghua Yu

author
#0 lore raw

PATCH 1/1 acpi/tables.c: Harden acpi_table_parse_entries

From: Fenghua Yu <[email protected]>

Parsing acpi table entries may fall into an infinite loop on a buggy BIOS which has entry length=0 in acpi table.

Instead of kernel hang with few failure clue which leads to heavy lifting debug effort, this patch hardens kernel boot by booting into non NUMA mode. The debug info left in log buffer helps people identify the issue.

---
 drivers/acpi/tables.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
drivers/acpi/tables.c +14 -4
index f336bca7..2572d97 100644
@@ -240,10 +240,17 @@ acpi_table_parse_entries(char *id,
 	       table_end) {
 		if (entry->type == entry_id
 		    && (!max_entries || count++ < max_entries))
-			if (handler(entry, table_end)) {
-				early_acpi_os_unmap_memory((char *)table_header, tbl_size);
-				return -EINVAL;
-			}
+			if (handler(entry, table_end))
+				goto err;
+
+		/*
+		 * If entry->length is 0, break from this loop to avoid
+		 * infinite loop.
+		 */
+		if (entry->length == 0) {
+			pr_err(PREFIX "[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
+			goto err;
+		}
 
 		entry = (struct acpi_subtable_header *)
 		    ((unsigned long)entry + entry->length);
@@ -255,6 +262,9 @@ acpi_table_parse_entries(char *id,
 
 	early_acpi_os_unmap_memory((char *)table_header, tbl_size);
 	return count;
+err:
+	early_acpi_os_unmap_memory((char *)table_header, tbl_size);
+	return -EINVAL;
 }
 
 int __init
Signature · 1 line
1.7.2
reviewer Applied
#1 lore raw

Applied.

thanks,
Len Brown, Intel Open Source Technology Center