From dffdac06c05a16b440819f1f9fdfc1f9d2a38349 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Mon, 21 Nov 2016 15:40:23 +0100 Subject: [PATCH] virt-aa-helper: fix parsing security labels by introducing VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When virt-aa-helper parses xml content it can fail on security labels. It fails by requiring to parse active domain content on seclabels that are not yet filled in. Testcase with virt-aa-helper on a minimal xml: $ cat << EOF > /tmp/test.xml test-seclabel 12345678-9abc-def1-2345-6789abcdef00 1 hvm EOF $ /usr/lib/libvirt/virt-aa-helper -d -r -p 0 \ -u libvirt-12345678-9abc-def1-2345-6789abcdef00 < /tmp/test.xml Current Result: virt-aa-helper: error: could not parse XML virt-aa-helper: error: could not get VM definition Expected Result is a valid apparmor profile Signed-off-by: Christian Ehrhardt Signed-off-by: Guido Günther --- src/conf/domain_conf.c | 6 ++++-- src/conf/domain_conf.h | 2 ++ src/security/virt-aa-helper.c | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5d2bc8dfe3..b001efc809 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16372,8 +16372,10 @@ virDomainDefParseXML(xmlDocPtr xml, /* analysis of security label, done early even though we format it * late, so devices can refer to this for defaults */ - if (virSecurityLabelDefsParseXML(def, ctxt, caps, flags) == -1) - goto error; + if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) { + if (virSecurityLabelDefsParseXML(def, ctxt, caps, flags) == -1) + goto error; + } /* Extract domain memory */ if (virDomainParseMemory("./memory[1]", NULL, ctxt, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3dfd7803df..4447b035b4 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2684,6 +2684,8 @@ typedef enum { VIR_DOMAIN_DEF_PARSE_ABI_UPDATE = 1 << 9, /* skip definition validation checks meant to be executed on define time only */ VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE = 1 << 10, + /* skip parsing of security labels */ + VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL = 1 << 11, } virDomainDefParseFlags; typedef enum { diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 77eeaff4fa..5f5d1cd710 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -705,6 +705,7 @@ get_definition(vahControl * ctl, const char *xmlStr) ctl->def = virDomainDefParseString(xmlStr, ctl->caps, ctl->xmlopt, NULL, + VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); if (ctl->def == NULL) { -- GitLab