[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87sh1cqqfs.fsf@xmission.com>
Date: Thu, 11 Oct 2018 13:38:31 -0500
From: ebiederm@...ssion.com (Eric W. Biederman)
To: David Howells <dhowells@...hat.com>
Cc: Alan Jenkins <alan.christopher.jenkins@...il.com>,
viro@...iv.linux.org.uk, torvalds@...ux-foundation.org,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
mszeredi@...hat.com
Subject: Re: [PATCH 03/34] teach move_mount(2) to work with OPEN_TREE_CLONE [ver #12]
David Howells <dhowells@...hat.com> writes:
> Okay, this appears to fix the cycle-creation problem.
>
> It could probably be improved by comparing sequence numbers as Alan suggests,
> but I need to work out how to get at that.
It should just be a matter of replacing the test
"if (p->mnt.mnt_sb->s_type == &nsfs)" with "if mnt_ns_loop(p->mnt.mnt_root)"
That would allow reusing 100% of the existing logic, and remove the need
to export file_system_type nsfs;
As your test exists below it will reject a lot more than mount namespace
file descriptors. It will reject file descriptors for every other
namespace as well.
Eric
> ---
> commit 069c3376f7849044117c866aeafbb1a525f84926
> Author: David Howells <dhowells@...hat.com>
> Date: Thu Oct 4 23:18:59 2018 +0100
>
> fixes
>
> diff --git a/fs/internal.h b/fs/internal.h
> index 17029b30e196..47a6c80c3c51 100644
> --- a/fs/internal.h
> +++ b/fs/internal.h
> @@ -172,6 +172,7 @@ extern void mnt_pin_kill(struct mount *m);
> * fs/nsfs.c
> */
> extern const struct dentry_operations ns_dentry_operations;
> +extern struct file_system_type nsfs;
>
> /*
> * fs/ioctl.c
> diff --git a/fs/namespace.c b/fs/namespace.c
> index e969ded7d54b..25ecd8b3c76b 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -2388,6 +2388,27 @@ static inline int tree_contains_unbindable(struct mount *mnt)
> return 0;
> }
>
> +/*
> + * Object if there are any nsfs mounts in the specified subtree. These can act
> + * as pins for mount namespaces that aren't checked by the mount-cycle checking
> + * code, thereby allowing cycles to be made.
> + */
> +static bool check_for_nsfs_mounts(struct mount *subtree)
> +{
> + struct mount *p;
> + bool ret = false;
> +
> + lock_mount_hash();
> + for (p = subtree; p; p = next_mnt(p, subtree))
> + if (p->mnt.mnt_sb->s_type == &nsfs)
> + goto out;
> +
> + ret = true;
> +out:
> + unlock_mount_hash();
> + return ret;
> +}
> +
> static int do_move_mount(struct path *old_path, struct path *new_path)
> {
> struct path parent_path = {.mnt = NULL, .dentry = NULL};
> @@ -2442,6 +2463,8 @@ static int do_move_mount(struct path *old_path, struct path *new_path)
> if (IS_MNT_SHARED(p) && tree_contains_unbindable(old))
> goto out1;
> err = -ELOOP;
> + if (!check_for_nsfs_mounts(old))
> + goto out1;
> for (; mnt_has_parent(p); p = p->mnt_parent)
> if (p == old)
> goto out1;
> diff --git a/fs/nsfs.c b/fs/nsfs.c
> index f069eb6495b0..d3abcd5c2a23 100644
> --- a/fs/nsfs.c
> +++ b/fs/nsfs.c
> @@ -269,7 +269,7 @@ static struct dentry *nsfs_mount(struct file_system_type *fs_type,
> return mount_pseudo(fs_type, "nsfs:", &nsfs_ops,
> &ns_dentry_operations, NSFS_MAGIC);
> }
> -static struct file_system_type nsfs = {
> +struct file_system_type nsfs = {
> .name = "nsfs",
> .mount = nsfs_mount,
> .kill_sb = kill_anon_super,
Powered by blists - more mailing lists