Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3125852pxb; Mon, 1 Mar 2021 02:10:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKpK0t5R+dFAlr3T0hr9F/9M33Wx2CsjmoDbDZBYXgXDD3Jn39YNCwuaknY5u+2XfgngkD X-Received: by 2002:a17:907:734a:: with SMTP id dq10mr14813951ejc.411.1614593435161; Mon, 01 Mar 2021 02:10:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614593435; cv=none; d=google.com; s=arc-20160816; b=bZsGx/+9r92vR3dV4HK/GJUlOthVPQPnNsQWtJHtoIYhomPssbQPNWsFGhj5qb8cMl nI1ZBf93+qD4sNuTjTZH9RnbGknSHYhSVSV4sChMJ36hbTvqkh/PlvnpqecteK9kJNHN 75IuULnlZV/6XI2o6NZJazVIO5qE2R3uEAz6GSfT7xxQ6rbHkT+tO/up4MWZH+cBT6B7 zpM1eVHylc9q/rFzgXrezOjlM2XnDunBe4JnInMR9ISHCgFYHxv21pwb77nqa0HUUEek b2h14VypUDze1NoAf8a6+Q+RUOIis5k2XwIxbMIy6YbudH54nypYAo/01jU0Ev5OU2ln b5nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=8xGpLXMyd4HRObUyHs5UcYn3zMQx9qQjoXWmdDMOaes=; b=Bd5BtrHf5Zrm5MHFVA3ZbE4Y0i1e9+Of/cNV6miGTkmO7MxecU3s+7bkb6NA2Z1klA rTus2TzLA5cLLTfs992zF2Shszri4JolT4lokNqaSW385PFZMASgH7vDd3LenEmq61f+ 87Cyck65VNjdUMJNnzmd8+pgVZcClxkFKaSiP4XDs6DknegbhMPHuwcdEB38g0J/tbGY ZXW1Gk5mtTiDhIVIQv6GjcGbpYu7vd8ZkoPeMw1fHF8+zFRihnWvUIj6T/rVzkjxJZ5i dFs68y4qr61v1RjoE8144Xe/nqHixT0PHG4eqQFbutoBfsEktlRDqx3QfBLBDSFHLo4s otdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx17si10297164edb.495.2021.03.01.02.10.12; Mon, 01 Mar 2021 02:10:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232002AbhCAKHW (ORCPT + 99 others); Mon, 1 Mar 2021 05:07:22 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:36907 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbhCAKGK (ORCPT ); Mon, 1 Mar 2021 05:06:10 -0500 Received: from ip5f5af0a0.dynamic.kabel-deutschland.de ([95.90.240.160] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lGfPZ-0003lu-Cu; Mon, 01 Mar 2021 10:04:21 +0000 Date: Mon, 1 Mar 2021 11:04:20 +0100 From: Christian Brauner To: Lorenz Bauer Cc: Alexander Viro , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , 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 Message-ID: <20210301100420.slnjvzql6el4jlfj@wittgenstein> References: <20210210120425.53438-1-lmb@cloudflare.com> <20210210120425.53438-3-lmb@cloudflare.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210210120425.53438-3-lmb@cloudflare.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 > #include > #include > +#include > > #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