render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
404507
From 093bf98d1a85c1032228bb5bc2089bdd67949e48 Mon Sep 17 00:00:00 2001
404507
Message-Id: <093bf98d1a85c1032228bb5bc2089bdd67949e48@dist-git>
404507
From: Pavel Hrdina <phrdina@redhat.com>
404507
Date: Tue, 5 Dec 2017 14:02:33 +0100
404507
Subject: [PATCH] security: introduce
404507
 virSecurityManager(Set|Restore)ChardevLabel
404507
404507
SELinux and DAC drivers already have both functions but they were not
404507
exported as public API of security manager.
404507
404507
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
404507
(cherry picked from commit 1b4f66ec80d7751d4f4c858ffc8d5e3b936e72de)
404507
404507
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1465833
404507
404507
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
404507
Reviewed-by: Erik Skultety <eskultet@redhat.com>
404507
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
404507
---
404507
 src/libvirt_private.syms        |  2 ++
404507
 src/security/security_dac.c     |  3 +++
404507
 src/security/security_driver.h  | 11 +++++++++++
404507
 src/security/security_manager.c | 40 ++++++++++++++++++++++++++++++++++++++
404507
 src/security/security_manager.h | 10 ++++++++++
404507
 src/security/security_nop.c     | 20 +++++++++++++++++++
404507
 src/security/security_selinux.c |  3 +++
404507
 src/security/security_stack.c   | 43 +++++++++++++++++++++++++++++++++++++++++
404507
 8 files changed, 132 insertions(+)
404507
404507
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
404507
index 19c1ecc408..cb76bbac87 100644
404507
--- a/src/libvirt_private.syms
404507
+++ b/src/libvirt_private.syms
404507
@@ -1273,6 +1273,7 @@ virSecurityManagerPreFork;
404507
 virSecurityManagerReleaseLabel;
404507
 virSecurityManagerReserveLabel;
404507
 virSecurityManagerRestoreAllLabel;
404507
+virSecurityManagerRestoreChardevLabel;
404507
 virSecurityManagerRestoreDiskLabel;
404507
 virSecurityManagerRestoreHostdevLabel;
404507
 virSecurityManagerRestoreImageLabel;
404507
@@ -1280,6 +1281,7 @@ virSecurityManagerRestoreInputLabel;
404507
 virSecurityManagerRestoreMemoryLabel;
404507
 virSecurityManagerRestoreSavedStateLabel;
404507
 virSecurityManagerSetAllLabel;
404507
+virSecurityManagerSetChardevLabel;
404507
 virSecurityManagerSetChildProcessLabel;
404507
 virSecurityManagerSetDaemonSocketLabel;
404507
 virSecurityManagerSetDiskLabel;
404507
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
404507
index 24d9264216..4e787fb038 100644
404507
--- a/src/security/security_dac.c
404507
+++ b/src/security/security_dac.c
404507
@@ -2135,4 +2135,7 @@ virSecurityDriver virSecurityDriverDAC = {
404507
     .getBaseLabel                       = virSecurityDACGetBaseLabel,
404507
 
404507
     .domainSetPathLabel                 = virSecurityDACDomainSetPathLabel,
404507
+
404507
+    .domainSetSecurityChardevLabel      = virSecurityDACSetChardevLabel,
404507
+    .domainRestoreSecurityChardevLabel  = virSecurityDACRestoreChardevLabel,
404507
 };
404507
diff --git a/src/security/security_driver.h b/src/security/security_driver.h
404507
index 1b3070d06d..47dad8ba20 100644
404507
--- a/src/security/security_driver.h
404507
+++ b/src/security/security_driver.h
404507
@@ -140,6 +140,14 @@ typedef int (*virSecurityDomainRestoreInputLabel) (virSecurityManagerPtr mgr,
404507
 typedef int (*virSecurityDomainSetPathLabel) (virSecurityManagerPtr mgr,
404507
                                               virDomainDefPtr def,
404507
                                               const char *path);
404507
+typedef int (*virSecurityDomainSetChardevLabel) (virSecurityManagerPtr mgr,
404507
+                                                 virDomainDefPtr def,
404507
+                                                 virDomainChrSourceDefPtr dev_source,
404507
+                                                 bool chardevStdioLogd);
404507
+typedef int (*virSecurityDomainRestoreChardevLabel) (virSecurityManagerPtr mgr,
404507
+                                                     virDomainDefPtr def,
404507
+                                                     virDomainChrSourceDefPtr dev_source,
404507
+                                                     bool chardevStdioLogd);
404507
 
404507
 
404507
 struct _virSecurityDriver {
404507
@@ -201,6 +209,9 @@ struct _virSecurityDriver {
404507
     virSecurityDriverGetBaseLabel getBaseLabel;
404507
 
404507
     virSecurityDomainSetPathLabel domainSetPathLabel;
404507
+
404507
+    virSecurityDomainSetChardevLabel domainSetSecurityChardevLabel;
404507
+    virSecurityDomainRestoreChardevLabel domainRestoreSecurityChardevLabel;
404507
 };
404507
 
404507
 virSecurityDriverPtr virSecurityDriverLookup(const char *name,
404507
diff --git a/src/security/security_manager.c b/src/security/security_manager.c
404507
index 3cf12188a0..9249aba1fa 100644
404507
--- a/src/security/security_manager.c
404507
+++ b/src/security/security_manager.c
404507
@@ -1152,3 +1152,43 @@ virSecurityManagerRestoreInputLabel(virSecurityManagerPtr mgr,
404507
     virReportUnsupportedError();
404507
     return -1;
404507
 }
404507
+
404507
+
404507
+int
404507
+virSecurityManagerSetChardevLabel(virSecurityManagerPtr mgr,
404507
+                                  virDomainDefPtr def,
404507
+                                  virDomainChrSourceDefPtr dev_source,
404507
+                                  bool chardevStdioLogd)
404507
+{
404507
+    if (mgr->drv->domainSetSecurityChardevLabel) {
404507
+        int ret;
404507
+        virObjectLock(mgr);
404507
+        ret = mgr->drv->domainSetSecurityChardevLabel(mgr, def, dev_source,
404507
+                                                      chardevStdioLogd);
404507
+        virObjectUnlock(mgr);
404507
+        return ret;
404507
+    }
404507
+
404507
+    virReportUnsupportedError();
404507
+    return -1;
404507
+}
404507
+
404507
+
404507
+int
404507
+virSecurityManagerRestoreChardevLabel(virSecurityManagerPtr mgr,
404507
+                                      virDomainDefPtr def,
404507
+                                      virDomainChrSourceDefPtr dev_source,
404507
+                                      bool chardevStdioLogd)
404507
+{
404507
+    if (mgr->drv->domainRestoreSecurityChardevLabel) {
404507
+        int ret;
404507
+        virObjectLock(mgr);
404507
+        ret = mgr->drv->domainRestoreSecurityChardevLabel(mgr, def, dev_source,
404507
+                                                          chardevStdioLogd);
404507
+        virObjectUnlock(mgr);
404507
+        return ret;
404507
+    }
404507
+
404507
+    virReportUnsupportedError();
404507
+    return -1;
404507
+}
404507
diff --git a/src/security/security_manager.h b/src/security/security_manager.h
404507
index 87fe890692..acc0dab374 100644
404507
--- a/src/security/security_manager.h
404507
+++ b/src/security/security_manager.h
404507
@@ -184,4 +184,14 @@ int virSecurityManagerDomainSetPathLabel(virSecurityManagerPtr mgr,
404507
                                          virDomainDefPtr vm,
404507
                                          const char *path);
404507
 
404507
+int virSecurityManagerSetChardevLabel(virSecurityManagerPtr mgr,
404507
+                                      virDomainDefPtr def,
404507
+                                      virDomainChrSourceDefPtr dev_source,
404507
+                                      bool chardevStdioLogd);
404507
+
404507
+int virSecurityManagerRestoreChardevLabel(virSecurityManagerPtr mgr,
404507
+                                          virDomainDefPtr def,
404507
+                                          virDomainChrSourceDefPtr dev_source,
404507
+                                          bool chardevStdioLogd);
404507
+
404507
 #endif /* VIR_SECURITY_MANAGER_H__ */
404507
diff --git a/src/security/security_nop.c b/src/security/security_nop.c
404507
index cfb032c686..ff739f8199 100644
404507
--- a/src/security/security_nop.c
404507
+++ b/src/security/security_nop.c
404507
@@ -262,6 +262,23 @@ virSecurityDomainInputLabelNop(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
404507
     return 0;
404507
 }
404507
 
404507
+static int
404507
+virSecurityDomainSetChardevLabelNop(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
404507
+                                    virDomainDefPtr def ATTRIBUTE_UNUSED,
404507
+                                    virDomainChrSourceDefPtr dev_source ATTRIBUTE_UNUSED,
404507
+                                    bool chardevStdioLogd ATTRIBUTE_UNUSED)
404507
+{
404507
+    return 0;
404507
+}
404507
+
404507
+static int
404507
+virSecurityDomainRestoreChardevLabelNop(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
404507
+                                        virDomainDefPtr def ATTRIBUTE_UNUSED,
404507
+                                        virDomainChrSourceDefPtr dev_source ATTRIBUTE_UNUSED,
404507
+                                        bool chardevStdioLogd ATTRIBUTE_UNUSED)
404507
+{
404507
+    return 0;
404507
+}
404507
 
404507
 virSecurityDriver virSecurityDriverNop = {
404507
     .privateDataLen                     = 0,
404507
@@ -314,4 +331,7 @@ virSecurityDriver virSecurityDriverNop = {
404507
     .domainGetSecurityMountOptions      = virSecurityDomainGetMountOptionsNop,
404507
 
404507
     .getBaseLabel                       = virSecurityGetBaseLabel,
404507
+
404507
+    .domainSetSecurityChardevLabel      = virSecurityDomainSetChardevLabelNop,
404507
+    .domainRestoreSecurityChardevLabel  = virSecurityDomainRestoreChardevLabelNop,
404507
 };
404507
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
404507
index d44de72e02..0121b22da5 100644
404507
--- a/src/security/security_selinux.c
404507
+++ b/src/security/security_selinux.c
404507
@@ -3089,4 +3089,7 @@ virSecurityDriver virSecurityDriverSELinux = {
404507
     .getBaseLabel                       = virSecuritySELinuxGetBaseLabel,
404507
 
404507
     .domainSetPathLabel                 = virSecuritySELinuxDomainSetPathLabel,
404507
+
404507
+    .domainSetSecurityChardevLabel      = virSecuritySELinuxSetChardevLabel,
404507
+    .domainRestoreSecurityChardevLabel  = virSecuritySELinuxRestoreChardevLabel,
404507
 };
404507
diff --git a/src/security/security_stack.c b/src/security/security_stack.c
404507
index cd916382b2..0375e7d89d 100644
404507
--- a/src/security/security_stack.c
404507
+++ b/src/security/security_stack.c
404507
@@ -719,6 +719,46 @@ virSecurityStackDomainSetPathLabel(virSecurityManagerPtr mgr,
404507
     return rc;
404507
 }
404507
 
404507
+static int
404507
+virSecurityStackDomainSetChardevLabel(virSecurityManagerPtr mgr,
404507
+                                      virDomainDefPtr def,
404507
+                                      virDomainChrSourceDefPtr dev_source,
404507
+                                      bool chardevStdioLogd)
404507
+{
404507
+    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
404507
+    virSecurityStackItemPtr item = priv->itemsHead;
404507
+    int rc = 0;
404507
+
404507
+    for (; item; item = item->next) {
404507
+        if (virSecurityManagerSetChardevLabel(item->securityManager,
404507
+                                              def, dev_source,
404507
+                                              chardevStdioLogd) < 0)
404507
+            rc = -1;
404507
+    }
404507
+
404507
+    return rc;
404507
+}
404507
+
404507
+static int
404507
+virSecurityStackDomainRestoreChardevLabel(virSecurityManagerPtr mgr,
404507
+                                          virDomainDefPtr def,
404507
+                                          virDomainChrSourceDefPtr dev_source,
404507
+                                          bool chardevStdioLogd)
404507
+{
404507
+    virSecurityStackDataPtr priv = virSecurityManagerGetPrivateData(mgr);
404507
+    virSecurityStackItemPtr item = priv->itemsHead;
404507
+    int rc = 0;
404507
+
404507
+    for (; item; item = item->next) {
404507
+        if (virSecurityManagerRestoreChardevLabel(item->securityManager,
404507
+                                                  def, dev_source,
404507
+                                                  chardevStdioLogd) < 0)
404507
+            rc = -1;
404507
+    }
404507
+
404507
+    return rc;
404507
+}
404507
+
404507
 virSecurityDriver virSecurityDriverStack = {
404507
     .privateDataLen                     = sizeof(virSecurityStackData),
404507
     .name                               = "stack",
404507
@@ -778,4 +818,7 @@ virSecurityDriver virSecurityDriverStack = {
404507
     .getBaseLabel                       = virSecurityStackGetBaseLabel,
404507
 
404507
     .domainSetPathLabel                 = virSecurityStackDomainSetPathLabel,
404507
+
404507
+    .domainSetSecurityChardevLabel      = virSecurityStackDomainSetChardevLabel,
404507
+    .domainRestoreSecurityChardevLabel  = virSecurityStackDomainRestoreChardevLabel,
404507
 };
404507
-- 
404507
2.15.1
404507