render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
43fe83
From 83edaa14dafc6fc409ad4c9e2b89351c3f519602 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <83edaa14dafc6fc409ad4c9e2b89351c3f519602.1378475168.git.jdenemar@redhat.com>
43fe83
From: Eric Blake <eblake@redhat.com>
43fe83
Date: Tue, 20 Aug 2013 11:08:54 -0600
43fe83
Subject: [PATCH] selinux: distinguish failure to label from request to avoid
43fe83
 label
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=924153
43fe83
43fe83
Commit 904e05a2 (v0.9.9) added a per-<disk> seclabel element with
43fe83
an attribute relabel='no' in order to try and minimize the
43fe83
impact of shutdown delays when an NFS server disappears.  The idea
43fe83
was that if a disk is on NFS and can't be labeled in the first
43fe83
place, there is no need to attempt the (no-op) relabel on domain
43fe83
shutdown.  Unfortunately, the way this was implemented was by
43fe83
modifying the domain XML so that the optimization would survive
43fe83
libvirtd restart, but in a way that is indistinguishable from an
43fe83
explicit user setting.  Furthermore, once the setting is turned
43fe83
on, libvirt avoids attempts at labeling, even for operations like
43fe83
snapshot or blockcopy where the chain is being extended or pivoted
43fe83
onto non-NFS, where SELinux labeling is once again possible.  As
43fe83
a result, it was impossible to do a blockcopy to pivot from an
43fe83
NFS image file onto a local file.
43fe83
43fe83
The solution is to separate the semantics of a chain that must
43fe83
not be labeled (which the user can set even on persistent domains)
43fe83
vs. the optimization of not attempting a relabel on cleanup (a
43fe83
live-only annotation), and using only the user's explicit notation
43fe83
rather than the optimization as the decision on whether to skip
43fe83
a label attempt in the first place.  When upgrading an older
43fe83
libvirtd to a newer, an NFS volume will still attempt the relabel;
43fe83
but as the avoidance of a relabel was only an optimization, this
43fe83
shouldn't cause any problems.
43fe83
43fe83
In the ideal future, libvirt will eventually have XML describing
43fe83
EVERY file in the backing chain, with each file having a separate
43fe83
<seclabel> element.  At that point, libvirt will be able to track
43fe83
more closely which files need a relabel attempt at shutdown.  But
43fe83
until we reach that point, the single <seclabel> for the entire
43fe83
<disk> chain is treated as a hint - when a chain has only one
43fe83
file, then we know it is accurate; but if the chain has more than
43fe83
one file, we have to attempt relabel in spite of the attribute,
43fe83
in case part of the chain is local and SELinux mattered for that
43fe83
portion of the chain.
43fe83
43fe83
* src/conf/domain_conf.h (_virSecurityDeviceLabelDef): Add new
43fe83
member.
43fe83
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML):
43fe83
Parse it, for live images only.
43fe83
(virSecurityDeviceLabelDefFormat): Output it.
43fe83
(virDomainDiskDefParseXML, virDomainChrSourceDefParseXML)
43fe83
(virDomainDiskSourceDefFormat, virDomainChrDefFormat)
43fe83
(virDomainDiskDefFormat): Pass flags on through.
43fe83
* src/security/security_selinux.c
43fe83
(virSecuritySELinuxRestoreSecurityImageLabelInt): Honor labelskip
43fe83
when possible.
43fe83
(virSecuritySELinuxSetSecurityFileLabel): Set labelskip, not
43fe83
norelabel, if labeling fails.
43fe83
(virSecuritySELinuxSetFileconHelper): Fix indentation.
43fe83
* docs/formatdomain.html.in (seclabel): Document new xml.
43fe83
* docs/schemas/domaincommon.rng (devSeclabel): Allow it in RNG.
43fe83
* tests/qemuxml2argvdata/qemuxml2argv-seclabel-*-labelskip.xml:
43fe83
* tests/qemuxml2argvdata/qemuxml2argv-seclabel-*-labelskip.args:
43fe83
* tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-*-labelskip.xml:
43fe83
New test files.
43fe83
* tests/qemuxml2argvtest.c (mymain): Run the new tests.
43fe83
* tests/qemuxml2xmltest.c (mymain): Likewise.
43fe83
43fe83
Signed-off-by: Eric Blake <eblake@redhat.com>
43fe83
(cherry picked from commit 0f082e699eda0ad14965c0bc75789c4bfac2bda7)
43fe83
---
43fe83
 docs/formatdomain.html.in                          |  6 ++-
