* [PATCH] userns: allow privileged user to operate locked mount
@ 2013-11-13 7:27 Gao feng
[not found] ` <1384327663-12032-1-git-send-email-gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Gao feng @ 2013-11-13 7:27 UTC (permalink / raw)
To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Cc: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
ebiederm-aS9lmoZGLiVWk0Htik3J/w
Privileged user should have rights to mount/umount/move
these even locked mount.
Signed-off-by: Gao feng <gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
---
fs/namespace.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index da5c494..7097fc7 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1297,6 +1297,11 @@ static inline bool may_mount(void)
return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
}
+static inline bool may_mount_lock(struct mount *mnt)
+{
+ return !(mnt->mnt.mnt_flags & MNT_LOCKED) || capable(CAP_SYS_ADMIN);
+}
+
/*
* Now umount can handle mount points as well as block devices.
* This is important for filesystems which use unnamed block devices.
@@ -1330,7 +1335,7 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
goto dput_and_out;
if (!check_mnt(mnt))
goto dput_and_out;
- if (mnt->mnt.mnt_flags & MNT_LOCKED)
+ if (!may_mount_lock(mnt))
goto dput_and_out;
retval = do_umount(mnt, flags);
@@ -1768,7 +1773,8 @@ static int do_loopback(struct path *path, const char *old_name,
if (!check_mnt(parent) || !check_mnt(old))
goto out2;
- if (!recurse && has_locked_children(old, old_path.dentry))
+ if (!recurse && has_locked_children(old, old_path.dentry) &&
+ !capable(CAP_SYS_ADMIN))
goto out2;
if (recurse)
@@ -1895,7 +1901,7 @@ static int do_move_mount(struct path *path, const char *old_name)
if (!check_mnt(p) || !check_mnt(old))
goto out1;
- if (old->mnt.mnt_flags & MNT_LOCKED)
+ if (!may_mount_lock(old))
goto out1;
err = -EINVAL;
@@ -2679,7 +2685,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
goto out4;
if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
goto out4;
- if (new_mnt->mnt.mnt_flags & MNT_LOCKED)
+ if (!may_mount_lock(new_mnt))
goto out4;
error = -ENOENT;
if (d_unlinked(new.dentry))
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] userns: allow privileged user to operate locked mount
[not found] ` <1384327663-12032-1-git-send-email-gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
@ 2013-11-14 23:50 ` Eric W. Biederman
[not found] ` <874n7e4k78.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Eric W. Biederman @ 2013-11-14 23:50 UTC (permalink / raw)
To: Gao feng
Cc: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
Gao feng <gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> writes:
> Privileged user should have rights to mount/umount/move
> these even locked mount.
Hmm. This is pretty much a can't happen case, as the only exist in mount
namespaces where the global root isn't the root. How are you getting
into this situation? Using setns() ?
Why would we even care?
As implemented this patch does not handle nested user namespaces and
that really worries me at a semantic level.
We don't want to design cases where we can create containers in
containers.
Eric
> Signed-off-by: Gao feng <gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
> ---
> fs/namespace.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/fs/namespace.c b/fs/namespace.c
> index da5c494..7097fc7 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -1297,6 +1297,11 @@ static inline bool may_mount(void)
> return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
> }
>
> +static inline bool may_mount_lock(struct mount *mnt)
> +{
> + return !(mnt->mnt.mnt_flags & MNT_LOCKED) || capable(CAP_SYS_ADMIN);
> +}
> +
> /*
> * Now umount can handle mount points as well as block devices.
> * This is important for filesystems which use unnamed block devices.
> @@ -1330,7 +1335,7 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
> goto dput_and_out;
> if (!check_mnt(mnt))
> goto dput_and_out;
> - if (mnt->mnt.mnt_flags & MNT_LOCKED)
> + if (!may_mount_lock(mnt))
> goto dput_and_out;
>
> retval = do_umount(mnt, flags);
> @@ -1768,7 +1773,8 @@ static int do_loopback(struct path *path, const char *old_name,
> if (!check_mnt(parent) || !check_mnt(old))
> goto out2;
>
> - if (!recurse && has_locked_children(old, old_path.dentry))
> + if (!recurse && has_locked_children(old, old_path.dentry) &&
> + !capable(CAP_SYS_ADMIN))
> goto out2;
>
> if (recurse)
> @@ -1895,7 +1901,7 @@ static int do_move_mount(struct path *path, const char *old_name)
> if (!check_mnt(p) || !check_mnt(old))
> goto out1;
>
> - if (old->mnt.mnt_flags & MNT_LOCKED)
> + if (!may_mount_lock(old))
> goto out1;
>
> err = -EINVAL;
> @@ -2679,7 +2685,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
> goto out4;
> if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
> goto out4;
> - if (new_mnt->mnt.mnt_flags & MNT_LOCKED)
> + if (!may_mount_lock(new_mnt))
> goto out4;
> error = -ENOENT;
> if (d_unlinked(new.dentry))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] userns: allow privileged user to operate locked mount
[not found] ` <874n7e4k78.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
@ 2013-11-15 0:47 ` Gao feng
[not found] ` <52856F0D.8090206-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Gao feng @ 2013-11-15 0:47 UTC (permalink / raw)
To: Eric W. Biederman
Cc: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On 11/15/2013 07:50 AM, Eric W. Biederman wrote:
> Gao feng <gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> writes:
>
>> Privileged user should have rights to mount/umount/move
>> these even locked mount.
>
> Hmm. This is pretty much a can't happen case, as the only exist in mount
> namespaces where the global root isn't the root. How are you getting
> into this situation? Using setns() ?
>
Before, priviged user can use setns to set his mount namespace to the
container's mount namespace, and change container's mount directly.
this patch just gives back host the control of container.
> Why would we even care?
>
> As implemented this patch does not handle nested user namespaces and
> that really worries me at a semantic level.
>
> We don't want to design cases where we can create containers in
> containers.
>
> Eric
>
>
>> Signed-off-by: Gao feng <gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
>> ---
>> fs/namespace.c | 14 ++++++++++----
>> 1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/namespace.c b/fs/namespace.c
>> index da5c494..7097fc7 100644
>> --- a/fs/namespace.c
>> +++ b/fs/namespace.c
>> @@ -1297,6 +1297,11 @@ static inline bool may_mount(void)
>> return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
>> }
>>
>> +static inline bool may_mount_lock(struct mount *mnt)
>> +{
>> + return !(mnt->mnt.mnt_flags & MNT_LOCKED) || capable(CAP_SYS_ADMIN);
>> +}
>> +
>> /*
>> * Now umount can handle mount points as well as block devices.
>> * This is important for filesystems which use unnamed block devices.
>> @@ -1330,7 +1335,7 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
>> goto dput_and_out;
>> if (!check_mnt(mnt))
>> goto dput_and_out;
>> - if (mnt->mnt.mnt_flags & MNT_LOCKED)
>> + if (!may_mount_lock(mnt))
>> goto dput_and_out;
>>
>> retval = do_umount(mnt, flags);
>> @@ -1768,7 +1773,8 @@ static int do_loopback(struct path *path, const char *old_name,
>> if (!check_mnt(parent) || !check_mnt(old))
>> goto out2;
>>
>> - if (!recurse && has_locked_children(old, old_path.dentry))
>> + if (!recurse && has_locked_children(old, old_path.dentry) &&
>> + !capable(CAP_SYS_ADMIN))
>> goto out2;
>>
>> if (recurse)
>> @@ -1895,7 +1901,7 @@ static int do_move_mount(struct path *path, const char *old_name)
>> if (!check_mnt(p) || !check_mnt(old))
>> goto out1;
>>
>> - if (old->mnt.mnt_flags & MNT_LOCKED)
>> + if (!may_mount_lock(old))
>> goto out1;
>>
>> err = -EINVAL;
>> @@ -2679,7 +2685,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
>> goto out4;
>> if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
>> goto out4;
>> - if (new_mnt->mnt.mnt_flags & MNT_LOCKED)
>> + if (!may_mount_lock(new_mnt))
>> goto out4;
>> error = -ENOENT;
>> if (d_unlinked(new.dentry))
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] userns: allow privileged user to operate locked mount
[not found] ` <52856F0D.8090206-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
@ 2013-11-15 1:38 ` Eric W. Biederman
0 siblings, 0 replies; 4+ messages in thread
From: Eric W. Biederman @ 2013-11-15 1:38 UTC (permalink / raw)
To: Gao feng
Cc: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
Gao feng <gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> writes:
> On 11/15/2013 07:50 AM, Eric W. Biederman wrote:
>> Gao feng <gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org> writes:
>>
>>> Privileged user should have rights to mount/umount/move
>>> these even locked mount.
>>
>> Hmm. This is pretty much a can't happen case, as the only exist in mount
>> namespaces where the global root isn't the root. How are you getting
>> into this situation? Using setns() ?
>>
>
> Before, priviged user can use setns to set his mount namespace to the
> container's mount namespace, and change container's mount directly.
> this patch just gives back host the control of container.
Having thought about this patch a little more I really don't like it.
There are other ways for a privileged user to get around the limitations
when the mount namespace is being created or the mounts are being
propagated.
This approach would require more then a signgle bit of accounting to
work in the nested user namespace case.
The lock says one or several mounts are mounted as a unit and need to
stay that way.
If there are real advantages to splitting things up I might be persuaded
to change my mind. But right now it looks like you are introducing
extra complexity for a very corner edge case that we don't want to
encourage people to use.
Eric
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-11-15 1:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-13 7:27 [PATCH] userns: allow privileged user to operate locked mount Gao feng
[not found] ` <1384327663-12032-1-git-send-email-gaofeng-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2013-11-14 23:50 ` Eric W. Biederman
[not found] ` <874n7e4k78.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-11-15 0:47 ` Gao feng
[not found] ` <52856F0D.8090206-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2013-11-15 1:38 ` Eric W. Biederman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).