Skip to contentSkip to conversation

Make ACPI DMAR parsing more robust

PATCH In review Espen Skoglund 2 participants 3 messages Apr 2, 2008 – Apr 3, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make ACPI DMAR parsing more robust

Parsing ACPI related VT-d tables may cause infinite loop due to u8 value wraparound. Also add sanity check on table length entry.

eSk

xen/drivers/passthrough/vtd/dmar.c +4 -4
diff -r db943e8d1051 xen/drivers/passthrough/vtd/dmar.c
@@ -211,7 +211,7 @@ static int scope_device_count(void *star
 static int scope_device_count(void *start, void *end)
 {
     struct acpi_dev_scope *scope;
-    u8 bus, sub_bus, sec_bus;
+    u16 bus, sub_bus, sec_bus;
     struct acpi_pci_path *path;
     int depth, count = 0;
     u8 dev, func;
@@ -231,7 +231,7 @@ static int scope_device_count(void *star
         bus = scope->start_bus;
         depth = (scope->length - sizeof(struct acpi_dev_scope))
 		    / sizeof(struct acpi_pci_path);
-        while ( --depth )
+        while ( depth && --depth )
         {
             bus = read_pci_config_byte(
                 bus, path->dev, path->fn, PCI_SECONDARY_BUS);
@@ -301,7 +301,7 @@ static int __init acpi_parse_dev_scope(
     void *start, void *end, void *acpi_entry, int type)
 {
     struct acpi_dev_scope *scope;
-    u8 bus, sub_bus, sec_bus;
+    u16 bus, sub_bus, sec_bus;
     struct acpi_pci_path *path;
     struct acpi_ioapic_unit *acpi_ioapic_unit = NULL;
     int depth;
@@ -353,7 +353,7 @@ static int __init acpi_parse_dev_scope(
 		    / sizeof(struct acpi_pci_path);
         bus = scope->start_bus;
 
-        while ( --depth )
+        while ( depth && --depth )
         {
             bus = read_pci_config_byte(
                 bus, path->dev, path->fn, PCI_SECONDARY_BUS);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Regarding the table length sanity check -- depth is set to the number of acp_pci_path structures in the table. But then we only follow the path to depth-1. Is that correct?

Also I changed the test to '--depth >= 0' which is equivalent and a bit easier to read imo.

-- Keir

Quoted 12 lines · Espen Skoglund

Parsing ACPI related VT-d tables may cause infinite loop due to u8 value wraparound. Also add sanity check on table length entry.

eSk

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw

Right. Depth *should* always be >= 1, but from my experience one can not always trust the info in the tables to be correct. Better be on the safe side.

eSk

[Keir Fraser]

Quoted 24 lines

Regarding the table length sanity check -- depth is set to the number of acp_pci_path structures in the table. But then we only follow the path to depth-1. Is that correct?

Also I changed the test to '--depth >= 0' which is equivalent and a bit easier to read imo.

-- Keir

Quoted 12 lines · Espen Skoglund

Parsing ACPI related VT-d tables may cause infinite loop due to u8 value wraparound. Also add sanity check on table length entry.

eSk

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel