All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathon Reinhart <jonathon.reinhart@gmail.com>
To: stable@vger.kernel.org
Cc: Jonathon Reinhart <jonathon.reinhart@gmail.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	"David S. Miller" <davem@davemloft.net>,
	Florian Westphal <fw@strlen.de>,
	netdev@vger.kernel.org
Subject: [PATCH] netfilter: conntrack: Make global sysctls readonly in non-init netns
Date: Thu, 13 May 2021 04:57:20 -0400	[thread overview]
Message-ID: <20210513085720.32367-1-jonathon.reinhart@gmail.com> (raw)

commit 2671fa4dc0109d3fb581bc3078fdf17b5d9080f6 upstream.

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.

This patch is necessarily different from the upstream patch due to the
refactoring which took place since 5.4 in commit d0febd81ae77
("netfilter: conntrack: re-visit sysctls in unprivileged namespaces").

Signed-off-by: Jonathon Reinhart <jonathon.reinhart@gmail.com>
---

Upstream commit 2671fa4dc010 was already applied to the 5.10, 5.11, and
5.12 trees.

This was tested on 5.4.118, so please apply to 5.4.y.
---
 net/netfilter/nf_conntrack_standalone.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 1a6982540126..46e3c9f5f4ce 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -1071,8 +1071,11 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
 #endif
 	}
 
-	if (!net_eq(&init_net, net))
+	if (!net_eq(&init_net, net)) {
+		table[NF_SYSCTL_CT_MAX].mode = 0444;
+		table[NF_SYSCTL_CT_EXPECT_MAX].mode = 0444;
 		table[NF_SYSCTL_CT_BUCKETS].mode = 0444;
+	}
 
 	net->ct.sysctl_header = register_net_sysctl(net, "net/netfilter", table);
 	if (!net->ct.sysctl_header)
-- 
2.20.1


             reply	other threads:[~2021-05-13  8:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-13  8:57 Jonathon Reinhart [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-05-13  8:28 [PATCH] netfilter: conntrack: Make global sysctls readonly in non-init netns Jonathon Reinhart
2021-05-17 12:03 ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210513085720.32367-1-jonathon.reinhart@gmail.com \
    --to=jonathon.reinhart@gmail.com \
    --cc=davem@davemloft.net \
    --cc=fw@strlen.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.