Skip to contentSkip to conversation

pci: mark ROMs read-only

PATCH In review Michael S. Tsirkin 3 participants 3 messages Jan 19, 2017 – Jan 24, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: mark ROMs read-only

Looks like we didn't mark PCI ROMs as RO allowing mischief such as guests writing there. Further, e.g. vhost gets confused trying to allocate enough space to log writes there. Fix it up.

---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci.c +1 -1
index 637d545..eaac185 100644
@@ -2199,7 +2199,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
         snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev)));
     }
     pdev->has_rom = true;
-    memory_region_init_ram(&pdev->rom, OBJECT(pdev), name, size, &error_fatal);
+    memory_region_init_rom(&pdev->rom, OBJECT(pdev), name, size, &error_fatal);
     vmstate_register_ram(&pdev->rom, &pdev->qdev);
     ptr = memory_region_get_ram_ptr(&pdev->rom);
     load_image(path, ptr);
Signature · 1 line
MST
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Michael S. Tsirkin

Looks like we didn't mark PCI ROMs as RO allowing mischief such as guests writing there. Further, e.g. vhost gets confused trying to allocate enough space to log writes there. Fix it up.

---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci.c +0 -0
index 637d545..eaac185 100644

hw/pci/pci.c static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, · line 2205

Quoted 8 lines
hw/pci/pci.c +1 -1
@@ -2199,7 +2199,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
         snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev)));
     }
     pdev->has_rom = true;
-    memory_region_init_ram(&pdev->rom, OBJECT(pdev), name, size, &error_fatal);
+    memory_region_init_rom(&pdev->rom, OBJECT(pdev), name, size, &error_fatal);
     vmstate_register_ram(&pdev->rom, &pdev->qdev);
     ptr = memory_region_get_ram_ptr(&pdev->rom);
     load_image(path, ptr);

Thanks,
Marcel

Tested-by on v1 1/1
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 16 lines · Michael S. Tsirkin

Looks like we didn't mark PCI ROMs as RO allowing mischief such as guests writing there. Further, e.g. vhost gets confused trying to allocate enough space to log writes there. Fix it up.

---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci/pci.c +0 -0
index 637d545..eaac185 100644

hw/pci/pci.c static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom, · line 2205

Quoted 8 lines
hw/pci/pci.c +1 -1
@@ -2199,7 +2199,7 @@ static void pci_add_option_rom(PCIDevice *pdev, bool is_default_rom,
         snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev)));
     }
     pdev->has_rom = true;
-    memory_region_init_ram(&pdev->rom, OBJECT(pdev), name, size, &error_fatal);
+    memory_region_init_rom(&pdev->rom, OBJECT(pdev), name, size, &error_fatal);
     vmstate_register_ram(&pdev->rom, &pdev->qdev);
     ptr = memory_region_get_ram_ptr(&pdev->rom);
     load_image(path, ptr);