提交 09f1bbcd 编写于 作者: M Michael Roth 提交者: Andreas Färber

qdev: Use int32_t container for devfn property

Valid range for devfn is -1 to 255 (-1 for automatic assignment). We do
not currently validate this due to devfn being stored as a uint32_t.
This can lead to segfaults and other strange behavior.

We could technically just cast it to int32_t to implement the checking,
but this will not work for visitor-based setting where we may do additional
bounds-checking based on target container type, which is int32_t for this
case.
Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NAndreas Färber <afaerber@suse.de>
上级 0d30b0a2
...@@ -1537,7 +1537,7 @@ PCIDevice *pci_create_multifunction(PCIBus *bus, int devfn, bool multifunction, ...@@ -1537,7 +1537,7 @@ PCIDevice *pci_create_multifunction(PCIBus *bus, int devfn, bool multifunction,
DeviceState *dev; DeviceState *dev;
dev = qdev_create(&bus->qbus, name); dev = qdev_create(&bus->qbus, name);
qdev_prop_set_uint32(dev, "addr", devfn); qdev_prop_set_int32(dev, "addr", devfn);
qdev_prop_set_bit(dev, "multifunction", multifunction); qdev_prop_set_bit(dev, "multifunction", multifunction);
return PCI_DEVICE(dev); return PCI_DEVICE(dev);
} }
......
...@@ -197,7 +197,7 @@ struct PCIDevice { ...@@ -197,7 +197,7 @@ struct PCIDevice {
/* the following fields are read only */ /* the following fields are read only */
PCIBus *bus; PCIBus *bus;
uint32_t devfn; int32_t devfn;
char name[64]; char name[64];
PCIIORegion io_regions[PCI_NUM_REGIONS]; PCIIORegion io_regions[PCI_NUM_REGIONS];
......
...@@ -824,7 +824,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque, ...@@ -824,7 +824,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
{ {
DeviceState *dev = DEVICE(obj); DeviceState *dev = DEVICE(obj);
Property *prop = opaque; Property *prop = opaque;
uint32_t *ptr = qdev_get_prop_ptr(dev, prop); int32_t *ptr = qdev_get_prop_ptr(dev, prop);
unsigned int slot, fn, n; unsigned int slot, fn, n;
Error *local_err = NULL; Error *local_err = NULL;
char *str; char *str;
...@@ -860,7 +860,7 @@ invalid: ...@@ -860,7 +860,7 @@ invalid:
static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len) static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len)
{ {
uint32_t *ptr = qdev_get_prop_ptr(dev, prop); int32_t *ptr = qdev_get_prop_ptr(dev, prop);
if (*ptr == -1) { if (*ptr == -1) {
return snprintf(dest, len, "<unset>"); return snprintf(dest, len, "<unset>");
...@@ -875,11 +875,8 @@ PropertyInfo qdev_prop_pci_devfn = { ...@@ -875,11 +875,8 @@ PropertyInfo qdev_prop_pci_devfn = {
.print = print_pci_devfn, .print = print_pci_devfn,
.get = get_int32, .get = get_int32,
.set = set_pci_devfn, .set = set_pci_devfn,
/* FIXME: this should be -1...255, but the address is stored .min = -1,
* into an uint32_t rather than int32_t. .max = 255,
*/
.min = 0,
.max = 0xFFFFFFFFULL,
}; };
/* --- blocksize --- */ /* --- blocksize --- */
......
...@@ -267,7 +267,7 @@ extern PropertyInfo qdev_prop_blocksize; ...@@ -267,7 +267,7 @@ extern PropertyInfo qdev_prop_blocksize;
#define DEFINE_PROP_HEX64(_n, _s, _f, _d) \ #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t) DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t) DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
#define DEFINE_PROP_PTR(_n, _s, _f) \ #define DEFINE_PROP_PTR(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册