[libvirt PATCH 04/10] conf: validate NVRAM template usage with R/W loader binary

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The QEMU driver will populate the template to the nvram file any time it
sees both the template and nvram paths present. It will auto-generate a
nvram path per-VM if not provided by the user, but only if the loader
is marked R/O.

So with a R/O loader we have these possible scenarios

  - No NVRAM path or template -> try to infer a template based on the
                                 loader path, if not possible, fatal
				 error. Auto-generate NVRAM per per VM
  - NVRAM path only -> try to infer a template based on the loader path,
                       if not possible, app must have pre-created NVRAM
  - NVRAM path + template -> QEMU driver will copy template to NVRAM
  - NVRAM template only -> auto-generate NVRAM path per VM and then
                           copy template

While with a R/W loader we have these possible scenarios

  - No NVRAM path or template -> do nothing
  - NVRAM path only -> app must have pre-created NVRAM
  - NVRAM path + template -> QEMU driver will copy template to NVRAM
  - NVRAM template only -> silently ignored

This change improves the last scenario by reporting an error from the
parser. Two alternative strategies though would be:

  - Auto-generate a NVRAM path per VM
  - Don't support templates at all with R/W loader

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/conf/domain_conf.c                        | 16 ++++++--
 ...-nvram-rw-template-vars.x86_64-latest.args | 41 +++++++++++++++++++
 .../bios-nvram-rw-template-vars.xml           | 36 ++++++++++++++++
 .../bios-nvram-rw-template.err                |  1 +
 .../bios-nvram-rw-template.xml                | 36 ++++++++++++++++
 .../bios-nvram-rw-vars.x86_64-latest.args     | 41 +++++++++++++++++++
 tests/qemuxml2argvdata/bios-nvram-rw-vars.xml | 36 ++++++++++++++++
 tests/qemuxml2argvtest.c                      |  3 ++
 8 files changed, 207 insertions(+), 3 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/bios-nvram-rw-template-vars.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/bios-nvram-rw-template-vars.xml
 create mode 100644 tests/qemuxml2argvdata/bios-nvram-rw-template.err
 create mode 100644 tests/qemuxml2argvdata/bios-nvram-rw-template.xml
 create mode 100644 tests/qemuxml2argvdata/bios-nvram-rw-vars.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/bios-nvram-rw-vars.xml

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ab8f2a52cc..31b49c4ec9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4808,17 +4808,26 @@ virDomainDefPostParseMemory(virDomainDef *def,
 }
 
 
-static void
+static int
 virDomainDefPostParseOs(virDomainDef *def)
 {
     if (!def->os.loader)
-        return;
+        return 0;
 
     if (def->os.loader->path &&
         def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_NONE) {
         /* By default, loader is type of 'rom' */
         def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_ROM;
     }
+
+    if (def->os.loader->readonly != VIR_TRISTATE_BOOL_YES &&
+        def->os.loader->templt && !def->os.loader->nvram) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("NVRAM template without VARs path not permitted with writable loader"));
+        return -1;
+    }
+
+    return 0;
 }
 
 
