These are all intended for use in a virtualization scenario and must
provide a security boundary. This can be done for almost all virtio
PCI devices by modifying the common type register helper.

Exceptions are made for the virtio-gpu-gl, virtio-vga-gl,
virtio-vga-rutatbaga and virtio-gpu-rutabaga devices.

Despite being intended for virtualization use cases, the complexity
of support for 3d acceleration is such that QEMU can't offer security
for these devices at this time.

Signed-off-by: Daniel P. Berrangé <[email protected]>
---
 hw/display/virtio-gpu-pci-gl.c   |  2 +-
 hw/display/virtio-vga-gl.c       |  2 +-
 hw/display/virtio-vga-rutabaga.c |  2 +-
 hw/virtio/virtio-pci.c           | 17 ++++++++++++++++-
 include/hw/virtio/virtio-pci.h   | 10 +++++++++-
 5 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/hw/display/virtio-gpu-pci-gl.c b/hw/display/virtio-gpu-pci-gl.c
index c8923795dfa..dc67516b377 100644
--- a/hw/display/virtio-gpu-pci-gl.c
+++ b/hw/display/virtio-gpu-pci-gl.c
@@ -51,7 +51,7 @@ module_kconfig(VIRTIO_PCI);
 
 static void virtio_gpu_gl_pci_register_types(void)
 {
-    virtio_pci_types_register(&virtio_gpu_gl_pci_info);
+    virtio_pci_types_register_insecure(&virtio_gpu_gl_pci_info);
 }
 
 type_init(virtio_gpu_gl_pci_register_types)
diff --git a/hw/display/virtio-vga-gl.c b/hw/display/virtio-vga-gl.c
index 178e4c71725..029d288c035 100644
--- a/hw/display/virtio-vga-gl.c
+++ b/hw/display/virtio-vga-gl.c
@@ -42,7 +42,7 @@ module_kconfig(VIRTIO_VGA);
 static void virtio_vga_register_types(void)
 {
     if (have_vga) {
-        virtio_pci_types_register(&virtio_vga_gl_info);
+        virtio_pci_types_register_insecure(&virtio_vga_gl_info);
     }
 }
 
diff --git a/hw/display/virtio-vga-rutabaga.c b/hw/display/virtio-vga-rutabaga.c
index 1e07ee0b0d3..8ff715f8a35 100644
--- a/hw/display/virtio-vga-rutabaga.c
+++ b/hw/display/virtio-vga-rutabaga.c
@@ -41,7 +41,7 @@ module_kconfig(VIRTIO_VGA);
 static void virtio_vga_register_types(void)
 {
     if (have_vga) {
-        virtio_pci_types_register(&virtio_vga_rutabaga_info);
+        virtio_pci_types_register_insecure(&virtio_vga_rutabaga_info);
     }
 }
 
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index c73f1f546cb..fe2e545c302 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2510,7 +2510,9 @@ static void 
virtio_pci_non_transitional_instance_init(Object *obj)
     proxy->disable_modern = false;
 }
 
-void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)
+static void
+virtio_pci_types_register_internal(const VirtioPCIDeviceTypeInfo *t,
+                                   bool secure)
 {
     char *base_name = NULL;
     TypeInfo base_type_info = {
@@ -2527,6 +2529,7 @@ void virtio_pci_types_register(const 
VirtioPCIDeviceTypeInfo *t)
         .name = t->generic_name,
         .parent = base_type_info.name,
         .class_init = virtio_pci_generic_class_init,
+        .secure = secure,
         .interfaces = (const InterfaceInfo[]) {
             { INTERFACE_PCIE_DEVICE },
             { INTERFACE_CONVENTIONAL_PCI_DEVICE },
@@ -2562,6 +2565,7 @@ void virtio_pci_types_register(const 
VirtioPCIDeviceTypeInfo *t)
             .name          = t->non_transitional_name,
             .parent        = base_type_info.name,
             .instance_init = virtio_pci_non_transitional_instance_init,
+            .secure = secure,
             .interfaces = (const InterfaceInfo[]) {
                 { INTERFACE_PCIE_DEVICE },
                 { INTERFACE_CONVENTIONAL_PCI_DEVICE },
@@ -2576,6 +2580,7 @@ void virtio_pci_types_register(const 
VirtioPCIDeviceTypeInfo *t)
             .name          = t->transitional_name,
             .parent        = base_type_info.name,
             .instance_init = virtio_pci_transitional_instance_init,
+            .secure = secure,
             .interfaces = (const InterfaceInfo[]) {
                 /*
                  * Transitional virtio devices work only as Conventional PCI
@@ -2590,6 +2595,16 @@ void virtio_pci_types_register(const 
VirtioPCIDeviceTypeInfo *t)
     g_free(base_name);
 }
 
+void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t)
+{
+    virtio_pci_types_register_internal(t, true);
+}
+
+void virtio_pci_types_register_insecure(const VirtioPCIDeviceTypeInfo *t)
+{
+    virtio_pci_types_register_internal(t, false);
+}
+
 unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues)
 {
     /*
diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h
index ee50fb0d551..f033237035a 100644
--- a/include/hw/virtio/virtio-pci.h
+++ b/include/hw/virtio/virtio-pci.h
@@ -239,8 +239,16 @@ typedef struct VirtioPCIDeviceTypeInfo {
     const InterfaceInfo *interfaces;
 } VirtioPCIDeviceTypeInfo;
 
-/* Register virtio-pci type(s).  @t must be static. */
+/*
+ * Register virtio-pci type(s).
+ * @t must be static.
+ *
+ * Since they serve the virtualization use case, most virtio
+ * devices are expected to be classed as secure. In the rare
+ * scenario where this is not desired, use the second method.
+ */
 void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
+void virtio_pci_types_register_insecure(const VirtioPCIDeviceTypeInfo *t);
 
 /**
  * virtio_pci_optimal_num_queues:
-- 
2.56.1


Reply via email to