Skip to contentSkip to conversation

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

PATCH In review Pablo Neira Ayuso 2 participants 3 messages Aug 24 – Aug 25

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

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

Expose nf_hooks_lwtunnel sysctl with 0444 mode from non init-netns instead of 0644, sashiko reports this is exposing a global static branch to modification by unprivileged users.

Fixes a2225e0250c5 ("netfilter: move the sysctl nf_hooks_lwtunnel into the netfilter core")
---
 net/netfilter/nf_hooks_lwtunnel.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
net/netfilter/nf_hooks_lwtunnel.c +8 -4
index 4e1eef1ba0f1..0b4fca26233f 100644
@@ -68,14 +68,18 @@ static int __net_init nf_lwtunnel_net_init(struct net *net)
 {
 	const struct ctl_table *table;
 	struct ctl_table_header *hdr;
+	struct ctl_table *dup;
 
 	table = nf_lwtunnel_sysctl_table;
 	if (!net_eq(net, &init_net)) {
-		table = kmemdup(nf_lwtunnel_sysctl_table,
-				sizeof(nf_lwtunnel_sysctl_table),
-				GFP_KERNEL);
-		if (!table)
+		dup = kmemdup(nf_lwtunnel_sysctl_table,
+			      sizeof(nf_lwtunnel_sysctl_table),
+			      GFP_KERNEL);
+		if (!dup)
 			goto err_alloc;
+
+		dup->mode = 0444;
+		table = dup;
 	}
 
 	hdr = register_net_sysctl_sz(net, "net/netfilter", table,
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 3 lines · Pablo Neira Ayuso

Expose nf_hooks_lwtunnel sysctl with 0444 mode from non init-netns instead of 0644, sashiko reports this is exposing a global static branch to modification by unprivileged users.

No objection but I find this report weird. Why is that an issue in the first place?

Quoted 1 line
Fixes a2225e0250c5 ("netfilter: move the sysctl nf_hooks_lwtunnel into the netfilter core")

AFAICS it was exposed before this too, just via conntrack module and not the core.

author maintainer
#2 lore raw

Hi Florian,

Quoted 7 lines · Florian Westphal
Quoted 3 lines · Pablo Neira Ayuso

Expose nf_hooks_lwtunnel sysctl with 0444 mode from non init-netns instead of 0644, sashiko reports this is exposing a global static branch to modification by unprivileged users.

No objection but I find this report weird. Why is that an issue in the first place?

Sashiko specifies that this allows for unpriviledged user to turn on/off the nf_hooks_lwtunnel via static key, which is something that only init_net should be able to do.

Quoted 3 lines
Quoted 1 line
Fixes a2225e0250c5 ("netfilter: move the sysctl nf_hooks_lwtunnel into the netfilter core")

AFAICS it was exposed before this too, just via conntrack module and not the core.

I can point to the initial patch:

7a3f5b0de364 ("netfilter: add netfilter hooks to SRv6 data plane")