Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2877415pxj; Sun, 6 Jun 2021 17:49:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt6OTUAmwMo2tn+Ono5ilclSaBam5vN0Oxo62VSzsItvOFMqyLIJ0GP0ZDrOukZffkbahx X-Received: by 2002:aa7:cfd4:: with SMTP id r20mr17652368edy.237.1623026969590; Sun, 06 Jun 2021 17:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623026969; cv=none; d=google.com; s=arc-20160816; b=i2oCi9R23tVNlQf2Bxr9FCS4LUaccY3HoCuG/pLcI1cg4KmuwolWoGbZ9wGZampPK0 WeXDqutdAKDDwpxKY69R1hlx+fdbeI26r/e8DBlOf8cfyiY3Qh8jQUBFHufnqAZQu9hk 8qCGozaBCr70PDwkBd4HodFnHy8Xv/0nuKHYD0wh4GF4fHDmkT3MIXiD7L37s1dge4Lo 3fHqXn8ahBpIC5dQ6Ln8Zi+nTyUyGU+9Sk/Qfd5tx2ifHnjyR6v3l4z/5KSU0+PDjTAR elbKSjk3SuQ/tCkE+Y+n/9Ac1qZ3WEQFPSHq8lPVQO3wF4ICHqx5sYIecpTEZlP5H7UY /9Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BhyIEJR3nChTbrHZqmUAy7TeMp1NR81AY1C+mI8Wo5w=; b=UN5/v+Pjygu83+sk/NIwpNGK7pyylXkSr9XIyjsM0YGYJLcY4ImmbU6rxUVg74xVa4 3+TiWyGeY2KYhom2JZcH7bx+CrGOK9xggb00Eyx48j5Usjcq0VuKCbfP6jlPZQvomBfW 2jRvvtZ8SLPWr6Cqi70kw8DBhsQ+PIPSpb4uLIV6xhX4wJ/PkpJvH1eD8di3oK+n1K83 HXf71iscxj3u/i1Ixe7s2s6q8VV1ZWEg9eOW5NC2d8O5Oy/8gjxOw1g+FdgRRqGlCVB0 Ya1VZhc8q6yxzYJKb5LlzyT4WUV7tQz/0fb+KvakGIPTjALS6jvS9YbHUW/I8W79WgGe sfbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CWYiO1KP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id da5si10935825edb.393.2021.06.06.17.48.51; Sun, 06 Jun 2021 17:49:29 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CWYiO1KP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230099AbhFGAk4 (ORCPT + 99 others); Sun, 6 Jun 2021 20:40:56 -0400 Received: from mail-pg1-f178.google.com ([209.85.215.178]:33653 "EHLO mail-pg1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbhFGAkz (ORCPT ); Sun, 6 Jun 2021 20:40:55 -0400 Received: by mail-pg1-f178.google.com with SMTP id e20so593954pgg.0; Sun, 06 Jun 2021 17:38:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BhyIEJR3nChTbrHZqmUAy7TeMp1NR81AY1C+mI8Wo5w=; b=CWYiO1KP83T0IsRKn1QMS3LzHYuzKeraoS+zY+9stRMeqTU/QawI/cXPX1GsYiaNwM ErNvLOOIG5GbvdDV5e/V3fpHpp/tWIAfbeFb1g5wWAue492QId7XvxdUXKa6GE6Tdh/x 20Xyn9yAOB+rTnqGf9uvrxjwhAquFLuIPtCF/FNSx1aVgV5a5zF9CyZC10xbGTeFjyJr 6XXl51cVBaxYirDF4wY0whtEZf3XSLpyAG+iPRpmpdk5hrPH43bDlByAse3ofRX05GCr Gt4whNUx3OnUIw2Cgyi4XITOMLI9ayVVgnnbrl7ciVqzgZ1roUYtOJmUsuCDEo8r0nOF UMTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BhyIEJR3nChTbrHZqmUAy7TeMp1NR81AY1C+mI8Wo5w=; b=bnskK6KR2BfguykN1IAlK6VGdpT511wdqpwrmmeo/Qja006gaIb/EWZvX3baxOqk9s kfacGIFFRmFNoAyutSwYHEBpUvDhEQY63cfdkbDDIVQ3hNab0FxSi0UcKTvdc+fKa5OF PLuIw6uYby/+/Xt6MyLJwrw076tmRa8RG2sLNDx+SdOK5hjKg6n5WYhenAWc3vlyq5z2 IlIRqnff4mzdaT7O0ArshZq6gA2oKdarj/b3coXnHpVy4FdrkZvOVb+kUjBCOgXjsd5y R0ltCBcIRUzDbzj5P+6oQk5gPBZO+DfsS/ZFKBCwYu07Nf4ZbXX8ry0tZQvKvj0v8ICs 7tUQ== X-Gm-Message-State: AOAM531ujpkje3I0JhATOUKB6XOS6PyhDVswA83GgPzGP0yLY/Wl15bE /TvKVlfCNjrOMFu8Ixnz4+bYGIiVfj+LQhTOEclfywHrgGChtw== X-Received: by 2002:a62:31c7:0:b029:2e9:2c05:52d3 with SMTP id x190-20020a6231c70000b02902e92c0552d3mr14607993pfx.78.1623026271508; Sun, 06 Jun 2021 17:37:51 -0700 (PDT) MIME-Version: 1.0 References: <20210531153410.93150-1-changbin.du@gmail.com> <20210531220128.26c0cb36@kicinski-fedora-PC1C0HJN.hsd1.ca.comcast.net> <20210602091451.kbdul6nhobilwqvi@wittgenstein> <20210604095451.nkfgpsibm5nrqt3f@wittgenstein> In-Reply-To: <20210604095451.nkfgpsibm5nrqt3f@wittgenstein> From: Cong Wang Date: Sun, 6 Jun 2021 17:37:40 -0700 Message-ID: Subject: Re: [PATCH] nsfs: fix oops when ns->ops is not provided To: Christian Brauner Cc: Jakub Kicinski , Changbin Du , Alexander Viro , "David S. Miller" , Linux Kernel Network Developers , LKML , linux-fsdevel , stable , David Laight Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 4, 2021 at 2:54 AM Christian Brauner wrote: > > On Thu, Jun 03, 2021 at 03:52:29PM -0700, Cong Wang wrote: > > On Wed, Jun 2, 2021 at 2:14 AM Christian Brauner > > wrote: > > > But the point is that ns->ops should never be accessed when that > > > namespace type is disabled. Or in other words, the bug is that something > > > in netns makes use of namespace features when they are disabled. If we > > > handle ->ops being NULL we might be tapering over a real bug somewhere. > > > > It is merely a protocol between fs/nsfs.c and other namespace users, > > so there is certainly no right or wrong here, the only question is which > > one is better. > > > > > > > > Jakub's proposal in the other mail makes sense and falls in line with > > > how the rest of the netns getters are implemented. For example > > > get_net_ns_fd_fd(): > > > > It does not make any sense to me. get_net_ns() merely increases > > the netns refcount, which is certainly fine for init_net too, no matter > > CONFIG_NET_NS is enabled or disabled. Returning EOPNOTSUPP > > there is literally saying we do not support increasing init_net refcount, > > which is of course false. > > > > > struct net *get_net_ns_by_fd(int fd) > > > { > > > return ERR_PTR(-EINVAL); > > > } > > > > There is a huge difference between just increasing netns refcount > > and retrieving it by fd, right? I have no idea why you bring this up, > > calling them getters is missing their difference. > > This argument doesn't hold up. All netns helpers ultimately increase the > reference count of the net namespace they find. And if any of them > perform operations where they are called in environments wherey they > need CONFIG_NET_NS they handle this case at compile time. Let me explain it in this more straight way: what is the protocol here for indication of !CONFIG_XXX_NS? Clearly it must be ns->ops==NULL, because all namespaces use the following similar pattern: #ifdef CONFIG_NET_NS net->ns.ops = &netns_operations; #endif Now you are arguing the protocol is not this, but it is the getter of open_related_ns() returns an error pointer. > > (Pluse they are defined in a central place in net/net_namespace.{c,h}. > That includes the low-level get_net() function and all the others. > get_net_ns() is the only one that's defined out of band. So get_net_ns() > currently is arguably also misplaced.) Of course they do, only struct ns_common is generic. What's your point? Each ns.ops is defined by each namespace too. > > The problem I have with fixing this in nsfs is that it gives the > impression that this is a bug in nsfs whereas it isn't and it > potentially helps tapering over other bugs. Like I keep saying, this is just a protocol, there is no right or wrong here. If the protocol is just ops==NULL, then there is nothing wrong use it. (BTW, we have a lot of places that use ops==NULL as a protocol, they work really well.) > > get_net_ns() is only called for codepaths that call into nsfs via > open_related_ns() and it's the only namespace that does this. But I am pretty sure userns does the same: 197 case NS_GET_USERNS: 198 return open_related_ns(ns, ns_get_owner); > open_related_ns() is only well defined if CONFIG_ is > set. For example, none of the procfs namespace f_ops will be set for > !CONFIG_NET_NS. So clearly the socket specific getter here is buggy as > it doesn't account for !CONFIG_NET_NS and it should be fixed. If the protocol is just ops==NULL, then the core part should just check ops==NULL. Pure and simple. I have no idea why you do not admit the fact that every namespace intentionally leaves ops as NULL when its config is disabled. > > Plus your fix leaks references to init netns without fixing get_net_ns() > too. I thought it is 100% clear that this patch is not from me? Plus, the PoC patch from me actually suggests to change open_related_ns(), not __ns_get_path(). I have no idea why you both miss it. Thanks.