[PATCH 2/9] mnt: expose pointer to init_mnt_ns

Christian Brauner posted 9 patches 2 weeks, 1 day ago
[PATCH 2/9] mnt: expose pointer to init_mnt_ns
Posted by Christian Brauner 2 weeks, 1 day ago
There's various scenarios where we need to know whether we are in the
initial set of namespaces or not to e.g., shortcut permission checking.
All namespaces expose that information. Let's do that too.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/namespace.c                | 2 ++
 include/linux/mnt_namespace.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/fs/namespace.c b/fs/namespace.c
index a68998449698..c8251545d57e 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -81,6 +81,7 @@ static DECLARE_RWSEM(namespace_sem);
 static HLIST_HEAD(unmounted);	/* protected by namespace_sem */
 static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */
 static struct mnt_namespace *emptied_ns; /* protected by namespace_sem */
+struct mnt_namespace *init_mnt_ns;
 
 #ifdef CONFIG_FSNOTIFY
 LIST_HEAD(notify_list); /* protected by namespace_sem */
@@ -6037,6 +6038,7 @@ static void __init init_mount_tree(void)
 	set_fs_root(current->fs, &root);
 
 	ns_tree_add(ns);
+	init_mnt_ns = ns;
 }
 
 void __init mnt_init(void)
diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
index 70b366b64816..7e23c8364a9c 100644
--- a/include/linux/mnt_namespace.h
+++ b/include/linux/mnt_namespace.h
@@ -11,6 +11,8 @@ struct fs_struct;
 struct user_namespace;
 struct ns_common;
 
+extern struct mnt_namespace *init_mnt_ns;
+
 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
 		struct user_namespace *, struct fs_struct *);
 extern void put_mnt_ns(struct mnt_namespace *ns);

-- 
2.47.3
Re: [PATCH 2/9] mnt: expose pointer to init_mnt_ns
Posted by Jan Kara 2 weeks ago
On Wed 17-09-25 12:28:01, Christian Brauner wrote:
> There's various scenarios where we need to know whether we are in the
> initial set of namespaces or not to e.g., shortcut permission checking.
> All namespaces expose that information. Let's do that too.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Right. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/namespace.c                | 2 ++
>  include/linux/mnt_namespace.h | 2 ++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/fs/namespace.c b/fs/namespace.c
> index a68998449698..c8251545d57e 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -81,6 +81,7 @@ static DECLARE_RWSEM(namespace_sem);
>  static HLIST_HEAD(unmounted);	/* protected by namespace_sem */
>  static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */
>  static struct mnt_namespace *emptied_ns; /* protected by namespace_sem */
> +struct mnt_namespace *init_mnt_ns;
>  
>  #ifdef CONFIG_FSNOTIFY
>  LIST_HEAD(notify_list); /* protected by namespace_sem */
> @@ -6037,6 +6038,7 @@ static void __init init_mount_tree(void)
>  	set_fs_root(current->fs, &root);
>  
>  	ns_tree_add(ns);
> +	init_mnt_ns = ns;
>  }
>  
>  void __init mnt_init(void)
> diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
> index 70b366b64816..7e23c8364a9c 100644
> --- a/include/linux/mnt_namespace.h
> +++ b/include/linux/mnt_namespace.h
> @@ -11,6 +11,8 @@ struct fs_struct;
>  struct user_namespace;
>  struct ns_common;
>  
> +extern struct mnt_namespace *init_mnt_ns;
> +
>  extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
>  		struct user_namespace *, struct fs_struct *);
>  extern void put_mnt_ns(struct mnt_namespace *ns);
> 
> -- 
> 2.47.3
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
Re: [PATCH 2/9] mnt: expose pointer to init_mnt_ns
Posted by Christian Brauner 1 week, 6 days ago
On Wed, Sep 17, 2025 at 06:28:37PM +0200, Jan Kara wrote:
> On Wed 17-09-25 12:28:01, Christian Brauner wrote:
> > There's various scenarios where we need to know whether we are in the
> > initial set of namespaces or not to e.g., shortcut permission checking.
> > All namespaces expose that information. Let's do that too.
> > 
> > Signed-off-by: Christian Brauner <brauner@kernel.org>

I've changed this so it behaves exactly like all the other init
namespaces. See appended.
Re: [PATCH 2/9] mnt: expose pointer to init_mnt_ns
Posted by Jan Kara 1 week, 3 days ago
On Fri 19-09-25 12:05:16, Christian Brauner wrote:
> On Wed, Sep 17, 2025 at 06:28:37PM +0200, Jan Kara wrote:
> > On Wed 17-09-25 12:28:01, Christian Brauner wrote:
> > > There's various scenarios where we need to know whether we are in the
> > > initial set of namespaces or not to e.g., shortcut permission checking.
> > > All namespaces expose that information. Let's do that too.
> > > 
> > > Signed-off-by: Christian Brauner <brauner@kernel.org>
> 
> I've changed this so it behaves exactly like all the other init
> namespaces. See appended.

Yeah, looks good to me. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

(although I can see you've kept my Reviewed-by in the patch).

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
Re: [PATCH 2/9] mnt: expose pointer to init_mnt_ns
Posted by Christian Brauner 1 week, 2 days ago
On Mon, Sep 22, 2025 at 12:19:11PM +0200, Jan Kara wrote:
> On Fri 19-09-25 12:05:16, Christian Brauner wrote:
> > On Wed, Sep 17, 2025 at 06:28:37PM +0200, Jan Kara wrote:
> > > On Wed 17-09-25 12:28:01, Christian Brauner wrote:
> > > > There's various scenarios where we need to know whether we are in the
> > > > initial set of namespaces or not to e.g., shortcut permission checking.
> > > > All namespaces expose that information. Let's do that too.
> > > > 
> > > > Signed-off-by: Christian Brauner <brauner@kernel.org>
> > 
> > I've changed this so it behaves exactly like all the other init
> > namespaces. See appended.
> 
> Yeah, looks good to me. Feel free to add:
> 
> Reviewed-by: Jan Kara <jack@suse.cz>
> 
> (although I can see you've kept my Reviewed-by in the patch).

Sorry, that was an accident because I had amended the patch.
Thanks for paying attention to this!