43fe83
 docs/schemas/domaincommon.rng                      | 27 +++++++------
43fe83
 src/conf/domain_conf.c                             | 47 ++++++++++++++++------
43fe83
 src/conf/domain_conf.h                             |  3 +-
43fe83
 src/security/security_selinux.c                    | 18 ++++++---
43fe83
 .../qemuxml2argv-seclabel-dynamic-labelskip.args   |  5 +++
43fe83
 .../qemuxml2argv-seclabel-dynamic-labelskip.xml    | 32 +++++++++++++++
43fe83
 .../qemuxml2argv-seclabel-static-labelskip.args    |  5 +++
43fe83
 .../qemuxml2argv-seclabel-static-labelskip.xml     | 33 +++++++++++++++
43fe83
 tests/qemuxml2argvtest.c                           |  2 +
43fe83
 .../qemuxml2xmlout-seclabel-dynamic-labelskip.xml  | 31 ++++++++++++++
43fe83
 tests/qemuxml2xmltest.c                            |  8 ++--
43fe83
 12 files changed, 182 insertions(+), 35 deletions(-)
43fe83
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-labelskip.args
43fe83
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-labelskip.xml
43fe83
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-seclabel-static-labelskip.args
43fe83
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-seclabel-static-labelskip.xml
43fe83
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-dynamic-labelskip.xml
43fe83
43fe83
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
43fe83
index 3fd83c9..4308dbe 100644
43fe83
--- a/docs/formatdomain.html.in
43fe83
+++ b/docs/formatdomain.html.in
43fe83
@@ -5129,7 +5129,11 @@ qemu-kvm -net nic,model=? /dev/null
43fe83
       a seclabel element is attached to a specific path
43fe83
       rather than the top-level domain assignment, only the
43fe83
       attribute relabel or the
43fe83
-      sub-element label are supported.
43fe83
+      sub-element label are supported.  Additionally,
43fe83
+      since 1.1.2, an output-only
43fe83
+      element labelskip will be present for active
43fe83
+      domains on disks where labeling was skipped due to the image
43fe83
+      being on a file system that lacks security labeling.
43fe83
     

43fe83
 
43fe83
     

Example configs

43fe83
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
43fe83
index ac807e6..dfcd61c 100644
43fe83
--- a/docs/schemas/domaincommon.rng
43fe83
+++ b/docs/schemas/domaincommon.rng
43fe83
@@ -152,34 +152,35 @@
43fe83
   <define name="devSeclabel">
43fe83
     <element name="seclabel">
43fe83
       
43fe83
-           relabel=no or a <label> must be present.  -->
43fe83
+           relabel=no or a <label> must be present on input;
43fe83
+           output also can include labelskip=yes.  -->
43fe83
+      <optional>
43fe83
+        <attribute name='model'>
43fe83
+          <text/>
43fe83
+        </attribute>
43fe83
+      </optional>
43fe83
       <choice>
43fe83
         <group>
43fe83
-          <optional>
43fe83
-            <attribute name='model'>
43fe83
-              <text/>
43fe83
-            </attribute>
43fe83
-          </optional>
43fe83
           <attribute name='relabel'>
43fe83
             <value>no</value>
43fe83
           </attribute>
43fe83
         </group>
43fe83
         <group>
43fe83
-          <optional>
43fe83
-            <attribute name='model'>
43fe83
-              <text/>
43fe83
-            </attribute>
43fe83
-          </optional>
43fe83
+          <attribute name='labelskip'>
43fe83
+            <value>yes</value>
43fe83
+          </attribute>
43fe83
+        </group>
43fe83
+        <group>
43fe83
           <optional>
43fe83
             <attribute name='relabel'>
43fe83
               <value>yes</value>
43fe83
             </attribute>
43fe83
           </optional>
43fe83
-          <zeroOrMore>
43fe83
+          <oneOrMore>
43fe83
             <element name='label'>
43fe83
               <text/>
43fe83
             </element>
43fe83
-          </zeroOrMore>
43fe83
+          </oneOrMore>
43fe83
         </group>
43fe83
       </choice>
43fe83
     </element>
