Skip to content

Commit 2671fa4

Browse files
JonathonReinhartdavem330
authored andcommitted
netfilter: conntrack: Make global sysctls readonly in non-init netns
These sysctls point to global variables: - NF_SYSCTL_CT_MAX (&nf_conntrack_max) - NF_SYSCTL_CT_EXPECT_MAX (&nf_ct_expect_max) - NF_SYSCTL_CT_BUCKETS (&nf_conntrack_htable_size_user) Because their data pointers are not updated to point to per-netns structures, they must be marked read-only in a non-init_net ns. Otherwise, changes in any net namespace are reflected in (leaked into) all other net namespaces. This problem has existed since the introduction of net namespaces. The current logic marks them read-only only if the net namespace is owned by an unprivileged user (other than init_user_ns). Commit d0febd8 ("netfilter: conntrack: re-visit sysctls in unprivileged namespaces") "exposes all sysctls even if the namespace is unpriviliged." Since we need to mark them readonly in any case, we can forego the unprivileged user check altogether. Fixes: d0febd8 ("netfilter: conntrack: re-visit sysctls in unprivileged namespaces") Signed-off-by: Jonathon Reinhart <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 31c4d2f commit 2671fa4

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

net/netfilter/nf_conntrack_standalone.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,16 +1060,10 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
10601060
nf_conntrack_standalone_init_dccp_sysctl(net, table);
10611061
nf_conntrack_standalone_init_gre_sysctl(net, table);
10621062

1063-
/* Don't allow unprivileged users to alter certain sysctls */
1064-
if (net->user_ns != &init_user_ns) {
1063+
/* Don't allow non-init_net ns to alter global sysctls */
1064+
if (!net_eq(&init_net, net)) {
10651065
table[NF_SYSCTL_CT_MAX].mode = 0444;
10661066
table[NF_SYSCTL_CT_EXPECT_MAX].mode = 0444;
1067-
table[NF_SYSCTL_CT_HELPER].mode = 0444;
1068-
#ifdef CONFIG_NF_CONNTRACK_EVENTS
1069-
table[NF_SYSCTL_CT_EVENTS].mode = 0444;
1070-
#endif
1071-
table[NF_SYSCTL_CT_BUCKETS].mode = 0444;
1072-
} else if (!net_eq(&init_net, net)) {
10731067
table[NF_SYSCTL_CT_BUCKETS].mode = 0444;
10741068
}
10751069

0 commit comments

Comments
 (0)