]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: add new fstype_can_umask() helper
authorLennart Poettering <lennart@poettering.net>
Tue, 7 Mar 2023 10:29:38 +0000 (11:29 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 9 Mar 2023 20:56:42 +0000 (21:56 +0100)
src/basic/mountpoint-util.c
src/basic/mountpoint-util.h
src/shared/dissect-image.c
src/test/test-mountpoint-util.c

index 27d20f5fe3e2ee13daef70e9a782baed43b7b816..2cb319ba649a675ec520b6183e4fc24ea114e87b 100644 (file)
@@ -495,6 +495,19 @@ bool fstype_can_norecovery(const char *fstype) {
                           "btrfs");
 }
 
+bool fstype_can_umask(const char *fstype) {
+        int r;
+
+        assert(fstype);
+
+        /* On new kernels we can just ask the kernel */
+        r = mount_option_supported(fstype, "umask", "0077");
+        if (r >= 0)
+                return r;
+
+        return streq(fstype, "vfat");
+}
+
 bool fstype_can_uid_gid(const char *fstype) {
 
         /* All file systems that have a uid=/gid= mount option that fixates the owners of all files and directories,
index e0c8f6b3564f2fdbd48254ed5003377174d461cf..977e8e738dd7766c8f37a2d2289b8c4862ce29b9 100644 (file)
@@ -50,6 +50,7 @@ bool fstype_is_ro(const char *fsype);
 bool fstype_can_discard(const char *fstype);
 bool fstype_can_uid_gid(const char *fstype);
 bool fstype_can_norecovery(const char *fstype);
+bool fstype_can_umask(const char *fstype);
 
 int dev_is_devtmpfs(void);
 
index 59adb324266e5a471fa9cd5f353de9a9c3ad1694..2502e3a0eb3f37a06c0dcb28b0b599a2c727be63 100644 (file)
@@ -1537,7 +1537,9 @@ int partition_pick_mount_options(
         case PARTITION_XBOOTLDR:
                 flags |= MS_NOSUID|MS_NOEXEC|ms_nosymfollow_supported();
 
-                if (!fstype || streq(fstype, "vfat"))
+                /* The ESP might contain a pre-boot random seed. Let's make this unaccessible to regular
+                 * userspace. ESP/XBOOTLDR is almost certainly VFAT, hence if we don't know assume it is. */
+                if (!fstype || fstype_can_umask(fstype))
                         if (!strextend_with_separator(&options, ",", "umask=0077"))
                                 return -ENOMEM;
                 break;
index d6aa2c7b94964398490c2fadc08a8999f8bba261..f5481b5d6bfcfe080e6d4ba25ea5c9dc89542ec5 100644 (file)
@@ -361,6 +361,11 @@ TEST(fstype_can_norecovery) {
         assert_se(!fstype_can_norecovery("tmpfs"));
 }
 
+TEST(fstype_can_umask) {
+        assert_se(fstype_can_umask("vfat"));
+        assert_se(!fstype_can_umask("tmpfs"));
+}
+
 static int intro(void) {
         /* let's move into our own mount namespace with all propagation from the host turned off, so
          * that /proc/self/mountinfo is static and constant for the whole time our test runs. */