Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2916144rwb; Thu, 29 Sep 2022 17:28:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4TvDcoZjzd8Zjf7TLXGcwrV8EeFKyIRWLk86y3Vc9+X1YFM/tf/i83FAovbfhXN7K3PlLz X-Received: by 2002:a50:fa83:0:b0:457:fd83:f60a with SMTP id w3-20020a50fa83000000b00457fd83f60amr5613967edr.111.1664497696163; Thu, 29 Sep 2022 17:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664497696; cv=none; d=google.com; s=arc-20160816; b=OsDM21MilLd09GZTZ9MXsJ7LDPq1zBLlLENicNd2/ZCqpkfF8Ckde5vnNn3kVUUgG/ Aiew7anZiuu/3VWE+GR3uZG3DCobGjVx/uqmiPE8mFO2FLhvpcZzEk5PqILmH8jsDiZO TTQ9xgEkjMokexF+zSa+TC7+b1lbnVY+8V/D7hgsL7zKd3+J02ebyAUWCQjqybOJQu6J IAesxK0JoZMOtVlLc8YdqUtNyIEVwR9rOZAKngNj38RfmRQnk4AAs9BkF2oh+D1N8ZOW DmwmnRqTlYuFErhOQ3+4zphUgR0vTVN6d+sx0g/SkivtHQ9NOnTTxXs7LF7N9LizNDPt tsrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=f7WrZuRB2GX0P+1NfkIg4YGL4fmYDCdScdWAGuAPgzc=; b=V3lTJ1TQYeqfgJOPF3tOcDL0AUnY+5/nuDA5whyU6AqEhd2at1u3pe26RFNH0FJetP 4UodkVXy+DVAnj6k9I2W/csErMnx+A5u6kLq/PEXDLy1PaSjsyaUpzpesR2BXwkzirFr zvpkYsuZ9vTLgBFjp0uLr13h5y0GVhm+RSsjFadJ7pA5gUmzP1jMMuSF0NCfmADsKRaE spexUCVJMhSybkIeojkqFLe+J0HafJ0AOXOnGivWIe0lnt8ffJQUcasQtNML54/7qAor wlCsZuotpHgjaKQGO3JL2JkgPw/TBQtl2SJLf6IdFTFeuwDluwxy4T9c4RGgsQ19BdPw gN6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="eP4G/3Sz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a170906974a00b00780b046fb73si581510ejy.728.2022.09.29.17.27.50; Thu, 29 Sep 2022 17:28:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="eP4G/3Sz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229457AbiI2XiU (ORCPT + 99 others); Thu, 29 Sep 2022 19:38:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbiI2XiR (ORCPT ); Thu, 29 Sep 2022 19:38:17 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67D0214C062; Thu, 29 Sep 2022 16:38:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=f7WrZuRB2GX0P+1NfkIg4YGL4fmYDCdScdWAGuAPgzc=; b=eP4G/3SzWgOlPrSUKmlI9aNrCR 4rACRsmYEJ6uMECWrySSKj8fMonyU0DVvv70pYZIYb0JlLsCpPQSER+gHFMJQzJD0meT4GGrUFG4c IshwHvMxaie7wdpK7pDPnR724hijO8//B6KYNx+xUO6IX8zorTfSI7SnAZ6AcHKEafgAfBNaXGAcH XvXsp1vBNgD1Bl9mqzUfljEFgpr9wSAyCz6WsupjgupJI9DBiDSmneAkwqUXTq4MgXc+oBFb8Sydu Aa3M7KqRQWPZmgxu+Sivk6+zWQR6BjDt1MU/1PIVbmd8laLiRHL5WVwvVVYMcBbQFrOnZOMIiTzqV HGsZvZhw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1oe36W-005937-0h; Thu, 29 Sep 2022 23:38:08 +0000 Date: Fri, 30 Sep 2022 00:38:08 +0100 From: Al Viro To: "Eric W. Biederman" Cc: Linus Torvalds , David Laight , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "Serge E. Hallyn" Subject: Re: [CFT][PATCH] proc: Update /proc/net to point at the accessing threads network namespace Message-ID: References: <871qrt4ymg.fsf@email.froward.int.ebiederm.org> <87ill53igy.fsf_-_@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87ill53igy.fsf_-_@email.froward.int.ebiederm.org> Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 29, 2022 at 05:48:29PM -0500, Eric W. Biederman wrote: > +static const char *proc_net_symlink_get_link(struct dentry *dentry, > + struct inode *inode, > + struct delayed_call *done) > +{ > + struct pid_namespace *ns = proc_pid_ns(inode->i_sb); > + pid_t tid = task_pid_nr_ns(current, ns); > + char *name; > + > + if (!tid) > + return ERR_PTR(-ENOENT); > + name = kmalloc(10 + 4 + 1, dentry ? GFP_KERNEL : GFP_ATOMIC); > + if (unlikely(!name)) > + return dentry ? ERR_PTR(-ENOMEM) : ERR_PTR(-ECHILD); > + sprintf(name, "%u/net", tid); > + set_delayed_call(done, kfree_link, name); > + return name; > +} Just to troll adobriyan a bit: static const char *dynamic_get_link(struct delayed_call *done, bool is_rcu, const char *fmt, ...) { va_list args; char *body; va_start(args, fmt); body = kvasprintf(is_rcu ? GFP_ATOMIC : GFP_KERNEL, fmt, args); va_end(args); if (unlikely(!body)) return is_rcu ? ERR_PTR(-ECHILD) : ERR_PTR(-ENOMEM); set_delayed_call(done, kfree_link, body); return body; } static const char *proc_net_symlink_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done) { struct pid_namespace *ns = proc_pid_ns(inode->i_sb); pid_t tid = task_pid_nr_ns(current, ns); if (!tid) return ERR_PTR(-ENOENT); return dyname_get_link(done, !dentry, "%u/net", tid); } static const char *proc_self_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done) { struct pid_namespace *ns = proc_pid_ns(inode->i_sb); pid_t tgid = task_tgid_nr_ns(current, ns); if (!tgid) return ERR_PTR(-ENOENT); return dynamic_get_link(done, !dentry, "%u", tgid); } static const char *proc_thread_self_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done) { struct pid_namespace *ns = proc_pid_ns(inode->i_sb); pid_t tgid = task_tgid_nr_ns(current, ns); pid_t pid = task_pid_nr_ns(current, ns); if (!pid) return ERR_PTR(-ENOENT); return dynamic_get_link(done, !dentry, "%u/task/%u", tgid, pid); }