43fe83
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
43fe83
index 53daf73..d6b4ea7 100644
43fe83
--- a/src/conf/domain_conf.c
43fe83
+++ b/src/conf/domain_conf.c
43fe83
@@ -4484,7 +4484,8 @@ static int
43fe83
 virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn,
43fe83
                                   size_t *nseclabels_rtn,
43fe83
                                   virSecurityLabelDefPtr *vmSeclabels,
43fe83
-                                  int nvmSeclabels, xmlXPathContextPtr ctxt)
43fe83
+                                  int nvmSeclabels, xmlXPathContextPtr ctxt,
43fe83
+                                  unsigned int flags)
43fe83
 {
43fe83
     virSecurityDeviceLabelDefPtr *seclabels;
43fe83
     size_t nseclabels = 0;
43fe83
@@ -4492,7 +4493,7 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn,
43fe83
     size_t i, j;
43fe83
     xmlNodePtr *list = NULL;
43fe83
     virSecurityLabelDefPtr vmDef = NULL;
43fe83
-    char *model, *relabel, *label;
43fe83
+    char *model, *relabel, *label, *labelskip;
43fe83
 
43fe83
     if ((n = virXPathNodeSet("./seclabel", ctxt, &list)) < 0)
43fe83
         goto error;
43fe83
@@ -4547,6 +4548,13 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDefPtr **seclabels_rtn,
43fe83
             seclabels[i]->norelabel = false;
43fe83
         }
43fe83
 
43fe83
+        /* labelskip is only parsed on live images */
43fe83
+        labelskip = virXMLPropString(list[i], "labelskip");
43fe83
+        seclabels[i]->labelskip = false;
43fe83
+        if (labelskip && !(flags & VIR_DOMAIN_XML_INACTIVE))
43fe83
+            seclabels[i]->labelskip = STREQ(labelskip, "yes");
43fe83
+        VIR_FREE(labelskip);
43fe83
+
43fe83
         ctxt->node = list[i];
43fe83
         label = virXPathStringLimit("string(./label)",
43fe83
                                     VIR_SECURITY_LABEL_BUFLEN-1, ctxt);
43fe83
@@ -5208,7 +5216,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
43fe83
                                               &def->nseclabels,
43fe83
                                               vmSeclabels,
43fe83
                                               nvmSeclabels,
43fe83
-                                              ctxt) < 0)
43fe83
+                                              ctxt,
43fe83
+                                              flags) < 0)
43fe83
             goto error;
43fe83
         ctxt->node = saved_node;
43fe83
     }
43fe83
@@ -6884,7 +6893,8 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
43fe83
                                                           &chr_def->nseclabels,
43fe83
                                                           vmSeclabels,
43fe83
                                                           nvmSeclabels,
43fe83
-                                                          ctxt) < 0) {
43fe83
+                                                          ctxt,
43fe83
+                                                          flags) < 0) {
43fe83
                         ctxt->node = saved_node;
43fe83
                         goto error;
43fe83
                     }
43fe83
@@ -14028,14 +14038,23 @@ virSecurityLabelDefFormat(virBufferPtr buf, virSecurityLabelDefPtr def)
43fe83
 
43fe83
 static void
43fe83
 virSecurityDeviceLabelDefFormat(virBufferPtr buf,
43fe83
-                                virSecurityDeviceLabelDefPtr def)
43fe83
+                                virSecurityDeviceLabelDefPtr def,
43fe83
+                                unsigned int flags)
43fe83
 {
43fe83
+    /* For offline output, skip elements that allow labels but have no
43fe83
+     * label specified (possible if labelskip was ignored on input).  */
43fe83
+    if ((flags & VIR_DOMAIN_XML_INACTIVE) && !def->label && !def->norelabel)
43fe83
+        return;
43fe83
+
43fe83
     virBufferAddLit(buf, "
43fe83
 
43fe83
     if (def->model)
43fe83
         virBufferAsprintf(buf, " model='%s'", def->model);
43fe83
 
43fe83
-    virBufferAsprintf(buf, " relabel='%s'", def->norelabel ? "no" : "yes");
43fe83
+    if (def->labelskip)
43fe83
+        virBufferAddLit(buf, " labelskip='yes'");
43fe83
+    else
43fe83
+        virBufferAsprintf(buf, " relabel='%s'", def->norelabel ? "no" : "yes");
43fe83
 
43fe83
     if (def->label) {
43fe83
         virBufferAddLit(buf, ">\n");
43fe83
@@ -14110,7 +14129,8 @@ virDomainDiskBlockIoDefFormat(virBufferPtr buf,
43fe83
 
43fe83
 static int
43fe83
 virDomainDiskSourceDefFormat(virBufferPtr buf,
43fe83
-                             virDomainDiskDefPtr def)
43fe83
+                             virDomainDiskDefPtr def,
43fe83
+                             unsigned int flags)
43fe83
 {
43fe83
     int n;
43fe83
     const char *startupPolicy = virDomainStartupPolicyTypeToString(def->startupPolicy);
43fe83
@@ -14129,7 +14149,8 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
43fe83
                 virBufferAddLit(buf, ">\n");
43fe83
                 virBufferAdjustIndent(buf, 8);
43fe83
                 for (n = 0; n < def->nseclabels; n++)
43fe83
-                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n]);
43fe83
+                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n],
43fe83
+                                                    flags);
43fe83
                 virBufferAdjustIndent(buf, -8);
