All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] do_mounts: always prefer tmpfs for rootfs when available
@ 2021-07-02 23:44 Alexander Lobakin
  2021-08-04 21:14 ` Alexander Lobakin
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Lobakin @ 2021-07-02 23:44 UTC (permalink / raw)
  To: Alexander Viro
  Cc: Kees Cook, Sami Tolvanen, Miguel Ojeda, Johan Hovold,
	Bjorn Helgaas, Masahiro Yamada, Joe Perches, Alexander Lobakin,
	John Wood, Jens Axboe, Jan Kara, Hannes Reinecke, Tejun Heo,
	Greg Kroah-Hartman, Andrew Morton, linux-fsdevel, linux-kernel

Inspired by the situation from [0].

The roots of choosing tmpfs/ramfs backend for rootfs go far back
in history, and it's unclear at all why it was decided to select
full-blown tmpfs when "root=" is not specified and feature-poor
ramfs otherwise.
There are several cases when "root=" is not needed at all to work,
and it doesn't break anything or make any [negative] sense. On the
other hand, such separation is rather counter-intuitive and makes
debugging more difficult.
Simply always use tmpfs when it's available -- just like devtmpfs
does [for over a decade].

[0] https://lore.kernel.org/kernel-hardening/20210701234807.50453-1-alobakin@pm.me/

Signed-off-by: Alexander Lobakin <alobakin@pm.me>
---
 fs/namespace.c       |  2 --
 include/linux/init.h |  1 -
 init/do_mounts.c     | 26 +++++++-------------------
 3 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index ab4174a3c802..310ab44fdbe7 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -17,7 +17,6 @@
 #include <linux/security.h>
 #include <linux/cred.h>
 #include <linux/idr.h>
-#include <linux/init.h>		/* init_rootfs */
 #include <linux/fs_struct.h>	/* get_fs_root et.al. */
 #include <linux/fsnotify.h>	/* fsnotify_vfsmount_delete */
 #include <linux/file.h>
@@ -4248,7 +4247,6 @@ void __init mnt_init(void)
 	if (!fs_kobj)
 		printk(KERN_WARNING "%s: kobj create error\n", __func__);
 	shmem_init();
-	init_rootfs();
 	init_mount_tree();
 }

diff --git a/include/linux/init.h b/include/linux/init.h
index d82b4b2e1d25..10839922a1d3 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -148,7 +148,6 @@ extern unsigned int reset_devices;
 /* used by init/main.c */
 void setup_arch(char **);
 void prepare_namespace(void);
-void __init init_rootfs(void);
 extern struct file_system_type rootfs_fs_type;

 #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 74aede860de7..c00b05015a66 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -611,24 +611,12 @@ void __init prepare_namespace(void)
 	init_chroot(".");
 }

-static bool is_tmpfs;
-static int rootfs_init_fs_context(struct fs_context *fc)
-{
-	if (IS_ENABLED(CONFIG_TMPFS) && is_tmpfs)
-		return shmem_init_fs_context(fc);
-
-	return ramfs_init_fs_context(fc);
-}
-
 struct file_system_type rootfs_fs_type = {
-	.name		= "rootfs",
-	.init_fs_context = rootfs_init_fs_context,
-	.kill_sb	= kill_litter_super,
+	.name			= "rootfs",
+#ifdef CONFIG_TMPFS
+	.init_fs_context	= shmem_init_fs_context,
+#else
+	.init_fs_context	= ramfs_init_fs_context,
+#endif
+	.kill_sb		= kill_litter_super,
 };
-
-void __init init_rootfs(void)
-{
-	if (IS_ENABLED(CONFIG_TMPFS) && !saved_root_name[0] &&
-		(!root_fs_names || strstr(root_fs_names, "tmpfs")))
-		is_tmpfs = true;
-}
--
2.32.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] do_mounts: always prefer tmpfs for rootfs when available
  2021-07-02 23:44 [PATCH] do_mounts: always prefer tmpfs for rootfs when available Alexander Lobakin
@ 2021-08-04 21:14 ` Alexander Lobakin
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Lobakin @ 2021-08-04 21:14 UTC (permalink / raw)
  To: Alexander Viro
  Cc: Alexander Lobakin, Kees Cook, Sami Tolvanen, Miguel Ojeda,
	Johan Hovold, Bjorn Helgaas, Masahiro Yamada, Joe Perches,
	John Wood, Jens Axboe, Jan Kara, Hannes Reinecke, Tejun Heo,
	Greg Kroah-Hartman, Andrew Morton, linux-fsdevel, linux-kernel

