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