[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 01/16] pci: reject too large ROMs
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 01/16] pci: reject too large ROMs |
Date: |
Fri, 5 Feb 2021 10:03:31 -0500 |
From: Paolo Bonzini <pbonzini@redhat.com>
get_image_size() returns an int64_t, which pci_add_option_rom() assigns
to an "int" without any range checking. A 32-bit BAR could be up to
2 GiB in size, so reject anything above it. In order to accomodate
a rounded-up size of 2 GiB, change pci_patch_ids's size argument
to unsigned.
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20210203131828.156467-2-pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: David Edmondson <david.edmondson@oracle.com>
---
hw/pci/pci.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 512e9042ff..58560c044d 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -25,6 +25,7 @@
#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/datadir.h"
+#include "qemu/units.h"
#include "hw/irq.h"
#include "hw/pci/pci.h"
#include "hw/pci/pci_bridge.h"
@@ -2234,7 +2235,7 @@ static uint8_t pci_find_capability_at_offset(PCIDevice
*pdev, uint8_t offset)
/* Patch the PCI vendor and device ids in a PCI rom image if necessary.
This is needed for an option rom which is used for more than one device. */
-static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
+static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, uint32_t size)
{
uint16_t vendor_id;
uint16_t device_id;
@@ -2292,7 +2293,7 @@ static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr,
int size)
static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
Error **errp)
{
- int size;
+ int64_t size;
char *path;
void *ptr;
char name[32];
@@ -2342,6 +2343,11 @@ static void pci_add_option_rom(PCIDevice *pdev, bool
is_default_rom,
error_setg(errp, "romfile \"%s\" is empty", pdev->romfile);
g_free(path);
return;
+ } else if (size > 2 * GiB) {
+ error_setg(errp, "romfile \"%s\" too large (size cannot exceed 2 GiB)",
+ pdev->romfile);
+ g_free(path);
+ return;
}
size = pow2ceil(size);
--
MST
- [PULL v2 00/16] pc,virtio,pci: fixes, features,code removal, Michael S. Tsirkin, 2021/02/05
- [PULL v2 01/16] pci: reject too large ROMs,
Michael S. Tsirkin <=
- [PULL v2 03/16] virtio: move 'use-disabled-flag' property to hw_compat_4_2, Michael S. Tsirkin, 2021/02/05
- [PULL v2 02/16] pci: add romsize property, Michael S. Tsirkin, 2021/02/05
- [PULL v2 04/16] virtio-mmio: fix guest kernel crash with SHM regions, Michael S. Tsirkin, 2021/02/05
- [PULL v2 05/16] virtio: Add corresponding memory_listener_unregister to unrealize, Michael S. Tsirkin, 2021/02/05
- [PULL v2 06/16] virtio-pmem: add trace events, Michael S. Tsirkin, 2021/02/05
- [PULL v2 07/16] vhost: Unbreak SMMU and virtio-iommu on dev-iotlb support, Michael S. Tsirkin, 2021/02/05
- [PULL v2 08/16] hw/i386: Remove the deprecated pc-1.x machine types, Michael S. Tsirkin, 2021/02/05
- [PULL v2 10/16] vhost: Check for valid vdev in vhost_backend_handle_iotlb_msg, Michael S. Tsirkin, 2021/02/05
- [PULL v2 11/16] tests/acpi: allow updates for expected data files, Michael S. Tsirkin, 2021/02/05
- [PULL v2 12/16] acpi: Permit OEM ID and OEM table ID fields to be changed, Michael S. Tsirkin, 2021/02/05