0004-admin-Use-fsuid-to-ensure-correct-file-ownership.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. From 3895e09d784ebec0fbc4614d5c37068736120e1d Mon Sep 17 00:00:00 2001
  2. From: Ondrej Holy <oholy@redhat.com>
  3. Date: Thu, 23 May 2019 10:33:30 +0200
  4. Subject: [PATCH] admin: Use fsuid to ensure correct file ownership
  5. Files created over admin backend should be owned by root, but they are
  6. owned by the user itself. This is because the daemon drops the uid to
  7. make dbus connection work. Use fsuid and euid to fix this issue.
  8. Closes: https://gitlab.gnome.org/GNOME/gvfs/issues/21
  9. [Retrieved from:
  10. https://gitlab.gnome.org/GNOME/gvfs/commit/3895e09d784ebec0fbc4614d5c37068736120e1d]
  11. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  12. ---
  13. daemon/gvfsbackendadmin.c | 29 +++++++----------------------
  14. 1 file changed, 7 insertions(+), 22 deletions(-)
  15. diff --git a/daemon/gvfsbackendadmin.c b/daemon/gvfsbackendadmin.c
  16. index a74d09cf..32b51b1a 100644
  17. --- a/daemon/gvfsbackendadmin.c
  18. +++ b/daemon/gvfsbackendadmin.c
  19. @@ -157,19 +157,6 @@ complete_job (GVfsJob *job,
  20. g_vfs_job_succeeded (job);
  21. }
  22. -static void
  23. -fix_file_info (GFileInfo *info)
  24. -{
  25. - /* Override read/write flags, since the above call will use access()
  26. - * to determine permissions, which does not honor our privileged
  27. - * capabilities.
  28. - */
  29. - g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, TRUE);
  30. - g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, TRUE);
  31. - g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, TRUE);
  32. - g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME, TRUE);
  33. -}
  34. -
  35. static void
  36. do_query_info (GVfsBackend *backend,
  37. GVfsJobQueryInfo *query_info_job,
  38. @@ -195,7 +182,6 @@ do_query_info (GVfsBackend *backend,
  39. if (error != NULL)
  40. goto out;
  41. - fix_file_info (real_info);
  42. g_file_info_copy_into (real_info, info);
  43. g_object_unref (real_info);
  44. @@ -220,7 +206,6 @@ do_query_info_on_read (GVfsBackend *backend,
  45. if (error != NULL)
  46. goto out;
  47. - fix_file_info (real_info);
  48. g_file_info_copy_into (real_info, info);
  49. g_object_unref (real_info);
  50. @@ -245,7 +230,6 @@ do_query_info_on_write (GVfsBackend *backend,
  51. if (error != NULL)
  52. goto out;
  53. - fix_file_info (real_info);
  54. g_file_info_copy_into (real_info, info);
  55. g_object_unref (real_info);
  56. @@ -977,14 +961,15 @@ acquire_caps (uid_t uid)
  57. struct __user_cap_header_struct hdr;
  58. struct __user_cap_data_struct data;
  59. - /* Tell kernel not clear capabilities when dropping root */
  60. - if (prctl (PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0)
  61. - g_error ("prctl(PR_SET_KEEPCAPS) failed");
  62. -
  63. - /* Drop root uid, but retain the required permitted caps */
  64. - if (setuid (uid) < 0)
  65. + /* Set euid to user to make dbus work */
  66. + if (seteuid (uid) < 0)
  67. g_error ("unable to drop privs");
  68. + /* Set fsuid to still behave like root when working with files */
  69. + setfsuid (0);
  70. + if (setfsuid (-1) != 0)
  71. + g_error ("setfsuid failed");
  72. +
  73. memset (&hdr, 0, sizeof(hdr));
  74. hdr.version = _LINUX_CAPABILITY_VERSION;
  75. --
  76. 2.24.1