All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <christian.brauner@ubuntu.com>
To: Lorenz Bauer <lmb@cloudflare.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	kernel-team@cloudflare.com, linux-api@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 2/4] nsfs: add an ioctl to discover the network namespace cookie
Date: Mon, 1 Mar 2021 11:04:20 +0100	[thread overview]
Message-ID: <20210301100420.slnjvzql6el4jlfj@wittgenstein> (raw)
In-Reply-To: <20210210120425.53438-3-lmb@cloudflare.com>

On Wed, Feb 10, 2021 at 12:04:23PM +0000, Lorenz Bauer wrote:
> Network namespaces have a globally unique non-zero identifier aka a
> cookie, in line with socket cookies. Add an ioctl to retrieve the
> cookie from user space without going via BPF.
> 
> Cc: linux-api@vger.kernel.org
> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
> ---
>  fs/nsfs.c                   |  9 +++++++++
>  include/net/net_namespace.h | 11 +++++++++++
>  include/uapi/linux/nsfs.h   |  2 ++
>  3 files changed, 22 insertions(+)
> 
> diff --git a/fs/nsfs.c b/fs/nsfs.c
> index 800c1d0eb0d0..d7865e39c049 100644
> --- a/fs/nsfs.c
> +++ b/fs/nsfs.c
> @@ -11,6 +11,7 @@
>  #include <linux/user_namespace.h>
>  #include <linux/nsfs.h>
>  #include <linux/uaccess.h>
> +#include <net/net_namespace.h>
>  
>  #include "internal.h"
>  
> @@ -191,6 +192,8 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
>  	struct user_namespace *user_ns;
>  	struct ns_common *ns = get_proc_ns(file_inode(filp));
>  	uid_t __user *argp;
> +	struct net *net_ns;
> +	u64 cookie;
>  	uid_t uid;
>  
>  	switch (ioctl) {
> @@ -209,6 +212,12 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
>  		argp = (uid_t __user *) arg;
>  		uid = from_kuid_munged(current_user_ns(), user_ns->owner);
>  		return put_user(uid, argp);
> +	case NS_GET_COOKIE:
> +		if (ns->ops->type != CLONE_NEWNET)
> +			return -EINVAL;
> +		net_ns = container_of(ns, struct net, ns);
> +		cookie = net_gen_cookie(net_ns);
> +		return put_user(cookie, (u64 __user *)arg);

Hey Lorenz,

Just to make sure: is it intentional that any user can retrieve the
cookie associated with any network namespace, i.e. you don't require any
form of permission checking in the owning user namespace of the network
namespace?

Christian

  parent reply	other threads:[~2021-03-01 10:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10 12:04 [PATCH bpf 0/4] Expose network namespace cookies to user space Lorenz Bauer
2021-02-10 12:04 ` [PATCH bpf 1/4] net: add SO_NETNS_COOKIE socket option Lorenz Bauer
2021-02-10 12:04   ` Lorenz Bauer
2021-02-10 14:51   ` Eric Dumazet
2021-02-10 14:51     ` Eric Dumazet
2021-02-10 12:04 ` [PATCH bpf 2/4] nsfs: add an ioctl to discover the network namespace cookie Lorenz Bauer
2021-02-10 15:07   ` kernel test robot
2021-02-10 15:07     ` kernel test robot
2021-02-10 15:26   ` kernel test robot
2021-02-10 15:26     ` kernel test robot
2021-03-01 10:04   ` Christian Brauner [this message]
2021-03-02  9:47     ` Lorenz Bauer
2021-03-02 10:14       ` Christian Brauner
2021-02-10 12:04 ` [PATCH bpf 3/4] tools/testing: add test for NS_GET_COOKIE Lorenz Bauer
2021-02-10 12:04 ` [PATCH bpf 4/4] tools/testing: add a selftest for SO_NETNS_COOKIE Lorenz Bauer

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=20210301100420.slnjvzql6el4jlfj@wittgenstein \
    --to=christian.brauner@ubuntu.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=kernel-team@cloudflare.com \
    --cc=kuba@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lmb@cloudflare.com \
    --cc=netdev@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.