render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
51d9a2
From 427a75470c813205af2ea6bd81daacb0281ef58a Mon Sep 17 00:00:00 2001
51d9a2
Message-Id: <427a75470c813205af2ea6bd81daacb0281ef58a@dist-git>
51d9a2
From: Michal Privoznik <mprivozn@redhat.com>
51d9a2
Date: Wed, 25 Jul 2018 08:27:10 +0200
51d9a2
Subject: [PATCH] qemuDomainSaveMemory: Don't enforce dynamicOwnership
51d9a2
MIME-Version: 1.0
51d9a2
Content-Type: text/plain; charset=UTF-8
51d9a2
Content-Transfer-Encoding: 8bit
51d9a2
51d9a2
https://bugzilla.redhat.com/show_bug.cgi?id=1589115
51d9a2
51d9a2
When doing a memory snapshot qemuOpenFile() is used. This means
51d9a2
that the file where memory is saved is firstly attempted to be
51d9a2
created under root:root (because that's what libvirtd is running
51d9a2
under) and if this fails the second attempt is done under
51d9a2
domain's uid:gid. This does not make much sense - qemu is given
51d9a2
opened FD so it does not need to access the file. Moreover, if
51d9a2
dynamicOwnership is set in qemu.conf and the file lives on a
51d9a2
squashed NFS this is deadly combination and very likely to fail.
51d9a2
51d9a2
The fix consists of using:
51d9a2
51d9a2
  qemuOpenFileAs(fallback_uid = cfg->user,
51d9a2
                 fallback_gid = cfg->group,
51d9a2
                 dynamicOwnership = false)
51d9a2
51d9a2
In other words, dynamicOwnership is turned off for memory
51d9a2
snapshot (chown() will still be attempted if the file does not
51d9a2
live on NFS) and instead of using domain DAC label, configured
51d9a2
user:group is set as fallback.
51d9a2
51d9a2
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
51d9a2
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
51d9a2
(cherry picked from commit 8c8c32339ae965fa6991462e98be1f5890ac7499)
51d9a2
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
51d9a2
Reviewed-by: Ján Tomko <jtomko@redhat.com>
51d9a2
---
51d9a2
 src/qemu/qemu_driver.c | 15 +++++++++------
51d9a2
 1 file changed, 9 insertions(+), 6 deletions(-)
51d9a2
51d9a2
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
51d9a2
index efd0a05c90..c7689cc239 100644
51d9a2
--- a/src/qemu/qemu_driver.c
51d9a2
+++ b/src/qemu/qemu_driver.c
51d9a2
@@ -3185,6 +3185,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver,
51d9a2
                      unsigned int flags,
51d9a2
                      qemuDomainAsyncJob asyncJob)
51d9a2
 {
51d9a2
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
51d9a2
     bool needUnlink = false;
51d9a2
     int ret = -1;
51d9a2
     int fd = -1;
51d9a2
@@ -3202,9 +3203,10 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver,
51d9a2
             goto cleanup;
51d9a2
         }
51d9a2
     }
51d9a2
-    fd = qemuOpenFile(driver, vm, path,
51d9a2
-                      O_WRONLY | O_TRUNC | O_CREAT | directFlag,
51d9a2
-                      &needUnlink);
51d9a2
+
51d9a2
+    fd = qemuOpenFileAs(cfg->user, cfg->group, false, path,
51d9a2
+                        O_WRONLY | O_TRUNC | O_CREAT | directFlag,
51d9a2
+                        &needUnlink);
51d9a2
     if (fd < 0)
51d9a2
         goto cleanup;
51d9a2
 
51d9a2
@@ -3244,6 +3246,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver,
51d9a2
  cleanup:
51d9a2
     VIR_FORCE_CLOSE(fd);
51d9a2
     virFileWrapperFdFree(wrapperFd);
51d9a2
+    virObjectUnref(cfg);
51d9a2
 
51d9a2
     if (ret < 0 && needUnlink)
51d9a2
         unlink(path);
51d9a2
@@ -3793,9 +3796,9 @@ doCoreDump(virQEMUDriverPtr driver,
51d9a2
     /* Core dumps usually imply last-ditch analysis efforts are
51d9a2
      * desired, so we intentionally do not unlink even if a file was
51d9a2
      * created.  */
51d9a2
-    if ((fd = qemuOpenFile(driver, vm, path,
51d9a2
-                           O_CREAT | O_TRUNC | O_WRONLY | directFlag,
51d9a2
-                           NULL)) < 0)
51d9a2
+    if ((fd = qemuOpenFileAs(cfg->user, cfg->group, false, path,
51d9a2
+                             O_CREAT | O_TRUNC | O_WRONLY | directFlag,
51d9a2
+                             NULL)) < 0)
51d9a2
         goto cleanup;
51d9a2
 
51d9a2
     if (!(wrapperFd = virFileWrapperFdNew(&fd, path, flags)))
51d9a2
-- 
51d9a2
2.18.0
51d9a2