Blame SOURCES/admin-Use-fsuid-to-ensure-correct-file-ownership.patch

f07a28
From d7d362995aa0cb8905c8d5c2a2a4c305d2ffff80 Mon Sep 17 00:00:00 2001
f07a28
From: Ondrej Holy <oholy@redhat.com>
f07a28
Date: Thu, 23 May 2019 10:33:30 +0200
f07a28
Subject: [PATCH] admin: Use fsuid to ensure correct file ownership
f07a28
f07a28
Files created over admin backend should be owned by root, but they are
f07a28
owned by the user itself. This is because the daemon drops the uid to
f07a28
make dbus connection work. Use fsuid and euid to fix this issue.
f07a28
f07a28
Closes: https://gitlab.gnome.org/GNOME/gvfs/issues/21
f07a28
---
f07a28
 daemon/gvfsbackendadmin.c | 29 +++++++----------------------
f07a28
 1 file changed, 7 insertions(+), 22 deletions(-)
f07a28
f07a28
diff --git a/daemon/gvfsbackendadmin.c b/daemon/gvfsbackendadmin.c
f07a28
index a74d09cf..32b51b1a 100644
f07a28
--- a/daemon/gvfsbackendadmin.c
f07a28
+++ b/daemon/gvfsbackendadmin.c
f07a28
@@ -157,19 +157,6 @@ complete_job (GVfsJob *job,
f07a28
   g_vfs_job_succeeded (job);
f07a28
 }
f07a28
 
f07a28
-static void
f07a28
-fix_file_info (GFileInfo *info)
f07a28
-{
f07a28
-  /* Override read/write flags, since the above call will use access()
f07a28
-   * to determine permissions, which does not honor our privileged
f07a28
-   * capabilities.
f07a28
-   */
f07a28
-  g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, TRUE);
f07a28
-  g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, TRUE);
f07a28
-  g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, TRUE);
f07a28
-  g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME, TRUE);
f07a28
-}
f07a28
-
f07a28
 static void
f07a28
 do_query_info (GVfsBackend *backend,
f07a28
                GVfsJobQueryInfo *query_info_job,
f07a28
@@ -195,7 +182,6 @@ do_query_info (GVfsBackend *backend,
f07a28
   if (error != NULL)
f07a28
     goto out;
f07a28
 
f07a28
-  fix_file_info (real_info);
f07a28
   g_file_info_copy_into (real_info, info);
f07a28
   g_object_unref (real_info);
f07a28
 
f07a28
@@ -220,7 +206,6 @@ do_query_info_on_read (GVfsBackend *backend,
f07a28
   if (error != NULL)
f07a28
     goto out;
f07a28
 
f07a28
-  fix_file_info (real_info);
f07a28
   g_file_info_copy_into (real_info, info);
f07a28
   g_object_unref (real_info);
f07a28
 
f07a28
@@ -245,7 +230,6 @@ do_query_info_on_write (GVfsBackend *backend,
f07a28
   if (error != NULL)
f07a28
     goto out;
f07a28
 
f07a28
-  fix_file_info (real_info);
f07a28
   g_file_info_copy_into (real_info, info);
f07a28
   g_object_unref (real_info);
f07a28
 
f07a28
@@ -977,14 +961,15 @@ acquire_caps (uid_t uid)
f07a28
   struct __user_cap_header_struct hdr;
f07a28
   struct __user_cap_data_struct data;
f07a28
 
f07a28
-  /* Tell kernel not clear capabilities when dropping root */
f07a28
-  if (prctl (PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0)
f07a28
-    g_error ("prctl(PR_SET_KEEPCAPS) failed");
f07a28
-
f07a28
-  /* Drop root uid, but retain the required permitted caps */
f07a28
-  if (setuid (uid) < 0)
f07a28
+  /* Set euid to user to make dbus work */
f07a28
+  if (seteuid (uid) < 0)
f07a28
     g_error ("unable to drop privs");
f07a28
 
f07a28
+  /* Set fsuid to still behave like root when working with files */
f07a28
+  setfsuid (0);
f07a28
+  if (setfsuid (-1) != 0)
f07a28
+   g_error ("setfsuid failed");
f07a28
+
f07a28
   memset (&hdr, 0, sizeof(hdr));
f07a28
   hdr.version = _LINUX_CAPABILITY_VERSION;
f07a28
 
f07a28
-- 
f07a28
2.23.0
f07a28