c873f9
From f019023539b64742e8f1ebc38ea26a204fa0a45c Mon Sep 17 00:00:00 2001
c873f9
Message-Id: <f019023539b64742e8f1ebc38ea26a204fa0a45c@dist-git>
c873f9
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
c873f9
Date: Tue, 2 Oct 2018 14:00:41 +0200
c873f9
Subject: [PATCH] security: dac: also label listen UNIX sockets
c873f9
MIME-Version: 1.0
c873f9
Content-Type: text/plain; charset=UTF-8
c873f9
Content-Transfer-Encoding: 8bit
c873f9
c873f9
We switched to opening mode='bind' sockets ourselves:
c873f9
commit 30fb2276d88b275dc2aad6ddd28c100d944b59a5
c873f9
    qemu: support passing pre-opened UNIX socket listen FD
c873f9
in v4.5.0-rc1~251
c873f9
c873f9
Then fixed qemuBuildChrChardevStr to change libvirtd's label
c873f9
while creating the socket:
c873f9
commit b0c6300fc42bbc3e5eb0b236392f7344581c5810
c873f9
    qemu: ensure FDs passed to QEMU for chardevs have correct SELinux labels
c873f9
v4.5.0-rc1~52
c873f9
c873f9
Also add labeling of these sockets to the DAC driver.
c873f9
Instead of duplicating the logic which decides whether libvirt should
c873f9
pre-create the socket, assume an existing path meaning that it was created
c873f9
by libvirt.
c873f9
c873f9
https://bugzilla.redhat.com/show_bug.cgi?id=1633389
c873f9
c873f9
Signed-off-by: Ján Tomko <jtomko@redhat.com>
c873f9
Reviewed-by: Erik Skultety <eskultet@redhat.com>
c873f9
(cherry picked from commit d6b8838dd83697f721fe0706068df765148154de)
c873f9
Signed-off-by: Ján Tomko <jtomko@redhat.com>
c873f9
c873f9
RHEL 8.0: https://bugzilla.redhat.com/show_bug.cgi?id=1634775
c873f9
RHEL 7.6: https://bugzilla.redhat.com/show_bug.cgi?id=1635228
c873f9
c873f9
Conflicts: src/security/security_dac.c
c873f9
    commit 3ac7793ad1ae0f4dc7b7ddbcfd182d5ff0b45538
c873f9
      security_dac: Pass virSecurityManagerPtr to virSecurityDACSetOwnership
c873f9
    is not backported
c873f9
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
c873f9
---
c873f9
 src/security/security_dac.c | 7 ++++++-
c873f9
 1 file changed, 6 insertions(+), 1 deletion(-)
c873f9
c873f9
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
c873f9
index 4b623dcf39..74c70dd092 100644
c873f9
--- a/src/security/security_dac.c
c873f9
+++ b/src/security/security_dac.c
c873f9
@@ -1248,7 +1248,12 @@ virSecurityDACSetChardevLabel(virSecurityManagerPtr mgr,
c873f9
         break;
c873f9
 
c873f9
     case VIR_DOMAIN_CHR_TYPE_UNIX:
c873f9
-        if (!dev_source->data.nix.listen) {
c873f9
+        if (!dev_source->data.nix.listen ||
c873f9
+            (dev_source->data.nix.path &&
c873f9
+             virFileExists(dev_source->data.nix.path))) {
c873f9
+            /* Also label mode='bind' sockets if they exist,
c873f9
+             * e.g. because they were created by libvirt
c873f9
+             * and passed via FD */
c873f9
             if (virSecurityDACSetOwnership(priv, NULL,
c873f9
                                            dev_source->data.nix.path,
c873f9
                                            user, group) < 0)
c873f9
-- 
c873f9
2.19.0
c873f9