netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for 2.6.33] conntrack: restrict runtime hashsize modifications
@ 2010-02-03 20:39 Alexey Dobriyan
  2010-02-03 20:50 ` Jon Masters
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Alexey Dobriyan @ 2010-02-03 20:39 UTC (permalink / raw)
  To: davem, kaber; +Cc: jonathan, eric.dumazet, netdev, netfilter-devel

Jon Masters correctly points out that conntrack hash sizes
(nf_conntrack_htable_size) are global (not per-netns) and
modifiable at runtime via /sys/module/nf_conntrack/hashsize .

Steps to reproduce:
	clone(CLONE_NEWNET)
	[grow /sys/module/nf_conntrack/hashsize]
	exit()

At netns exit we are going to scan random memory for conntracks to be killed.

Apparently there is a code which deals with hashtable resize for
init_net (and it was there befode netns conntrack code), so prohibit
hashsize modification if there is more than one netns exists.

To change hashtable sizes, you need to reload module.

Expectation hashtable size was simply glued to a variable with no code
to rehash expectations, so it was a bug to allow writing to it.
Make "expect_hashsize" readonly.

This is temporarily until we figure out what to do.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: stable@kernel.org
---

 net/netfilter/nf_conntrack_core.c   |   15 +++++++++++++++
 net/netfilter/nf_conntrack_expect.c |    2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -21,6 +21,7 @@
 #include <linux/stddef.h>
 #include <linux/slab.h>
 #include <linux/random.h>
+#include <linux/rtnetlink.h>
 #include <linux/jhash.h>
 #include <linux/err.h>
 #include <linux/percpu.h>
@@ -1198,6 +1199,20 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
 	if (!nf_conntrack_htable_size)
 		return param_set_uint(val, kp);
 
+	{
+		struct net *net;
+		unsigned int nr;
+
+		nr = 0;
+		rtnl_lock();
+		for_each_net(net)
+			nr++;
+		rtnl_unlock();
+		/* init_net always exists */
+		if (nr != 1)
+			return -EINVAL;
+	}
+
 	hashsize = simple_strtoul(val, NULL, 0);
 	if (!hashsize)
 		return -EINVAL;
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -569,7 +569,7 @@ static void exp_proc_remove(struct net *net)
 #endif /* CONFIG_PROC_FS */
 }
 
-module_param_named(expect_hashsize, nf_ct_expect_hsize, uint, 0600);
+module_param_named(expect_hashsize, nf_ct_expect_hsize, uint, 0400);
 
 int nf_conntrack_expect_init(struct net *net)
 {

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2010-02-08 14:35 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-03 20:39 [PATCH for 2.6.33] conntrack: restrict runtime hashsize modifications Alexey Dobriyan
2010-02-03 20:50 ` Jon Masters
2010-02-04 16:18 ` Patrick McHardy
2010-02-04 16:27   ` Patrick McHardy
2010-02-04 20:18     ` Jon Masters
2010-02-05 10:00       ` Patrick McHardy
2010-02-05 10:14         ` Jon Masters
2010-02-05 10:21           ` Patrick McHardy
2010-02-04 17:04   ` Patrick McHardy
2010-02-04 19:47     ` Alexey Dobriyan
2010-02-04 20:23       ` Jon Masters
2010-02-05 10:00       ` Patrick McHardy
2010-02-05 10:11         ` Jon Masters
2010-02-05 10:19           ` Patrick McHardy
2010-02-05 11:16         ` Patrick McHardy
2010-02-05 11:19           ` Alexey Dobriyan
2010-02-05 11:22             ` Patrick McHardy
2010-02-05 11:25               ` Patrick McHardy
2010-02-05 11:51               ` Jon Masters
2010-02-05 11:23             ` Alexey Dobriyan
2010-02-05 22:04         ` Alexey Dobriyan
2010-02-08 13:34           ` Patrick McHardy
2010-02-08 14:35             ` Patrick McHardy
2010-02-04 20:20     ` Jon Masters
2010-02-05 10:03       ` Patrick McHardy
2010-02-05 10:12         ` Jon Masters
2010-02-05 10:21           ` Patrick McHardy
2010-02-04 17:26 ` Patrick McHardy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).