From e844ee075259162c6b2585cd4b026865077a4015 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 12 Apr 2025 15:22:05 +0200 Subject: [PATCH] fstab-generator: honor x-systemd.validatefs from kernel cmdline too --- src/fstab-generator/fstab-generator.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 3b3bc9db670..6f802898816 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -1167,7 +1167,7 @@ static bool validate_root_or_usr_mount_source(const char *what, const char *swit static int add_sysroot_mount(void) { _cleanup_free_ char *what = NULL; const char *extra_opts = NULL, *fstype = NULL; - bool default_rw = true, makefs = false; + bool default_rw = true; MountPointFlags flags; if (!validate_root_or_usr_mount_source(arg_root_what, "root=")) @@ -1218,8 +1218,9 @@ static int add_sysroot_mount(void) { log_debug("Found entry what=%s where=/sysroot type=%s opts=%s", what, strna(arg_root_fstype), strempty(combined_options)); - makefs = fstab_test_option(combined_options, "x-systemd.makefs\0"); - flags = makefs * MOUNT_MAKEFS; + /* Only honor x-systemd.makefs and .validatefs here, others are not relevant in initrd/not used + * at all (also see mandatory_mount_drop_unapplicable_options()) */ + flags = fstab_options_to_flags(combined_options, /* is_swap = */ false) & (MOUNT_MAKEFS|MOUNT_VALIDATEFS); return add_mount("/proc/cmdline", arg_dest, @@ -1237,8 +1238,7 @@ static int add_sysroot_mount(void) { static int add_sysroot_usr_mount(void) { _cleanup_free_ char *what = NULL; const char *extra_opts = NULL; - MountPointFlags flags; - bool makefs; + bool makefs, validatefs; int r; /* Returns 0 if we didn't do anything, > 0 if we either generated a unit for the /usr/ mount, or we @@ -1308,8 +1308,10 @@ static int add_sysroot_usr_mount(void) { log_debug("Found entry what=%s where=/sysusr/usr type=%s opts=%s", what, strna(arg_usr_fstype), strempty(combined_options)); + /* Only honor x-systemd.makefs and .validatefs here, others are not relevant in initrd/not used + * at all (also see mandatory_mount_drop_unapplicable_options()) */ makefs = fstab_test_option(combined_options, "x-systemd.makefs\0"); - flags = makefs * MOUNT_MAKEFS; + validatefs = fstab_test_option(combined_options, "x-systemd.validatefs\0"); r = add_mount("/proc/cmdline", arg_dest, @@ -1319,13 +1321,13 @@ static int add_sysroot_usr_mount(void) { arg_usr_fstype, combined_options, /* passno= */ is_device_path(what) ? 1 : 0, - flags, + makefs ? MOUNT_MAKEFS : 0, SPECIAL_INITRD_USR_FS_TARGET, "imports.target"); if (r < 0) return r; - r = add_sysusr_sysroot_usr_bind_mount("/proc/cmdline", /* validatefs = */ false); + r = add_sysusr_sysroot_usr_bind_mount("/proc/cmdline", validatefs); if (r < 0) return r; -- 2.47.3