mountpoint-util: add new fstype_can_umask() helper

This commit is contained in:
Lennart Poettering
2023-03-09 21:56:42 +01:00
parent 034ebc47a2
commit 6eda6f7e51
4 changed files with 22 additions and 1 deletions
+13
View 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,
+1
View 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);
+3 -1
View 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;
+5
View 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. */