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

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