d6cc78
From: Cole Robinson <crobinso@redhat.com>
d6cc78
Date: Wed, 9 Mar 2016 12:20:37 -0500
d6cc78
Subject: [PATCH] util: virfile: Only setuid for virFileRemove if on NFS
d6cc78
d6cc78
NFS with root-squash is the only reason we need to do setuid/setgid
d6cc78
crazyness in virFileRemove, so limit that behavior to the NFS case.
d6cc78
d6cc78
(cherry picked from commit adefc561cc4c6a007529769c3df286f2ed461684)
d6cc78
---
d6cc78
 src/util/virfile.c | 11 +++++++++--
d6cc78
 1 file changed, 9 insertions(+), 2 deletions(-)
d6cc78
d6cc78
diff --git a/src/util/virfile.c b/src/util/virfile.c
d6cc78
index a913903..0bba850 100644
d6cc78
--- a/src/util/virfile.c
d6cc78
+++ b/src/util/virfile.c
d6cc78
@@ -2315,6 +2315,7 @@ virFileOpenAs(const char *path, int openflags, mode_t mode,
d6cc78
 
d6cc78
 
d6cc78
 /* virFileRemoveNeedsSetuid:
d6cc78
+ * @path: file we plan to remove
d6cc78
  * @uid: file uid to check
d6cc78
  * @gid: file gid to check
d6cc78
  *
d6cc78
@@ -2322,7 +2323,7 @@ virFileOpenAs(const char *path, int openflags, mode_t mode,
d6cc78
  * owned by the passed uid/gid pair. Needed for NFS with root-squash
d6cc78
  */
d6cc78
 static bool
d6cc78
-virFileRemoveNeedsSetuid(uid_t uid, gid_t gid)
d6cc78
+virFileRemoveNeedsSetuid(const char *path, uid_t uid, gid_t gid)
d6cc78
 {
d6cc78
     /* If running unprivileged, setuid isn't going to work */
d6cc78
     if (geteuid() != 0)
d6cc78
@@ -2336,6 +2337,12 @@ virFileRemoveNeedsSetuid(uid_t uid, gid_t gid)
d6cc78
     if (uid == geteuid() && gid == getegid())
d6cc78
         return false;
d6cc78
 
d6cc78
+    /* Only perform the setuid stuff for NFS, which is the only case
d6cc78
+       that may actually need it. This can error, but just be safe and
d6cc78
+       only check for a clear negative result. */
d6cc78
+    if (virFileIsSharedFSType(path, VIR_FILE_SHFS_NFS) == 0)
d6cc78
+        return false;
d6cc78
+
d6cc78
     return true;
d6cc78
 }
d6cc78
 
d6cc78
@@ -2361,7 +2368,7 @@ virFileRemove(const char *path,
d6cc78
     gid_t *groups;
d6cc78
     int ngroups;
d6cc78
 
d6cc78
-    if (!virFileRemoveNeedsSetuid(uid, gid)) {
d6cc78
+    if (!virFileRemoveNeedsSetuid(path, uid, gid)) {
d6cc78
         if (virFileIsDir(path))
d6cc78
             return rmdir(path);
d6cc78
         else