From: Serge Hallyn <serge.hallyn@ubuntu.com>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Linux Containers <containers@lists.linux-foundation.org>,
util-linux@vger.kernel.org
Subject: Re: bind mounting namespace inodes for unprivileged users
Date: Tue, 3 May 2016 21:22:02 +0000 [thread overview]
Message-ID: <20160503212202.GA32233@ubuntumail> (raw)
In-Reply-To: <1462299656.16133.51.camel@HansenPartnership.com>
Quoting James Bottomley (James.Bottomley@HansenPartnership.com):
> Right at the moment, unprivileged users cannot call mount --bind to
> create a permanent copy of any of their namespaces. This is annoying
> because it means that for entry to long running containers you have to
> spawn an undying process and use nsenter via the /proc/<pid>/ns files.
>
> The first question is: assuming we restrict it to bind mounting only
> nsfs inodes, is there any reason an unprivileged user shouldn't be able
> to bind a namespace they've created to a file they own in the initial
> mount namespace?
>
> Assuming the answer to this is no, then how to implement it becomes the
> next problem. Right at the moment, util-linux/mount will deny a non
> -root user the ability to use --bind. This check could be relaxed and,
> since mount is setuid root, it could be modified to force the binding
> as root meaning this could be implemented entirely within the util
> -linux package.
>
> Doing this from within the kernel sys_mount is much more problematic:
> no root users are forbidden from calling any type of mount by the
> may_mount() check, which makes sure you only have root capability in
> the user_ns attached to the current mnt_ns. Overriding that simply to
> allow nsfs binding looks like a recipe for introducing unexpected
> security problems.
>
> So, does anyone have any strong (or even weak) opinions about this
> before I start coding patches?
Hi,
so this is a bit scatterbrained, but it points to what I think is
a workable way to do this all unprivileged (well, besides the
privilege conferred by newuidmap/newgidmap). Assume you are
uid 1000 and have a /etc/sub{u,g}id entry joe:100000:65536.
Start by creating one container (namespace, whatever you want to
call it) which has uid 1000 mapped to container root, and all subuids
mapped into the container so that container root is privileged over
them. This container/namespace creates a private mntns which is
where you'll be keeping the persistent nsfs bind mounts. Let's
call this the 'factotum' for the duration of this email.
Now say you create a container with 100000 as container root and you
want to persist its user and network namespaces. The init task (which
you don't want to keep around) is pid 999. Uid 1000 cannot see under
/proc/999/ns, but a task in your factotum can. So it can open
/proc/999/ns/net and /proc/999/ns/user and bind mount them. Any time a
task (pid 1999) owned by 1000 on the host wants to use such an inode,
the factotum can open it, and task 1999 can open /proc/$(pidof
factotum)/fd/N, or the factotum could simply pass the open fds over a
unix socket. Any task spawned by uid 1000 should then be able to setns
using those fds.
This is something which could be done by transparently by 'unshare'
and 'nsenter'.
-serge
next prev parent reply other threads:[~2016-05-03 21:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-03 18:20 bind mounting namespace inodes for unprivileged users James Bottomley
2016-05-03 21:22 ` Serge Hallyn [this message]
2016-05-04 11:15 ` James Bottomley
2016-05-04 8:44 ` Karel Zak
2016-05-04 13:16 ` James Bottomley
2016-05-04 14:38 ` Eric W. Biederman
2016-05-04 17:28 ` James Bottomley
2016-05-04 17:43 ` Eric W. Biederman
2016-05-04 18:00 ` James Bottomley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160503212202.GA32233@ubuntumail \
--to=serge.hallyn@ubuntu.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=containers@lists.linux-foundation.org \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox