🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16145

Re: [PATCH net-next 08/15] netfilter: lwtunnel: expose read-only sysctl nf_hooks_lwtunnel for non init-netns

#16145
From: netdev-bot+sashiko
Date: Sat, 14 Nov 2026 03:23
124 lines
12175 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch sets the per-netns copy of
  net.netfilter.nf_hooks_lwtunnel to mode 0444 in nf_lwtunnel_net_init()…
- [Low] The nf_hooks_lwtunnel entry in
  Documentation/networking/nf_conntrack-sysctl.rst (lines 212-217)…

--

netfilter: lwtunnel: expose read-only sysctl nf_hooks_lwtunnel for non init-netns

The commit registers the per-netns copy of the nf_hooks_lwtunnel sysctl
with mode 0444 instead of 0644 in every netns except init_net. This stops
unprivileged users from flipping the global nf_hooks_lwtunnel_enabled
static key from inside a user namespace.

> diff --git a/net/netfilter/nf_hooks_lwtunnel.c b/net/netfilter/nf_hooks_lwtunnel.c
> index 40c6fce14a63f..7e2ee8677f1fc 100644
> --- a/net/netfilter/nf_hooks_lwtunnel.c
> +++ b/net/netfilter/nf_hooks_lwtunnel.c
> @@ -68,14 +68,18 @@ static int __net_init nf_lwtunnel_net_init(struct net *net)

[ ... ]

>  	if (!net_eq(net, &init_net)) {
> -		table = kmemdup(nf_lwtunnel_sysctl_table,
> -				sizeof(nf_lwtunnel_sysctl_table),
> -				GFP_KERNEL_ACCOUNT);
> -		if (!table)
> +		dup = kmemdup(nf_lwtunnel_sysctl_table,
> +			      sizeof(nf_lwtunnel_sysctl_table),
> +			      GFP_KERNEL_ACCOUNT);
> +		if (!dup)
>  			goto err_alloc;
> +
> +		dup->mode = 0444;
> +		table = dup;

[Severity: Medium]
Should the SRv6 netfilter selftests be updated along with this change?

With 0444, nobody can write the knob from a child netns, including global
root with CAP_NET_ADMIN. net_ctl_permissions() copies only the owner bits:

net/sysctl_net.c:net_ctl_permissions() {
    ...
	if (ns_capable_noaudit(net->user_ns, CAP_NET_ADMIN)) {
		int mode = (table->mode >> 6) & 7;
		return (mode << 6) | (mode << 3) | mode;
	}
    ...
}

test_perm() in fs/proc/proc_sysctl.c does not let root override this, so
the write returns -EACCES.

Both tools/testing/selftests/net/srv6_end_dx4_netfilter_test.sh and
srv6_end_dx6_netfilter_test.sh write the knob from the rt-N netns in
setup_rt_netfilter():

	ip netns exec ${nsname} sysctl -wq net.netfilter.nf_hooks_lwtunnel=1

The scripts don't check the exit status, so the failure goes unnoticed.
nf_hooks_lwtunnel_enabled then stays off, and decapsulated SRv6 packets
never reach the NF_HOOK(NF_INET_PRE_ROUTING) calls in seg6_local.c.

router_netfilter_tests() only checks ping connectivity:

	setup_rt_netfilter 1
	setup_rt_netfilter 2

	check_and_log_hs_connectivity 1 2 100

Plain SRv6 forwarding works without the hooks, so the "netfilter enabled
in routers" tests would still pass without running the netfilter path at
all.

Userspace sees the same change: a privileged container manager that used
to enable this knob as real root from inside a pod netns will now get
EACCES and has to write it in init_net instead.

The restriction itself matches other global netfilter sysctls, such as
those in nf_conntrack_standalone.c and ipvs. The concern is only that the
dependent selftests stay as they are. As of 3e59905baa0f, both scripts
still write the sysctl from rt-N.

[Severity: Low]
This isn't a bug, but should the nf_hooks_lwtunnel entry in
Documentation/networking/nf_conntrack-sysctl.rst mention the new
restriction?

The entry currently reads:

	nf_hooks_lwtunnel - BOOLEAN
		- 0 - disabled (default)
		- not 0 - enabled

		If this option is enabled, the lightweight tunnel netfilter hooks are
		enabled. This option cannot be disabled once it is enabled.

The same document already has this note for nf_conntrack_buckets:

	This sysctl is only writeable in the initial net namespace.

A similar note here would explain the EACCES that users now get when they
write the knob from a child netns. As of 3e59905baa0f, the entry is
unchanged.

>  	}
>  
>  	hdr = register_net_sysctl_sz(net, "net/netfilter", table,

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113031251.2437074-2-pablo%40netfilter.org
Technical Details
Message-ID: <179462662676.2199510.16804675187126889146@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363072-linux-kernel-netdev=dewy.ru
References: <20261113031251.2437074-9-pablo@netfilter.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363072-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 08/15] netfilter: lwtunnel: expose read-only
 sysctl nf_hooks_lwtunnel for non init-netns
Date: Sat, 14 Nov 2026 03:23:46 +0000
Organization: Usenet Network
Message-ID: <179462662676.2199510.16804675187126889146@kernel.org>
References: <20261113031251.2437074-9-pablo@netfilter.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1500174"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:vMCfpfwjnJ3lJGLAXqei6ePWFsc= sha256:Kg8A1II+oQ5GZZQREgBcImPAa/3X//UVvJFHCZV2xgE=
	sha1:EzsBwgOepRJRdOG6tan5SvQqMR4= sha256:UylUIuocxVU2W6PwK30sO5LRgsOx0iU1wE4VJ/9GR90=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 1018E114757; Sat, 14 Nov 2026 06:25:25 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id CnhVE2dBcLO7;
	Sat, 14 Nov 2026 06:25:20 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-363072-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 4EE8211474A; Sat, 14 Nov 2026 06:25:12 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id E59F3325CB; Sat, 14 Nov 2026 03:24:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794626629;
	b=n5nMVhHiwYjzCf7y4LmzDarK9oDM1hYK0Bnga+DXg3OT52IXK6/uVQwmHHRf3gAu1h7M
	 yEV8rpmaCu1A8ln/51+72SBgDkM0zqVWmbrAbSGtBa1aD1+N9IjCaytgSKliLaiBJ8zFK
	 0h+bdc8XLAa2WxGrHmy0qCcvkVydlyIP5ETBapOO+KKzldnJSAq/fBMkZ978oYVexhaty
	 /n/pTvoKZPtqnUxzvO4XkrHuf8arofmbej3QRtCddO7R15QdHYONtOOHf7pZ1Z/JIy2QD
	 zy1SnHZ/46ON6YcJeq5xkqKM7ENkJEIHGo8qcLQj8cs4uZmT7XajOA+yQjvd3lWlGow==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794626629;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=dY5PKsK5J19Th8+Fm7xUFkkD+sSQ56nEk4CE9XaBMtk=;
	b=JelQyVi1Myqx7hdqFdv14+Q5F5Dt+gL6trWjITJMwU17ZPwdMZWzfk0PSXX4qCS2U8aG
	 dimsHVrU39YH2t45Jxik96x9Pvo8xeBIhCxnujSI5BX2mT60PzIrq6x2aVxkfYO+QXE1d
	 Z3faIjbFQ4S3qM11LcqfcbEENFnJu+KbTh7Ide+UY+vJhAjy2iQ7rThOfKj16BVq/DSEi
	 GmH842pHpx2GH537NfXIbyb4pHWa/hma8sMqnIiPKO8OVIltQEQrpP2gKTM5cv2JlIqFz
	 wgHl4SMF2X/hYKlZ4ScHav3jD2LlRtBPX6K5nNe/GCfX6MIy/yK63k/qZFNIXouoZ7g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Kuz/70jq";
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 07A9960A260F;
	Sat, 14 Nov 2026 03:23:49 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Kuz/70jq
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794626628;
	b=D/6AqFtHpkC5n3u1Mh7K9A832U3EULs238hOc/PF7mE0b60E+kJUrz79ehS3jaX5KHuM
	 CglErTvfJseK/ozDy9wDfiJ22LLgFrMGARI4jVhSR3wgZWoiNq21G7+2OdZFeDso+PFqX
	 UNLM8cqEl5hETKPDP8gYNNm3rdcnLqQtT4hW2Vzw51mKJnF6mw6rpelPtqsZDauN/JHSW
	 ROpA+dfI4ot31FUt0CfKXiYrp2w5/rXcBjriWI7AnXA6V9C/9U3OAcrKilC0dzywk802z
	 9y952+GeB7QkkbaWJ0ajzsGNV0EUA/jgGOctt+hFULB4jCbmiXjdJvtmD32hH75pX7A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794626628;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=dY5PKsK5J19Th8+Fm7xUFkkD+sSQ56nEk4CE9XaBMtk=;
	b=IDLoOWoUGcRrCA9GRl389vUdlA5rgfkcrQHqPwKpVprmnMLl8PlX/snAZnUVhEctX5Pf
	 oVzDmzb43qesxYk2MD1PqwICoFHYrIn124W7EhZKjldOn0PufdlJ1bO9t/Rrjf4/4iID5
	 9L1GijzXEc3Iog5a6Nvmn2u8WUMIk126IWKlbzlub1sxMSeVtnvDKAOlc9/EMc7LShT9p
	 pw3BnAHhpntL9Z79TR1cbE1LGC/O7RpC9HYEWobwohNgDy6fmd33acqvm51BxMMpYzxz+
	 ajLjAyfGCuqx/oKvxBJBhig/MCZu5uvFVBHlWnRw9nURezl7ruxCd6fUrSR98ujBsVw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Kuz/70jq";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26A6660A2603;
	Sat, 14 Nov 2026 03:23:47 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33DC01F000C9;
	Sat, 14 Nov 2026 03:23:47 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794626627;
	bh=dY5PKsK5J19Th8+Fm7xUFkkD+sSQ56nEk4CE9XaBMtk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Kuz/70jqck+5ctD4Heff1oMkImRe04SygmZFqp3VQzdNB0gr79UC9S3GlYUgJDt7q
	 7kQaMFOjRhrx7JVcTiySF0I3S0U4Plby/2/a5WID9Atqcf4Lrqv1eEbJNpdT5WLKve
	 OQfYlM71m4btZrX5BqiiahUgbBbl7rGS4dlwKklcr7hQPlYNJldoXtWXXgBKFjL8Yo
	 l7eFtzwYXHryigN0ceiLUm3f1uzHwQXM0Trt856lP8UjSUICtIJb9gkFXi9/AFIcaO
	 RCol05Z7J0XAb2DpKP5M/TTOyT/dArz7r+qtbfMSHH0k0zA3kQjLca4OPqcYcaLNb+
	 yw77EimEMkrZA==
X-Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
 netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
 edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg
X-In-Reply-To: <20261113031251.2437074-9-pablo@netfilter.org>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list