render / rpms / libvirt

Forked from rpms/libvirt 7 months ago
Clone
49d448
From 07fb786e0d17bd395333d276ebbaad42c72ee358 Mon Sep 17 00:00:00 2001
49d448
Message-Id: <07fb786e0d17bd395333d276ebbaad42c72ee358@dist-git>
49d448
From: David Michael <david@bigbadwolfsecurity.com>
49d448
Date: Tue, 28 Jun 2022 08:33:41 -0400
49d448
Subject: [PATCH] security_selinux.c: Relabel existing mode="bind" UNIX sockets
49d448
49d448
This supports sockets created by libvirt and passed by FD using the
49d448
same method as in security_dac.c.
49d448
49d448
Signed-off-by: David Michael <david@bigbadwolfsecurity.com>
49d448
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
49d448
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
49d448
(cherry picked from commit 9f13f54a6348b54170f7de3595039c99b9da72c7)
49d448
49d448
https://bugzilla.redhat.com/show_bug.cgi?id=2101575
49d448
49d448
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
49d448
---
49d448
 src/security/security_selinux.c            | 9 +++++++--
49d448
 tests/securityselinuxlabeldata/chardev.txt | 2 +-
49d448
 2 files changed, 8 insertions(+), 3 deletions(-)
49d448
49d448
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
49d448
index 0952431064..b90e819fd2 100644
49d448
--- a/src/security/security_selinux.c
49d448
+++ b/src/security/security_selinux.c
49d448
@@ -2545,7 +2545,12 @@ virSecuritySELinuxSetChardevLabel(virSecurityManager *mgr,
49d448
         break;
49d448
 
49d448
     case VIR_DOMAIN_CHR_TYPE_UNIX:
49d448
-        if (!dev_source->data.nix.listen) {
49d448
+        if (!dev_source->data.nix.listen ||
49d448
+            (dev_source->data.nix.path &&
49d448
+             virFileExists(dev_source->data.nix.path))) {
49d448
+            /* Also label mode='bind' sockets if they exist,
49d448
+             * e.g. because they were created by libvirt
49d448
+             * and passed via FD */
49d448
             if (virSecuritySELinuxSetFilecon(mgr,
49d448
                                              dev_source->data.nix.path,
49d448
                                              imagelabel,
49d448
@@ -2622,7 +2627,7 @@ virSecuritySELinuxRestoreChardevLabel(virSecurityManager *mgr,
49d448
     case VIR_DOMAIN_CHR_TYPE_UNIX:
49d448
         if (!dev_source->data.nix.listen) {
49d448
             if (virSecuritySELinuxRestoreFileLabel(mgr,
49d448
-                                                   dev_source->data.file.path,
49d448
+                                                   dev_source->data.nix.path,
49d448
                                                    true) < 0)
49d448
                 goto done;
49d448
         }
49d448
diff --git a/tests/securityselinuxlabeldata/chardev.txt b/tests/securityselinuxlabeldata/chardev.txt
49d448
index 3f4b6302b9..bdb367f7a5 100644
49d448
--- a/tests/securityselinuxlabeldata/chardev.txt
49d448
+++ b/tests/securityselinuxlabeldata/chardev.txt
49d448
@@ -2,6 +2,6 @@
49d448
 /plain.dev;system_u:object_r:svirt_image_t:s0:c41,c264
49d448
 /plain.fifo;system_u:object_r:svirt_image_t:s0:c41,c264
49d448
 /nolabel.sock;
49d448
-/plain.sock;
49d448
+/plain.sock;system_u:object_r:svirt_image_t:s0:c41,c264
49d448
 /yeslabel.sock;system_u:object_r:svirt_image_t:s0:c41,c264
49d448
 /altlabel.sock;system_u:object_r:svirt_image_custom_t:s0:c41,c264
49d448
-- 
49d448
2.35.1
49d448