@@ -6139,7 +6148,8 @@ virDomainDefPostParseCommon(virDomainDef *def,
     if (virDomainDefPostParseMemory(def, data->parseFlags) < 0)
         return -1;
 
-    virDomainDefPostParseOs(def);
+    if (virDomainDefPostParseOs(def) < 0)
+        return -1;
 
     virDomainDefPostParseMemtune(def);
 
diff --git a/tests/qemuxml2argvdata/bios-nvram-rw-template-vars.x86_64-latest.args b/tests/qemuxml2argvdata/bios-nvram-rw-template-vars.x86_64-latest.args
new file mode 100644
index 0000000000..8d971ec29b
--- /dev/null
+++ b/tests/qemuxml2argvdata/bios-nvram-rw-template-vars.x86_64-latest.args
@@ -0,0 +1,41 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-test-bios \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-test-bios/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-test-bios/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-test-bios/.config \
+/usr/bin/qemu-system-x86_64 \
+-name guest=test-bios,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-test-bios/master-key.aes"}' \
+-blockdev '{"driver":"file","filename":"/var/lib/libvirt/qemu/nvram/test-bios.fd","node-name":"libvirt-pflash0-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-pflash0-format","read-only":false,"driver":"raw","file":"libvirt-pflash0-storage"}' \
+-blockdev '{"driver":"file","filename":"/some/vars/path.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"}' \
+-machine pc,usb=off,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \
+-accel tcg \
+-cpu qemu64 \
+-m 1024 \
+-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":1073741824}' \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 362d1fc1-df7d-193e-5c18-49a71bd1da66 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot menu=on,strict=on \
+-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
+-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \
+-device '{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-1-format","id":"ide0-0-0","bootindex":1}' \
+-device '{"driver":"usb-tablet","id":"input0","bus":"usb.0","port":"1"}' \
+-audiodev '{"id":"audio1","driver":"none"}' \
+-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/bios-nvram-rw-template-vars.xml b/tests/qemuxml2argvdata/bios-nvram-rw-template-vars.xml
new file mode 100644
index 0000000000..fe6a064c84
--- /dev/null
+++ b/tests/qemuxml2argvdata/bios-nvram-rw-template-vars.xml
@@ -0,0 +1,36 @@
+<domain type='qemu'>
+  <name>test-bios</name>
+  <uuid>362d1fc1-df7d-193e-5c18-49a71bd1da66</uuid>
+  <memory unit='KiB'>1048576</memory>
+  <currentMemory unit='KiB'>1048576</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <loader readonly='no' type='pflash'>/var/lib/libvirt/qemu/nvram/test-bios.fd</loader>
+    <nvram template="/some/vars/template/path.fd">/some/vars/path.fd</nvram>
+    <boot dev='hd'/>
+    <bootmenu enable='yes'/>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='tablet' bus='usb'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/bios-nvram-rw-template.err b/tests/qemuxml2argvdata/bios-nvram-rw-template.err
new file mode 100644
index 0000000000..fdfa6c711e
--- /dev/null
+++ b/tests/qemuxml2argvdata/bios-nvram-rw-template.err
@@ -0,0 +1 @@
+XML error: NVRAM template without VARs path not permitted with writable loader
diff --git a/tests/qemuxml2argvdata/bios-nvram-rw-template.xml b/tests/qemuxml2argvdata/bios-nvram-rw-template.xml
new file mode 100644
index 0000000000..334ed1425b
--- /dev/null
+++ b/tests/qemuxml2argvdata/bios-nvram-rw-template.xml
@@ -0,0 +1,36 @@
+<domain type='qemu'>
+  <name>test-bios</name>
+  <uuid>362d1fc1-df7d-193e-5c18-49a71bd1da66</uuid>
+  <memory unit='KiB'>1048576</memory>
+  <currentMemory unit='KiB'>1048576</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <loader readonly='no' type='pflash'>/var/lib/libvirt/qemu/nvram/test-bios.fd</loader>
+    <nvram template="/some/vars/template/path.fd"/>
+    <boot dev='hd'/>
+    <bootmenu enable='yes'/>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='tablet' bus='usb'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/bios-nvram-rw-vars.x86_64-latest.args b/tests/qemuxml2argvdata/bios-nvram-rw-vars.x86_64-latest.args
new file mode 100644
index 0000000000..8d971ec29b
--- /dev/null
+++ b/tests/qemuxml2argvdata/bios-nvram-rw-vars.x86_64-latest.args
@@ -0,0 +1,41 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-test-bios \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-test-bios/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-test-bios/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-test-bios/.config \
+/usr/bin/qemu-system-x86_64 \
+-name guest=test-bios,debug-threads=on \
+-S \
+-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-test-bios/master-key.aes"}' \
+-blockdev '{"driver":"file","filename":"/var/lib/libvirt/qemu/nvram/test-bios.fd","node-name":"libvirt-pflash0-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-pflash0-format","read-only":false,"driver":"raw","file":"libvirt-pflash0-storage"}' \
+-blockdev '{"driver":"file","filename":"/some/vars/path.fd","node-name":"libvirt-pflash1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-pflash1-format","read-only":false,"driver":"raw","file":"libvirt-pflash1-storage"}' \
+-machine pc,usb=off,dump-guest-core=off,pflash0=libvirt-pflash0-format,pflash1=libvirt-pflash1-format,memory-backend=pc.ram \
+-accel tcg \
+-cpu qemu64 \
+-m 1024 \
+-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":1073741824}' \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 362d1fc1-df7d-193e-5c18-49a71bd1da66 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot menu=on,strict=on \
+-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
+-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1","node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \
+-device '{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-1-format","id":"ide0-0-0","bootindex":1}' \
+-device '{"driver":"usb-tablet","id":"input0","bus":"usb.0","port":"1"}' \
+-audiodev '{"id":"audio1","driver":"none"}' \
+-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/bios-nvram-rw-vars.xml b/tests/qemuxml2argvdata/bios-nvram-rw-vars.xml
new file mode 100644
index 0000000000..12fdb251f3
--- /dev/null
+++ b/tests/qemuxml2argvdata/bios-nvram-rw-vars.xml
@@ -0,0 +1,36 @@
+<domain type='qemu'>
+  <name>test-bios</name>
+  <uuid>362d1fc1-df7d-193e-5c18-49a71bd1da66</uuid>
+  <memory unit='KiB'>1048576</memory>
+  <currentMemory unit='KiB'>1048576</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+    <loader readonly='no' type='pflash'>/var/lib/libvirt/qemu/nvram/test-bios.fd</loader>
+    <nvram>/some/vars/path.fd</nvram>
+    <boot dev='hd'/>
+    <bootmenu enable='yes'/>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='tablet' bus='usb'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index a7e8246d38..a43f19b7a6 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1270,6 +1270,9 @@ mymain(void)
     DO_TEST_PARSE_ERROR_NOCAPS("bios-nvram-no-path");
     DO_TEST_CAPS_LATEST("bios-nvram-rw");
     DO_TEST_CAPS_LATEST("bios-nvram-rw-implicit");
+    DO_TEST_PARSE_ERROR_NOCAPS("bios-nvram-rw-template");
+    DO_TEST_CAPS_LATEST("bios-nvram-rw-template-vars");
+    DO_TEST_CAPS_LATEST("bios-nvram-rw-vars");
     DO_TEST("bios-nvram-secure",
             QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
             QEMU_CAPS_DEVICE_PCI_BRIDGE,
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux