render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From 86f741bf77f39d4af3698b71797e430c2a6989c3 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <86f741bf77f39d4af3698b71797e430c2a6989c3@dist-git>
c480ed
From: Michal Privoznik <mprivozn@redhat.com>
c480ed
Date: Thu, 3 Jan 2019 10:03:44 +0100
c480ed
Subject: [PATCH] qemu_security: Fully implement qemuSecurityDomainSetPathLabel
c480ed
c480ed
Even though the current use of the function does not require full
c480ed
implementation with transactions (none of the callers pass a path
c480ed
somewhere under /dev), it doesn't hurt either. Moreover, in
c480ed
future patches the paradigm is going to shift so that any API
c480ed
that touches a file is required to use transactions.
c480ed
c480ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c480ed
Reviewed-by: John Ferlan <jferlan@redhat.com>
c480ed
(cherry picked from commit da24db2d30352c094f76dffb523e7f344ff8e30d)
c480ed
c480ed
https://bugzilla.redhat.com/show_bug.cgi?id=1658112
c480ed
c480ed
Signed-off-by: Erik Skultety <eskultet@redhat.com>
c480ed
Message-Id: <4de2beabd9868259f1856f7eafcc835b5b2a3d6b.1546506016.git.eskultet@redhat.com>
c480ed
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
---
c480ed
 src/qemu/qemu_domain.c   |  3 +--
c480ed
 src/qemu/qemu_process.c  | 15 ++++++---------
c480ed
 src/qemu/qemu_security.c | 30 ++++++++++++++++++++++++++++++
c480ed
 src/qemu/qemu_security.h |  6 +++++-
c480ed
 4 files changed, 42 insertions(+), 12 deletions(-)
c480ed
c480ed
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
c480ed
index 95b84af78a..c9899b9e6d 100644
c480ed
--- a/src/qemu/qemu_domain.c
c480ed
+++ b/src/qemu/qemu_domain.c
c480ed
@@ -801,8 +801,7 @@ qemuDomainWriteMasterKeyFile(virQEMUDriverPtr driver,
c480ed
         goto cleanup;
c480ed
     }
c480ed
 
c480ed
-    if (qemuSecurityDomainSetPathLabel(driver->securityManager,
c480ed
-                                       vm->def, path, false) < 0)
c480ed
+    if (qemuSecurityDomainSetPathLabel(driver, vm, path, false) < 0)
c480ed
         goto cleanup;
c480ed
 
c480ed
     ret = 0;
c480ed
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
c480ed
index 34aac69afc..c0f95dd5f1 100644
c480ed
--- a/src/qemu/qemu_process.c
c480ed
+++ b/src/qemu/qemu_process.c
c480ed
@@ -2778,8 +2778,7 @@ qemuProcessStartManagedPRDaemon(virDomainObjPtr vm)
c480ed
         virCgroupAddMachineTask(priv->cgroup, cpid) < 0)
c480ed
         goto cleanup;
c480ed
 
c480ed
-    if (qemuSecurityDomainSetPathLabel(driver->securityManager,
c480ed
-                                       vm->def, socketPath, true) < 0)
c480ed
+    if (qemuSecurityDomainSetPathLabel(driver, vm, socketPath, true) < 0)
c480ed
         goto cleanup;
c480ed
 
c480ed
     priv->prDaemonRunning = true;
c480ed
@@ -3656,7 +3655,7 @@ qemuProcessNeedMemoryBackingPath(virDomainDefPtr def,
c480ed
 
c480ed
 static int
c480ed
 qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver,
c480ed
-                                       virDomainDefPtr def,
c480ed
+                                       virDomainObjPtr vm,
c480ed
                                        const char *path,
c480ed
                                        bool build)
c480ed
 {
c480ed
@@ -3671,8 +3670,7 @@ qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver,
c480ed
             return -1;
c480ed
         }
c480ed
 
c480ed
-        if (qemuSecurityDomainSetPathLabel(driver->securityManager,
c480ed
-                                           def, path, true) < 0)
c480ed
+        if (qemuSecurityDomainSetPathLabel(driver, vm, path, true) < 0)
c480ed
             return -1;
c480ed
     } else {
c480ed
         if (virFileDeleteTree(path) < 0)
c480ed
@@ -3708,7 +3706,7 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
c480ed
             if (!path)
c480ed
                 goto cleanup;
c480ed
 
c480ed
-            if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def,
c480ed
+            if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm,
c480ed
                                                        path, build) < 0)
c480ed
                 goto cleanup;
c480ed
 
c480ed
@@ -3720,7 +3718,7 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
c480ed
         if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0)
c480ed
             goto cleanup;
c480ed
 
c480ed
-        if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def,
c480ed
+        if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm,
c480ed
                                                    path, build) < 0)
c480ed
             goto cleanup;
c480ed
 
c480ed
@@ -4904,8 +4902,7 @@ qemuProcessMakeDir(virQEMUDriverPtr driver,
c480ed
         goto cleanup;
c480ed
     }
c480ed
 
c480ed
-    if (qemuSecurityDomainSetPathLabel(driver->securityManager,
c480ed
-                                       vm->def, path, true) < 0)
c480ed
+    if (qemuSecurityDomainSetPathLabel(driver, vm, path, true) < 0)
c480ed
         goto cleanup;
c480ed
 
c480ed
     ret = 0;
c480ed
diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c
c480ed
index af3be42854..268def309a 100644
c480ed
--- a/src/qemu/qemu_security.c
c480ed
+++ b/src/qemu/qemu_security.c
c480ed
@@ -493,3 +493,33 @@ qemuSecurityCleanupTPMEmulator(virQEMUDriverPtr driver,
c480ed
 {
c480ed
     virSecurityManagerRestoreTPMLabels(driver->securityManager, def);
c480ed
 }
c480ed
+
c480ed
+
c480ed
+int
c480ed
+qemuSecurityDomainSetPathLabel(virQEMUDriverPtr driver,
c480ed
+                               virDomainObjPtr vm,
c480ed
+                               const char *path,
c480ed
+                               bool allowSubtree)
c480ed
+{
c480ed
+    int ret = -1;
c480ed
+
c480ed
+    if (qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT) &&
c480ed
+        virSecurityManagerTransactionStart(driver->securityManager) < 0)
c480ed
+        goto cleanup;
c480ed
+
c480ed
+    if (virSecurityManagerDomainSetPathLabel(driver->securityManager,
c480ed
+                                             vm->def,
c480ed
+                                             path,
c480ed
+                                             allowSubtree) < 0)
c480ed
+        goto cleanup;
c480ed
+
c480ed
+    if (qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT) &&
c480ed
+        virSecurityManagerTransactionCommit(driver->securityManager,
c480ed
+                                            vm->pid) < 0)
c480ed
+        goto cleanup;
c480ed
+
c480ed
+    ret = 0;
c480ed
+ cleanup:
c480ed
+    virSecurityManagerTransactionAbort(driver->securityManager);
c480ed
+    return ret;
c480ed
+}
c480ed
diff --git a/src/qemu/qemu_security.h b/src/qemu/qemu_security.h
c480ed
index a189b63828..fd11fbdd9d 100644
c480ed
--- a/src/qemu/qemu_security.h
c480ed
+++ b/src/qemu/qemu_security.h
c480ed
@@ -95,12 +95,16 @@ int qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver,
c480ed
 void qemuSecurityCleanupTPMEmulator(virQEMUDriverPtr driver,
c480ed
                                     virDomainDefPtr def);
c480ed
 
c480ed
+int qemuSecurityDomainSetPathLabel(virQEMUDriverPtr driver,
c480ed
+                                   virDomainObjPtr vm,
c480ed
+                                   const char *path,
c480ed
+                                   bool allowSubtree);
c480ed
+
c480ed
 /* Please note that for these APIs there is no wrapper yet. Do NOT blindly add
c480ed
  * new APIs here. If an API can touch a /dev file add a proper wrapper instead.
c480ed
  */
c480ed
 # define qemuSecurityCheckAllLabel virSecurityManagerCheckAllLabel
c480ed
 # define qemuSecurityClearSocketLabel virSecurityManagerClearSocketLabel
c480ed
-# define qemuSecurityDomainSetPathLabel virSecurityManagerDomainSetPathLabel
c480ed
 # define qemuSecurityGenLabel virSecurityManagerGenLabel
c480ed
 # define qemuSecurityGetBaseLabel virSecurityManagerGetBaseLabel
c480ed
 # define qemuSecurityGetDOI virSecurityManagerGetDOI
c480ed
-- 
c480ed
2.22.0
c480ed