From: "Serge E. Hallyn" <serge-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org>
To: "chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org"
<chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
Cc: Greg Kroah-Hartman
<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
"containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org"
<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
"Serge Hallyn
(serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org)"
<serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>,
"Eric W. Biederman
(ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org)"
<ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>,
"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: Could not mount sysfs when enable userns but disable netns
Date: Fri, 11 Jul 2014 16:28:06 +0200 [thread overview]
Message-ID: <20140711142806.GA26441@mail.hallyn.com> (raw)
In-Reply-To: <5871495633F38949900D2BF2DC04883E562293-ZEd+hNNJ6a5ZYpXjqAkB5jz3u5zwRJJDAzI0kPv9QBlmR6Xm/wNWPw@public.gmane.org>
Quoting chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org (chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org):
> Hello,
>
> How to reproduce:
> 1. Prepare a container, enable userns and disable netns
> 2. use libvirt-lxc to start a container
> 3. libvirt could not mount sysfs then failed to start.
>
> Then I found that
> commit 7dc5dbc879bd0779924b5132a48b731a0bc04a1e says:
> "Don't allow mounting sysfs unless the caller has CAP_SYS_ADMIN rights
> over the net namespace."
>
> But why should we check sysfs mouont permission over net namespace?
> We've already checked CAP_SYS_ADMIN though.
>
> What the relationship between sysfs and net namespace,
> or this check is a little redundant?
It is not redundant. The whole point is that after clone(CLONE_NEWUSER)
you get a newly filled set of capabilities. But you should not have
privileges over the host's network namesapce. After you unshare a new
network namespace, you *should* have privilege over it. So the fact
that we've already check CAP_SYS_ADMIN means nothing, because the
capabilities need to be targeted.
> Any insights on this?
>
> Thanks,
> - Chen
>
> PS: codes below could be a workaround
>
> @@ -34,7 +35,8 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type,
> if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type))
> return ERR_PTR(-EPERM);
>
> - if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
> + if (current->nsproxy->net_ns != &init_net &&
> + !kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
> return ERR_PTR(-EPERM);
> }
> _______________________________________________
> Containers mailing list
> Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> https://lists.linuxfoundation.org/mailman/listinfo/containers
next prev parent reply other threads:[~2014-07-11 14:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-11 7:27 Could not mount sysfs when enable userns but disable netns chenhanxiao-BthXqXjhjHXQFUHtdCDX3A
[not found] ` <5871495633F38949900D2BF2DC04883E562293-ZEd+hNNJ6a5ZYpXjqAkB5jz3u5zwRJJDAzI0kPv9QBlmR6Xm/wNWPw@public.gmane.org>
2014-07-11 14:28 ` Serge E. Hallyn [this message]
[not found] ` <20140711142806.GA26441-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2014-07-11 16:29 ` Eric W. Biederman
[not found] ` <87ha2nyi3y.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2014-07-14 9:32 ` chenhanxiao-BthXqXjhjHXQFUHtdCDX3A
[not found] ` <5871495633F38949900D2BF2DC04883E5632BD-ZEd+hNNJ6a5ZYpXjqAkB5jz3u5zwRJJDAzI0kPv9QBlmR6Xm/wNWPw@public.gmane.org>
2014-07-14 17:23 ` Eric W. Biederman
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=20140711142806.GA26441@mail.hallyn.com \
--to=serge-a9i7lubdfnhqt0dzr+alfa@public.gmane.org \
--cc=chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.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