Skip to contentSkip to conversation

pci init: fail qemu if devfn exceeding the max devices number supported on bus

PATCH In review Ken CC 1 participant 3 messages Aug 24, 2010 1 message not in the archive KVM

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 20100824062517.12408.45246.stgit@k1

Ken CC

author
#1 lore raw

PATCH 2/3 pci init: fail qemu if devfn exceeding the max devices number supported on bus

assert(devfn < PCIBUS_MAX_DEVICES)

---
 hw/pci.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci.c +1 -0
index 02019a1..1e804da 100644
@@ -747,6 +747,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
                                          PCIConfigWriteFunc *config_write,
                                          bool is_bridge)
 {
+    assert(devfn < PCIBUS_MAX_DEVICES);
     if (devfn < 0) {
         for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices);
             devfn += PCI_FUNC_MAX) {
author
#2 lore raw

broken thread, please ignore.

Quoted 24 lines · Ken CC

assert(devfn < PCIBUS_MAX_DEVICES)

---
 hw/pci.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci.c +1 -1
index 02019a1..1e804da 100644
@@ -747,6 +747,7 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
                                          PCIConfigWriteFunc *config_write,
                                          bool is_bridge)
 {
+    assert(devfn < PCIBUS_MAX_DEVICES);
     if (devfn < 0) {
         for(devfn = bus->devfn_min ; devfn < ARRAY_SIZE(bus->devices);
             devfn += PCI_FUNC_MAX) {
 
--

To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#3 lore raw

PATCH 3/3 Check pci slot number in parse_pci_devfn

In reply to a message not in the archive

Define MAX_PCI_SLOTS as 0x1f, if pci addr provided from command line is bigger than 0x1f, return error -EINVAL.

0x1f << 3 | 7 == 255 (PCIBUS_MAX_DEVICES - 1)

---
 hw/qdev-properties.c |    2 ++
 hw/qdev.h            |    3 +++
 2 files changed, 5 insertions(+), 0 deletions(-)
hw/qdev-properties.c +2 -0
index 9219cd7..96d814c 100644
@@ -514,6 +514,8 @@ static int parse_pci_devfn(DeviceState *dev, Property *prop, const char *str)
             return -EINVAL;
         }
     }
+    if (slot > MAX_PCI_SLOTS)
+        return -EINVAL;
     if (str[n] != '\0')
         return -EINVAL;
     if (fn > 7)
hw/qdev.h +3 -0
index 678f8b7..fcfe52e 100644
@@ -7,6 +7,9 @@
 #include "qemu-char.h"
 #include "qemu-option.h"
 
+
+#define MAX_PCI_SLOTS 0x1f
+
 typedef struct Property Property;
 
 typedef struct PropertyInfo PropertyInfo;