From patchwork Tue Jun 25 10:36:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hallsmark, Per" X-Patchwork-Id: 1121963 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=windriver.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45Y2dJ2GS4z9s8m for ; Tue, 25 Jun 2019 20:36:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729137AbfFYKgP (ORCPT ); Tue, 25 Jun 2019 06:36:15 -0400 Received: from mail1.windriver.com ([147.11.146.13]:58842 "EHLO mail1.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728377AbfFYKgO (ORCPT ); Tue, 25 Jun 2019 06:36:14 -0400 Received: from ALA-HCB.corp.ad.wrs.com ([147.11.189.41]) by mail1.windriver.com (8.15.2/8.15.1) with ESMTPS id x5PAa8bA026036 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Tue, 25 Jun 2019 03:36:08 -0700 (PDT) Received: from ALA-MBD.corp.ad.wrs.com ([169.254.3.194]) by ALA-HCB.corp.ad.wrs.com ([147.11.189.41]) with mapi id 14.03.0439.000; Tue, 25 Jun 2019 03:36:07 -0700 From: "Hallsmark, Per" To: Alexey Dobriyan , "David S. Miller" CC: "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "Hallsmark, Per" Subject: [PATCH] let proc net directory inodes reflect to active net namespace Thread-Topic: [PATCH] let proc net directory inodes reflect to active net namespace Thread-Index: AQHVK0C2SQYwxDnNd0ORdMMwE+Y4tg== Date: Tue, 25 Jun 2019 10:36:06 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: x-originating-ip: [128.224.18.181] MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hi, Linux kernel recently got a bugfix 1fde6f21d90f ("proc: fix /proc/net/* after setns(2)"), but unfortunately it only solves the issue for procfs net file inodes so they get correct content after a process change namespace. Checking on a v5.2-rc6 kernel : sh-4.4# sh netns_procfs_test.sh [ 16.451640] ip (108) used greatest stack depth: 12264 bytes left Before net namespace change : ==== /proc/net/dev ==== Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packd eth0: 0 0 0 0 0 0 0 0 0 0 lo: 0 0 0 0 0 0 0 0 0 0 if_default: 0 0 0 0 0 0 0 0 0 0 sit0: 0 0 0 0 0 0 0 0 0 0 ==== files in /proc/net/dev_snmp6 ==== . .. lo eth0 sit0 if_default After net namespace change : ==== /proc/net/dev ==== Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packd sit0: 0 0 0 0 0 0 0 0 0 0 if_other: 0 0 0 0 0 0 0 0 0 0 lo: 0 0 0 0 0 0 0 0 0 0 ==== files in /proc/net/dev_snmp6 ==== . .. lo eth0 sit0 if_default This kernel is fixed for file inode bug but suffers dir inode bug sh-4.4# As can be seen above, after the namespace change we see new content in procfs net/dev but the listing of procfs net/dev_snmp6 still shows entries from previous namespace. We need to apply similar bugfix for directory creation in procfs net as the mentioned commit do for files. Checking on a v5.2-rc6 kernel with bugfixes : sh-4.4# sh netns_procfs_test.sh [ 745.993882] ip (108) used greatest stack depth: 12264 bytes left Before net namespace change : ==== /proc/net/dev ==== Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packd lo: 0 0 0 0 0 0 0 0 0 0 sit0: 0 0 0 0 0 0 0 0 0 0 eth0: 0 0 0 0 0 0 0 0 0 0 if_default: 0 0 0 0 0 0 0 0 0 0 ==== files in /proc/net/dev_snmp6 ==== . .. lo eth0 sit0 if_default After net namespace change : ==== /proc/net/dev ==== Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packd if_other: 0 0 0 0 0 0 0 0 0 0 sit0: 0 0 0 0 0 0 0 0 0 0 lo: 0 0 0 0 0 0 0 0 0 0 ==== files in /proc/net/dev_snmp6 ==== . .. lo sit0 if_other This kernel is fixed for both file and dir inode bug sh-4.4# Here we see that the directory procfs net/dev_snmp6 is updated according to the namespace change. The fix is two commits, first updates proc_net_mkdir() entries similar to mentioned patch and second one is changing net/ipv6/proc.c to use proc_net_mkdir() instead. Speaking about proc_net_mkdir()... [phallsma@arn-phallsma-l3 linux]$ git grep proc_mkdir | grep proc_net drivers/isdn/divert/divert_procfs.c: isdn_proc_entry = proc_mkdir("isdn", init_net.proc_net); drivers/isdn/hysdn/hysdn_procconf.c: hysdn_proc_entry = proc_mkdir(PROC_SUBDIR_NAME, init_net.proc_net); drivers/net/bonding/bond_procfs.c: bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net); drivers/net/wireless/intel/ipw2x00/libipw_module.c: libipw_proc = proc_mkdir(DRV_PROCNAME, init_net.proc_net); drivers/net/wireless/intersil/hostap/hostap_main.c: hostap_proc = proc_mkdir("hostap", init_net.proc_net); drivers/staging/rtl8192u/ieee80211/ieee80211_module.c: ieee80211_proc = proc_mkdir(DRV_NAME, init_net.proc_net); drivers/staging/rtl8192u/r8192U_core.c: rtl8192_proc = proc_mkdir(RTL819XU_MODULE_NAME, init_net.proc_net); net/appletalk/atalk_proc.c: if (!proc_mkdir("atalk", init_net.proc_net)) net/core/pktgen.c: pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net); net/ipv4/netfilter/ipt_CLUSTERIP.c: cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net); net/ipv6/proc.c: net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net); net/llc/llc_proc.c: llc_proc_dir = proc_mkdir("llc", init_net.proc_net); net/netfilter/xt_hashlimit.c: hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net); net/netfilter/xt_hashlimit.c: hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net); net/netfilter/xt_recent.c: recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net); net/sunrpc/cache.c: cd->procfs = proc_mkdir(cd->name, sn->proc_net_rpc); net/sunrpc/stats.c: sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net); net/x25/x25_proc.c: if (!proc_mkdir("x25", init_net.proc_net)) [phallsma@arn-phallsma-l3 linux]$ IMHO all code should use proc_net_mkdir() instead of proc_mkdir() for procfs net entries, or am I missing something here? If not possible to changeover to proc_net_mkdir() there is a need for duplicating my first commit at those places. I'm fixing the one for dev_snmp6() which is what I've tested as well. Also wonder if it all is optimal. Wouldn't it be better to re-enable dcache for these (files as well as directories) and in addition have kernel drop dcache in case of a namespace change? Attaching patches and app/script for verifying. I'm not on the mailing lists so please keep me on CC in case of responding. Best regards, Per --- Per Hallsmark per.hallsmark@windriver.com Senior Member Technical Staff Wind River AB Mobile: +46733249340 Office: +46859461127 Torshamnsgatan 27 164 40 Kista From 6925a5408ffce37dc71871c2ee05db96e60cae0d Mon Sep 17 00:00:00 2001 From: Per Hallsmark Date: Thu, 20 Jun 2019 10:21:31 +0200 Subject: [PATCH 2/2] net: Directories created in /proc/net should be done via proc_net_mkdir() Directories created in /proc/net should be done via proc_net_mkdir() Signed-off-by: Per Hallsmark --- net/ipv6/proc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c index 4a8da679866e..3728c57e93dc 100644 --- a/net/ipv6/proc.c +++ b/net/ipv6/proc.c @@ -282,7 +282,8 @@ static int __net_init ipv6_proc_init_net(struct net *net) snmp6_seq_show, NULL)) goto proc_snmp6_fail; - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net); + net->mib.proc_net_devsnmp6 = proc_net_mkdir(net, + "dev_snmp6", net->proc_net); if (!net->mib.proc_net_devsnmp6) goto proc_dev_snmp6_fail; return 0; -- 2.20.1