Skip to contentSkip to conversation

netfilter: conntrack: Unable to change conntrack accounting of a net namespace via 'nf_conntrack_acct' sysfs

REGRESSION Applied Shmulik Ladkani 3 participants 6 messages Aug 27, 2019 – Aug 28, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

Prior d912dec12428 ("netfilter: conntrack: merge acct and helper sysctl table with main one") one was able to enable extended accounting within a (non-init)
net-namespace by setting: 'net.netfilter.nf_conntrack_acct=1'

However since d912dec12428, doing so results in changing init_net's sysctl_acct field, instead of the relevant net's sysctl_acct.

Seen in original code, PRE d912dec12428, which creates a reference to each net's _OWN_ ct.sysctl_acct within a separate acct_sysctl_table, snip:

-static int nf_conntrack_acct_init_sysctl(struct net *net) -{
- struct ctl_table *table;
-
- table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
- GFP_KERNEL);
- if (!table)
- goto out;
-
- table[0].data = &net->ct.sysctl_acct;
-

(where 'nf_conntrack_acct_init_sysctl()' was originally called by 'nf_conntrack_acct_pernet_init()').

However POST d912dec12428, the per-net netfilter sysctl table simply inherits from global 'nf_ct_sysctl_table[]', which has

+ .data = &init_net.ct.sysctl_acct,

effectivly making any 'net.netfilter.nf_conntrack_acct' sysctl change affect the 'init_net' and not relevant net namespace.

Also, looks like "nf_conntrack_helper", "nf_conntrack_events", "nf_conntrack_timestamp" where also harmed in a similar way, see:

d912dec12428 ("netfilter: conntrack: merge acct and helper sysctl table with main one") cb2833ed0044 ("netfilter: conntrack: merge ecache and timestamp sysctl tables with main one")

Florian, would it be possible for you to revert these on -net ?

Many thanks,
Shmulik

maintainer
#1 lore raw
Quoted 20 lines · Shmulik Ladkani
(quoted diff) +0 -11
-static int nf_conntrack_acct_init_sysctl(struct net *net)
-{
-	struct ctl_table *table;
-
-	table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
-			GFP_KERNEL);
-	if (!table)
-		goto out;
-
-	table[0].data = &net->ct.sysctl_acct;
-

(where 'nf_conntrack_acct_init_sysctl()' was originally called by 'nf_conntrack_acct_pernet_init()').

However POST d912dec12428, the per-net netfilter sysctl table simply inherits from global 'nf_ct_sysctl_table[]', which has

(quoted diff) +1 -0
+		.data		= &init_net.ct.sysctl_acct,
Quoted 8 lines

effectivly making any 'net.netfilter.nf_conntrack_acct' sysctl change affect the 'init_net' and not relevant net namespace.

Also, looks like "nf_conntrack_helper", "nf_conntrack_events", "nf_conntrack_timestamp" where also harmed in a similar way, see:

d912dec12428 ("netfilter: conntrack: merge acct and helper sysctl table with main one") cb2833ed0044 ("netfilter: conntrack: merge ecache and timestamp sysctl tables with main one")

Thanks for reporting this bug, I will submit a patch soon.

maintainer
#2 lore raw

PATCH 1/1 netfilter: conntrack: make sysctls per-namespace again

In reply to Shmulik Ladkani

When I merged the extension sysctl tables with the main one I forgot to reset them on netns creation. They currently read/write init_net settings.

Fixes d912dec12428 ("netfilter: conntrack: merge acct and helper sysctl table with main one")
Fixes cb2833ed0044 ("netfilter: conntrack: merge ecache and timestamp sysctl tables with main one")

---
Shmulik, could you please check if this fixes the bug for you? Thanks!

 net/netfilter/nf_conntrack_standalone.c | 5 +++++
 1 file changed, 5 insertions(+)
net/netfilter/nf_conntrack_standalone.c +5 -0
index e0d392cb3075..0006503d2da9 100644
@@ -1037,8 +1037,13 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
 	table[NF_SYSCTL_CT_COUNT].data = &net->ct.count;
 	table[NF_SYSCTL_CT_CHECKSUM].data = &net->ct.sysctl_checksum;
 	table[NF_SYSCTL_CT_LOG_INVALID].data = &net->ct.sysctl_log_invalid;
+	table[NF_SYSCTL_CT_ACCT].data = &net->ct.sysctl_acct;
+	table[NF_SYSCTL_CT_HELPER].data = &net->ct.sysctl_auto_assign_helper;
 #ifdef CONFIG_NF_CONNTRACK_EVENTS
 	table[NF_SYSCTL_CT_EVENTS].data = &net->ct.sysctl_events;
+#endif
+#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
+	table[NF_SYSCTL_CT_TIMESTAMP].data = &net->ct.sysctl_tstamp;
 #endif
 	table[NF_SYSCTL_CT_PROTO_TIMEOUT_GENERIC].data = &nf_generic_pernet(net)->timeout;
 	table[NF_SYSCTL_CT_PROTO_TIMEOUT_ICMP].data = &nf_icmp_pernet(net)->timeout;
Signature · 1 line
2.21.0
#3 lore raw

Re: [PATCH nf] netfilter: conntrack: make sysctls per-namespace again

Quoted 3 lines · On Tue, 27 Aug 2019 13:24:52 +0200 Florian Westphal <[email protected]> wrote:

---
Shmulik, could you please check if this fixes the bug for you? Thanks!

Thanks Florian for the quick fix, I'll check this by tomorrow mytime.

Shmulik

maintainer Applied
#4 lore raw

Re: [PATCH nf] netfilter: conntrack: make sysctls per-namespace again

In reply to Florian Westphal
Quoted 2 lines · Florian Westphal

When I merged the extension sysctl tables with the main one I forgot to reset them on netns creation. They currently read/write init_net settings.

Applied, thanks Florian.

author Tested-by on v1 1/1
#5 lore raw

Re: [PATCH nf] netfilter: conntrack: make sysctls per-namespace again

In reply to Florian Westphal
Quoted 10 lines · On Tue, 27 Aug 2019 13:24:52 +0200 Florian Westphal <[email protected]> wrote:

When I merged the extension sysctl tables with the main one I forgot to reset them on netns creation. They currently read/write init_net settings.

Fixes d912dec12428 ("netfilter: conntrack: merge acct and helper sysctl table with main one")
Fixes cb2833ed0044 ("netfilter: conntrack: merge ecache and timestamp sysctl tables with main one")

---
Shmulik, could you please check if this fixes the bug for you? Thanks!