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