Skip to contentSkip to conversation

pci-devfn: check that device/slot number is within range

PATCH Applied Donald Dutile 3 participants 3 messages Sep 21, 2011 – Sep 23, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci-devfn: check that device/slot number is within range

Need to check that guest slot/device number is not > 31 or walk off the devfn table when checking if a devfn is available or not in a guest.

before this fix, passing in an addr=abc or addr=34, can crash qemu, sometimes fail gracefully if data past end of devfn table fails the availability test.

with this fix, get clean error:
Property 'pci-assign.addr' doesn't take value '34'

also tested when no addr= param passed for guest (pcicfg) address, and that worked as well.

---
 hw/qdev-properties.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/qdev-properties.c +2 -0
index 7ce95b6..e0e54aa 100644
@@ -524,6 +524,8 @@ static int parse_pci_devfn(DeviceState *dev, Property *prop, const char *str)
         return -EINVAL;
     if (fn > 7)
         return -EINVAL;
+    if (slot > 31)
+        return -EINVAL;
     *ptr = slot << 3 | fn;
     return 0;
 }
Signature · 1 line
1.7.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Donald Dutile

Need to check that guest slot/device number is not > 31 or walk off the devfn table when checking if a devfn is available or not in a guest.

Here in do_pci_register_device():

    } else if (bus->devices[devfn]) {
        error_report("PCI: devfn %d not available for %s, in use by %s",
                     devfn, name, bus->devices[devfn]->name);
        return NULL;
    }
Quoted 11 lines

before this fix, passing in an addr=abc or addr=34, can crash qemu, sometimes fail gracefully if data past end of devfn table fails the availability test.

with this fix, get clean error:
Property 'pci-assign.addr' doesn't take value '34'

also tested when no addr= param passed for guest (pcicfg) address, and that worked as well.

#2 lore raw
In reply to Donald Dutile
Quoted 7 lines · Donald Dutile

Need to check that guest slot/device number is not> 31 or walk off the devfn table when checking if a devfn is available or not in a guest.

before this fix, passing in an addr=abc or addr=34, can crash qemu, sometimes fail gracefully if data past end of devfn table fails the availability test.

Quoted 7 lines

with this fix, get clean error:
Property 'pci-assign.addr' doesn't take value '34'

also tested when no addr= param passed for guest (pcicfg) address, and that worked as well.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 18 lines
---
  hw/qdev-properties.c |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)
hw/qdev-properties.c +2 -0
index 7ce95b6..e0e54aa 100644
@@ -524,6 +524,8 @@ static int parse_pci_devfn(DeviceState *dev, Property *prop, const char *str)
          return -EINVAL;
      if (fn>  7)
          return -EINVAL;
+    if (slot>  31)
+        return -EINVAL;
      *ptr = slot<<  3 | fn;
      return 0;
  }