From: Alexander Lobakin <alobakin@pm.me>
Date: Fri, 02 Jul 2021 23:44:35 +0000

> Inspired by the situation from [0].
>
> The roots of choosing tmpfs/ramfs backend for rootfs go far back
> in history, and it's unclear at all why it was decided to select
> full-blown tmpfs when "root=" is not specified and feature-poor
> ramfs otherwise.
> There are several cases when "root=" is not needed at all to work,
> and it doesn't break anything or make any [negative] sense. On the
> other hand, such separation is rather counter-intuitive and makes
> debugging more difficult.
> Simply always use tmpfs when it's available -- just like devtmpfs
> does [for over a decade].
>
> [0] https://lore.kernel.org/kernel-hardening/20210701234807.50453-1-alobakin@pm.me/
>
> Signed-off-by: Alexander Lobakin <alobakin@pm.me>

Ping?

> ---
>  fs/namespace.c       |  2 --
>  include/linux/init.h |  1 -
>  init/do_mounts.c     | 26 +++++++-------------------
>  3 files changed, 7 insertions(+), 22 deletions(-)
>
> diff --git a/fs/namespace.c b/fs/namespace.c
> index ab4174a3c802..310ab44fdbe7 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -17,7 +17,6 @@
>  #include <linux/security.h>
>  #include <linux/cred.h>
>  #include <linux/idr.h>
> -#include <linux/init.h>		/* init_rootfs */
>  #include <linux/fs_struct.h>	/* get_fs_root et.al. */
>  #include <linux/fsnotify.h>	/* fsnotify_vfsmount_delete */
>  #include <linux/file.h>
> @@ -4248,7 +4247,6 @@ void __init mnt_init(void)
>  	if (!fs_kobj)
>  		printk(KERN_WARNING "%s: kobj create error\n", __func__);
>  	shmem_init();
> -	init_rootfs();
>  	init_mount_tree();
>  }
>
> diff --git a/include/linux/init.h b/include/linux/init.h
> index d82b4b2e1d25..10839922a1d3 100644
> --- a/include/linux/init.h
> +++ b/include/linux/init.h
> @@ -148,7 +148,6 @@ extern unsigned int reset_devices;
>  /* used by init/main.c */
>  void setup_arch(char **);
>  void prepare_namespace(void);
> -void __init init_rootfs(void);
>  extern struct file_system_type rootfs_fs_type;
>
>  #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
> diff --git a/init/do_mounts.c b/init/do_mounts.c
> index 74aede860de7..c00b05015a66 100644
> --- a/init/do_mounts.c
> +++ b/init/do_mounts.c
> @@ -611,24 +611,12 @@ void __init prepare_namespace(void)
>  	init_chroot(".");
>  }
>
> -static bool is_tmpfs;
> -static int rootfs_init_fs_context(struct fs_context *fc)
> -{
> -	if (IS_ENABLED(CONFIG_TMPFS) && is_tmpfs)
> -		return shmem_init_fs_context(fc);
> -
> -	return ramfs_init_fs_context(fc);
> -}
> -
>  struct file_system_type rootfs_fs_type = {
> -	.name		= "rootfs",
> -	.init_fs_context = rootfs_init_fs_context,
> -	.kill_sb	= kill_litter_super,
> +	.name			= "rootfs",
> +#ifdef CONFIG_TMPFS
> +	.init_fs_context	= shmem_init_fs_context,
> +#else
> +	.init_fs_context	= ramfs_init_fs_context,
> +#endif
> +	.kill_sb		= kill_litter_super,
>  };
> -
> -void __init init_rootfs(void)
> -{
> -	if (IS_ENABLED(CONFIG_TMPFS) && !saved_root_name[0] &&
> -		(!root_fs_names || strstr(root_fs_names, "tmpfs")))
> -		is_tmpfs = true;
> -}
> --
> 2.32.0

Thanks,
Al


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-04 21:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-02 23:44 [PATCH] do_mounts: always prefer tmpfs for rootfs when available Alexander Lobakin
2021-08-04 21:14 ` Alexander Lobakin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.