43fe83
                 virBufferAddLit(buf, "      </source>\n");
43fe83
             } else {
43fe83
@@ -14146,7 +14167,8 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
43fe83
                 virBufferAddLit(buf, ">\n");
43fe83
                 virBufferAdjustIndent(buf, 8);
43fe83
                 for (n = 0; n < def->nseclabels; n++)
43fe83
-                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n]);
43fe83
+                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n],
43fe83
+                                                    flags);
43fe83
                 virBufferAdjustIndent(buf, -8);
43fe83
                 virBufferAddLit(buf, "      </source>\n");
43fe83
             } else {
43fe83
@@ -14211,7 +14233,8 @@ virDomainDiskSourceDefFormat(virBufferPtr buf,
43fe83
                 virBufferAddLit(buf, ">\n");
43fe83
                 virBufferAdjustIndent(buf, 8);
43fe83
                 for (n = 0; n < def->nseclabels; n++)
43fe83
-                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n]);
43fe83
+                    virSecurityDeviceLabelDefFormat(buf, def->seclabels[n],
43fe83
+                                                    flags);
43fe83
                 virBufferAdjustIndent(buf, -8);
43fe83
                 virBufferAddLit(buf, "      </source>\n");
43fe83
             } else {
43fe83
@@ -14347,7 +14370,7 @@ virDomainDiskDefFormat(virBufferPtr buf,
43fe83
         virBufferAddLit(buf, "      </auth>\n");
43fe83
     }
43fe83
 
43fe83
-    if (virDomainDiskSourceDefFormat(buf, def) < 0)
43fe83
+    if (virDomainDiskSourceDefFormat(buf, def, flags) < 0)
43fe83
         return -1;
43fe83
     virDomainDiskGeometryDefFormat(buf, def);
43fe83
     virDomainDiskBlockIoDefFormat(buf, def);
43fe83
@@ -15199,7 +15222,7 @@ virDomainChrDefFormat(virBufferPtr buf,
43fe83
     if (def->seclabels && def->nseclabels > 0) {
43fe83
         virBufferAdjustIndent(buf, 2);
43fe83
         for (n = 0; n < def->nseclabels; n++)
43fe83
-            virSecurityDeviceLabelDefFormat(buf, def->seclabels[n]);
43fe83
+            virSecurityDeviceLabelDefFormat(buf, def->seclabels[n], flags);
43fe83
         virBufferAdjustIndent(buf, -2);
43fe83
     }
43fe83
 
43fe83
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
43fe83
index 29ef0f8..b9e9600 100644
43fe83
--- a/src/conf/domain_conf.h
43fe83
+++ b/src/conf/domain_conf.h
43fe83
@@ -343,7 +343,8 @@ typedef virSecurityDeviceLabelDef *virSecurityDeviceLabelDefPtr;
43fe83
 struct _virSecurityDeviceLabelDef {
43fe83
     char *model;
43fe83
     char *label;        /* image label string */
43fe83
-    bool norelabel;
43fe83
+    bool norelabel;     /* true to skip label attempts */
43fe83
+    bool labelskip;     /* live-only; true if skipping failed label attempt */
43fe83
 };
43fe83
 
43fe83
 
43fe83
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
43fe83
index e3dce66a..38de060 100644
43fe83
--- a/src/security/security_selinux.c
43fe83
+++ b/src/security/security_selinux.c
43fe83
@@ -917,10 +917,10 @@ virSecuritySELinuxSetFileconHelper(const char *path, char *tcon, bool optional)
43fe83
                 security_get_boolean_active("virt_use_nfs") != 1) {
43fe83
                 msg = _("Setting security context '%s' on '%s' not supported. "
43fe83
                         "Consider setting virt_use_nfs");
43fe83
-               if (security_getenforce() == 1)
43fe83
-                   VIR_WARN(msg, tcon, path);
43fe83
-               else
43fe83
-                   VIR_INFO(msg, tcon, path);
43fe83
+                if (security_getenforce() == 1)
43fe83
+                    VIR_WARN(msg, tcon, path);
43fe83
+                else
43fe83
+                    VIR_INFO(msg, tcon, path);
43fe83
             } else {
43fe83
                 VIR_INFO("Setting security context '%s' on '%s' not supported",
43fe83
                          tcon, path);
43fe83
@@ -1135,6 +1135,14 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
43fe83
     if (seclabel->norelabel || (disk_seclabel && disk_seclabel->norelabel))
43fe83
         return 0;
43fe83
 
43fe83
+    /* If labelskip is true and there are no backing files, then we
43fe83
+     * know it is safe to skip the restore.  FIXME - backing files should
43fe83
+     * be tracked in domain XML, at which point labelskip should be a
43fe83
+     * per-file attribute instead of a disk attribute.  */
43fe83
+    if (disk_seclabel && disk_seclabel->labelskip &&
43fe83
+        !disk->backingChain)
43fe83
+        return 0;
43fe83
+
43fe83
     /* Don't restore labels on readoly/shared disks, because
43fe83
      * other VMs may still be accessing these
43fe83
      * Alternatively we could iterate over all running
43fe83
@@ -1219,7 +1227,7 @@ virSecuritySELinuxSetSecurityFileLabel(virDomainDiskDefPtr disk,
43fe83
         disk_seclabel = virDomainDiskDefGenSecurityLabelDef(SECURITY_SELINUX_NAME);
43fe83
         if (!disk_seclabel)
43fe83
             return -1;
43fe83
-        disk_seclabel->norelabel = true;
43fe83
+        disk_seclabel->labelskip = true;
43fe83
         if (VIR_APPEND_ELEMENT(disk->seclabels, disk->nseclabels,
43fe83
                                disk_seclabel) < 0) {
43fe83
             virSecurityDeviceLabelDefFree(disk_seclabel);
43fe83
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-labelskip.args b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-labelskip.args
43fe83
new file mode 100644
43fe83
index 0000000..892c6b5
43fe83
--- /dev/null
43fe83
+++ b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-labelskip.args
43fe83
@@ -0,0 +1,5 @@
43fe83
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu \
43fe83
+-name QEMUGuest1 -S -M pc -m 214 -smp 1 -nographic -monitor \
43fe83
+unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
43fe83
+-hda /dev/HostVG/QEMUGuest1 \
43fe83
+-net none -serial none -parallel none
43fe83
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-labelskip.xml b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-labelskip.xml
43fe83
new file mode 100644
43fe83
index 0000000..e3bc700
43fe83
--- /dev/null
43fe83
+++ b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-dynamic-labelskip.xml
43fe83
@@ -0,0 +1,32 @@
43fe83
+<domain type='qemu'>
43fe83
+  <name>QEMUGuest1</name>
43fe83
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
43fe83
+  <memory unit='KiB'>219100</memory>
43fe83
+  <currentMemory unit='KiB'>219100</currentMemory>
43fe83
+  <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu>
43fe83
+  <os>
43fe83
+    <type arch='i686' machine='pc'>hvm</type>
43fe83
+    <boot dev='hd'/>
43fe83
+  </os>
43fe83
+  <clock offset='utc'/>
43fe83
+  <on_poweroff>destroy</on_poweroff>
43fe83
+  <on_reboot>restart</on_reboot>
43fe83
+  <on_crash>destroy</on_crash>
43fe83
+  <devices>
43fe83
+    <emulator>/usr/bin/qemu</emulator>
43fe83
+    <disk type='block' device='disk'>
43fe83
+      <source dev='/dev/HostVG/QEMUGuest1'>
43fe83
+        <seclabel model='selinux' labelskip='yes'/>
43fe83
+      </source>
43fe83
+      <target dev='hda' bus='ide'/>
43fe83
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
43fe83
+    </disk>
43fe83
+    <controller type='usb' index='0'/>
43fe83
+    <controller type='ide' index='0'/>
43fe83
+    <controller type='pci' index='0' model='pci-root'/>
43fe83
+    <memballoon model='virtio'/>
43fe83
+  </devices>
43fe83
+  <seclabel type='dynamic' model='selinux' relabel='yes'>
43fe83
+    <baselabel>system_u:system_r:svirt_custom_t:s0</baselabel>
43fe83
+  </seclabel>
43fe83
+</domain>
43fe83
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-seclabel-static-labelskip.args b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-static-labelskip.args
43fe83
new file mode 100644
43fe83
index 0000000..892c6b5
43fe83
--- /dev/null
43fe83
+++ b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-static-labelskip.args
43fe83
@@ -0,0 +1,5 @@
43fe83
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu \
43fe83
+-name QEMUGuest1 -S -M pc -m 214 -smp 1 -nographic -monitor \
43fe83
+unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
43fe83
+-hda /dev/HostVG/QEMUGuest1 \
43fe83
+-net none -serial none -parallel none
43fe83
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-seclabel-static-labelskip.xml b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-static-labelskip.xml
43fe83
new file mode 100644
43fe83
index 0000000..a743448
43fe83
--- /dev/null
43fe83
+++ b/tests/qemuxml2argvdata/qemuxml2argv-seclabel-static-labelskip.xml
43fe83
@@ -0,0 +1,33 @@
43fe83
+<domain type='qemu' id='1'>
43fe83
+  <name>QEMUGuest1</name>
43fe83
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
43fe83
+  <memory unit='KiB'>219100</memory>
43fe83
+  <currentMemory unit='KiB'>219100</currentMemory>
43fe83
+  <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu>
43fe83
+  <os>
43fe83
+    <type arch='i686' machine='pc'>hvm</type>
43fe83
+    <boot dev='hd'/>
43fe83
+  </os>
43fe83
+  <clock offset='utc'/>
43fe83
+  <on_poweroff>destroy</on_poweroff>
43fe83
+  <on_reboot>restart</on_reboot>
43fe83
+  <on_crash>destroy</on_crash>
43fe83
+  <devices>
43fe83
+    <emulator>/usr/bin/qemu</emulator>
43fe83
+    <disk type='block' device='disk'>
43fe83
+      <source dev='/dev/HostVG/QEMUGuest1'>
43fe83
+        <seclabel model='selinux' labelskip='yes'/>
43fe83
+      </source>
43fe83
+      <target dev='hda' bus='ide'/>
43fe83
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
43fe83
+    </disk>
43fe83
+    <controller type='usb' index='0'/>
43fe83
+    <controller type='ide' index='0'/>
43fe83
+    <controller type='pci' index='0' model='pci-root'/>
43fe83
+    <memballoon model='virtio'/>
43fe83
+  </devices>
43fe83
+  <seclabel type='static' model='selinux' relabel='yes'>
43fe83
+    <label>system_u:system_r:svirt_custom_t:s0:c192,c392</label>
43fe83
+    <imagelabel>system_u:system_r:svirt_custom_t:s0:c192,c392</imagelabel>
43fe83
+  </seclabel>
43fe83
+</domain>
43fe83
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
43fe83
index 679124e..3a3c304 100644
43fe83
--- a/tests/qemuxml2argvtest.c
43fe83
+++ b/tests/qemuxml2argvtest.c
43fe83
@@ -923,8 +923,10 @@ mymain(void)
43fe83
     DO_TEST("seclabel-dynamic", QEMU_CAPS_NAME);
43fe83
     DO_TEST("seclabel-dynamic-baselabel", QEMU_CAPS_NAME);
43fe83
     DO_TEST("seclabel-dynamic-override", QEMU_CAPS_NAME);
43fe83
+    DO_TEST("seclabel-dynamic-labelskip", QEMU_CAPS_NAME);
43fe83
     DO_TEST("seclabel-static", QEMU_CAPS_NAME);
43fe83
     DO_TEST("seclabel-static-relabel", QEMU_CAPS_NAME);
43fe83
+    DO_TEST("seclabel-static-labelskip", QEMU_CAPS_NAME);
43fe83
     DO_TEST("seclabel-none", QEMU_CAPS_NAME);
43fe83
 
43fe83
     DO_TEST("pseries-basic",
43fe83
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-dynamic-labelskip.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-dynamic-labelskip.xml
43fe83
new file mode 100644
43fe83
index 0000000..0764691
43fe83
--- /dev/null
43fe83
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-dynamic-labelskip.xml
43fe83
@@ -0,0 +1,31 @@
43fe83
+<domain type='qemu'>
43fe83
+  <name>QEMUGuest1</name>
43fe83
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
43fe83
+  <memory unit='KiB'>219100</memory>
43fe83
+  <currentMemory unit='KiB'>219100</currentMemory>
43fe83
+  <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu>
43fe83
+  <os>
43fe83
+    <type arch='i686' machine='pc'>hvm</type>
43fe83
+    <boot dev='hd'/>
43fe83
+  </os>
43fe83
+  <clock offset='utc'/>
43fe83
+  <on_poweroff>destroy</on_poweroff>
43fe83
+  <on_reboot>restart</on_reboot>
43fe83
+  <on_crash>destroy</on_crash>
43fe83
+  <devices>
43fe83
+    <emulator>/usr/bin/qemu</emulator>
43fe83
+    <disk type='block' device='disk'>
43fe83
+      <source dev='/dev/HostVG/QEMUGuest1'>
43fe83
+      </source>
43fe83
+      <target dev='hda' bus='ide'/>
43fe83
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
43fe83
+    </disk>
43fe83
+    <controller type='usb' index='0'/>
43fe83
+    <controller type='ide' index='0'/>
43fe83
+    <controller type='pci' index='0' model='pci-root'/>
43fe83
+    <memballoon model='virtio'/>
43fe83
+  </devices>
43fe83
+  <seclabel type='dynamic' model='selinux' relabel='yes'>
43fe83
+    <baselabel>system_u:system_r:svirt_custom_t:s0</baselabel>
43fe83
+  </seclabel>
43fe83
+</domain>
43fe83
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
43fe83
index 5c6730d..6eebc68 100644
43fe83
--- a/tests/qemuxml2xmltest.c
43fe83
+++ b/tests/qemuxml2xmltest.c
43fe83
@@ -30,6 +30,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
43fe83
     char *actual = NULL;
43fe83
     int ret = -1;
43fe83
     virDomainDefPtr def = NULL;
43fe83
+    unsigned int flags = live ? 0 : VIR_DOMAIN_XML_INACTIVE;
43fe83
 
43fe83
     if (virtTestLoadFile(inxml, &inXmlData) < 0)
43fe83
         goto fail;
43fe83
@@ -37,11 +38,10 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
43fe83
         goto fail;
43fe83
 
43fe83
     if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt,
43fe83
-                                        QEMU_EXPECTED_VIRT_TYPES,
43fe83
-                                        live ? 0 : VIR_DOMAIN_XML_INACTIVE)))
43fe83
+                                        QEMU_EXPECTED_VIRT_TYPES, flags)))
43fe83
         goto fail;
43fe83
 
43fe83
-    if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
43fe83
+    if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE | flags)))
43fe83
         goto fail;
43fe83
 
43fe83
     if (STRNEQ(outXmlData, actual)) {
43fe83
@@ -257,7 +257,9 @@ mymain(void)
43fe83
 
43fe83
     DO_TEST_FULL("seclabel-dynamic-baselabel", false, WHEN_INACTIVE);
43fe83
     DO_TEST_FULL("seclabel-dynamic-override", false, WHEN_INACTIVE);
43fe83
+    DO_TEST_FULL("seclabel-dynamic-labelskip", true, WHEN_INACTIVE);
43fe83
     DO_TEST("seclabel-static");
43fe83
+    DO_TEST_FULL("seclabel-static-labelskip", false, WHEN_ACTIVE);
43fe83
     DO_TEST("seclabel-none");
43fe83
     DO_TEST("numad-static-vcpu-no-numatune");
43fe83
     DO_TEST("disk-scsi-lun-passthrough-sgio");
43fe83
-- 
43fe83
1.8.3.2
43fe83