netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] netfilter: netfilter fixes
@ 2010-11-03 22:12 kaber
  2010-11-03 22:12 ` [PATCH 1/5] netfilter: nf_conntrack: allow nf_ct_alloc_hashtable() to get highmem pages kaber
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: kaber @ 2010-11-03 22:12 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

Hi Dave,

the following five patches for 2.6.37-rc fix a few netfilter bugs:

- a lost __GFP_HIGHMEM from conntrack hashtable allocation, from Eric

- two unused function warnings in NAT without ctnetlink, from myself

- a missing memory barrier in conntrack protocol registration, from Eric

- two information leaks in arp_tables and ip_tables, from Vasiliy Kulikov

Please apply or pull from:

git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-2.6.git

Thanks!

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

* [PATCH 1/5] netfilter: nf_conntrack: allow nf_ct_alloc_hashtable() to get highmem pages
  2010-11-03 22:12 [PATCH 0/5] netfilter: netfilter fixes kaber
@ 2010-11-03 22:12 ` kaber
  2010-11-03 22:12 ` [PATCH 2/5] netfilter: nf_nat: fix compiler warning with CONFIG_NF_CT_NETLINK=n kaber
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: kaber @ 2010-11-03 22:12 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>

commit ea781f197d6a8 (use SLAB_DESTROY_BY_RCU and get rid of call_rcu())
did a mistake in __vmalloc() call in nf_ct_alloc_hashtable().

I forgot to add __GFP_HIGHMEM, so pages were taken from LOWMEM only.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Cc: stable@kernel.org
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/netfilter/nf_conntrack_core.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 1eacf8d..27a5ea6 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1312,7 +1312,8 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int *vmalloced, int nulls)
 	if (!hash) {
 		*vmalloced = 1;
 		printk(KERN_WARNING "nf_conntrack: falling back to vmalloc.\n");
-		hash = __vmalloc(sz, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
+		hash = __vmalloc(sz, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+				 PAGE_KERNEL);
 	}
 
 	if (hash && nulls)
-- 
1.7.1


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

* [PATCH 2/5] netfilter: nf_nat: fix compiler warning with CONFIG_NF_CT_NETLINK=n
  2010-11-03 22:12 [PATCH 0/5] netfilter: netfilter fixes kaber
  2010-11-03 22:12 ` [PATCH 1/5] netfilter: nf_conntrack: allow nf_ct_alloc_hashtable() to get highmem pages kaber
@ 2010-11-03 22:12 ` kaber
  2010-11-03 22:12 ` [PATCH 3/5] netfilter: fix nf_conntrack_l4proto_register() kaber
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: kaber @ 2010-11-03 22:12 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Patrick McHardy <kaber@trash.net>

net/ipv4/netfilter/nf_nat_core.c:52: warning: 'nf_nat_proto_find_get' defined but not used
net/ipv4/netfilter/nf_nat_core.c:66: warning: 'nf_nat_proto_put' defined but not used

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/netfilter/nf_nat_core.c |   40 +++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
index 295c974..c04787c 100644
--- a/net/ipv4/netfilter/nf_nat_core.c
+++ b/net/ipv4/netfilter/nf_nat_core.c
@@ -47,26 +47,6 @@ __nf_nat_proto_find(u_int8_t protonum)
 	return rcu_dereference(nf_nat_protos[protonum]);
 }
 
-static const struct nf_nat_protocol *
-nf_nat_proto_find_get(u_int8_t protonum)
-{
-	const struct nf_nat_protocol *p;
-
-	rcu_read_lock();
-	p = __nf_nat_proto_find(protonum);
-	if (!try_module_get(p->me))
-		p = &nf_nat_unknown_protocol;
-	rcu_read_unlock();
-
-	return p;
-}
-
-static void
-nf_nat_proto_put(const struct nf_nat_protocol *p)
-{
-	module_put(p->me);
-}
-
 /* We keep an extra hash for each conntrack, for fast searching. */
 static inline unsigned int
 hash_by_src(const struct net *net, u16 zone,
@@ -588,6 +568,26 @@ static struct nf_ct_ext_type nat_extend __read_mostly = {
 #include <linux/netfilter/nfnetlink.h>
 #include <linux/netfilter/nfnetlink_conntrack.h>
 
+static const struct nf_nat_protocol *
+nf_nat_proto_find_get(u_int8_t protonum)
+{
+	const struct nf_nat_protocol *p;
+
+	rcu_read_lock();
+	p = __nf_nat_proto_find(protonum);
+	if (!try_module_get(p->me))
+		p = &nf_nat_unknown_protocol;
+	rcu_read_unlock();
+
+	return p;
+}
+
+static void
+nf_nat_proto_put(const struct nf_nat_protocol *p)
+{
+	module_put(p->me);
+}
+
 static const struct nla_policy protonat_nla_policy[CTA_PROTONAT_MAX+1] = {
 	[CTA_PROTONAT_PORT_MIN]	= { .type = NLA_U16 },
 	[CTA_PROTONAT_PORT_MAX]	= { .type = NLA_U16 },
-- 
1.7.1


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

* [PATCH 3/5] netfilter: fix nf_conntrack_l4proto_register()
  2010-11-03 22:12 [PATCH 0/5] netfilter: netfilter fixes kaber
  2010-11-03 22:12 ` [PATCH 1/5] netfilter: nf_conntrack: allow nf_ct_alloc_hashtable() to get highmem pages kaber
  2010-11-03 22:12 ` [PATCH 2/5] netfilter: nf_nat: fix compiler warning with CONFIG_NF_CT_NETLINK=n kaber
@ 2010-11-03 22:12 ` kaber
  2010-11-03 22:12 ` [PATCH 4/5] ipv4: netfilter: arp_tables: fix information leak to userland kaber
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: kaber @ 2010-11-03 22:12 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>

While doing __rcu annotations work on net/netfilter I found following
bug. On some arches, it is possible we publish a table while its content
is not yet committed to memory, and lockless reader can dereference wild
pointer.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/netfilter/nf_conntrack_proto.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
index ed6d929..dc7bb74 100644
--- a/net/netfilter/nf_conntrack_proto.c
+++ b/net/netfilter/nf_conntrack_proto.c
@@ -292,6 +292,12 @@ int nf_conntrack_l4proto_register(struct nf_conntrack_l4proto *l4proto)
 
 		for (i = 0; i < MAX_NF_CT_PROTO; i++)
 			proto_array[i] = &nf_conntrack_l4proto_generic;
+
+		/* Before making proto_array visible to lockless readers,
+		 * we must make sure its content is committed to memory.
+		 */
+		smp_wmb();
+
 		nf_ct_protos[l4proto->l3proto] = proto_array;
 	} else if (nf_ct_protos[l4proto->l3proto][l4proto->l4proto] !=
 					&nf_conntrack_l4proto_generic) {
-- 
1.7.1


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

* [PATCH 4/5] ipv4: netfilter: arp_tables: fix information leak to userland
  2010-11-03 22:12 [PATCH 0/5] netfilter: netfilter fixes kaber
                   ` (2 preceding siblings ...)
  2010-11-03 22:12 ` [PATCH 3/5] netfilter: fix nf_conntrack_l4proto_register() kaber
@ 2010-11-03 22:12 ` kaber
  2010-11-03 22:12 ` [PATCH 5/5] ipv4: netfilter: ip_tables: " kaber
  2010-11-04  1:54 ` [PATCH 0/5] netfilter: netfilter fixes David Miller
  5 siblings, 0 replies; 9+ messages in thread
From: kaber @ 2010-11-03 22:12 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Vasiliy Kulikov <segooon@gmail.com>

Structure arpt_getinfo is copied to userland with the field "name"
that has the last elements unitialized.  It leads to leaking of
contents of kernel stack memory.

Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/netfilter/arp_tables.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 3cad259..3fac340 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -927,6 +927,7 @@ static int get_info(struct net *net, void __user *user,
 			private = &tmp;
 		}
 #endif
+		memset(&info, 0, sizeof(info));
 		info.valid_hooks = t->valid_hooks;
 		memcpy(info.hook_entry, private->hook_entry,
 		       sizeof(info.hook_entry));
-- 
1.7.1


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

* [PATCH 5/5] ipv4: netfilter: ip_tables: fix information leak to userland
  2010-11-03 22:12 [PATCH 0/5] netfilter: netfilter fixes kaber
                   ` (3 preceding siblings ...)
  2010-11-03 22:12 ` [PATCH 4/5] ipv4: netfilter: arp_tables: fix information leak to userland kaber
@ 2010-11-03 22:12 ` kaber
  2010-11-03 22:55   ` Jan Engelhardt
  2010-11-04  1:54 ` [PATCH 0/5] netfilter: netfilter fixes David Miller
  5 siblings, 1 reply; 9+ messages in thread
From: kaber @ 2010-11-03 22:12 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Vasiliy Kulikov <segooon@gmail.com>

Structure ipt_getinfo is copied to userland with the field "name"
that has the last elements unitialized.  It leads to leaking of
contents of kernel stack memory.

Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/netfilter/ip_tables.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index d31b007..a846d63 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -1124,6 +1124,7 @@ static int get_info(struct net *net, void __user *user,
 			private = &tmp;
 		}
 #endif
+		memset(&info, 0, sizeof(info));
 		info.valid_hooks = t->valid_hooks;
 		memcpy(info.hook_entry, private->hook_entry,
 		       sizeof(info.hook_entry));
-- 
1.7.1


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

* Re: [PATCH 5/5] ipv4: netfilter: ip_tables: fix information leak to userland
  2010-11-03 22:12 ` [PATCH 5/5] ipv4: netfilter: ip_tables: " kaber
@ 2010-11-03 22:55   ` Jan Engelhardt
  2010-11-04  1:55     ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Engelhardt @ 2010-11-03 22:55 UTC (permalink / raw)
  To: kaber; +Cc: davem, netfilter-devel, netdev

On Wednesday 2010-11-03 23:12, kaber@trash.net wrote:

>From: Vasiliy Kulikov <segooon@gmail.com>
>
>Structure ipt_getinfo is copied to userland with the field "name"
>that has the last elements unitialized.  It leads to leaking of
>contents of kernel stack memory.
>
>Signed-off-by: Vasiliy Kulikov <segooon@gmail.com>
>Signed-off-by: Patrick McHardy <kaber@trash.net>
>---
> net/ipv4/netfilter/ip_tables.c |    1 +


But then we would also need this:


--------8<-------------
parent 93aa45607748d2ffa73f41a435dced6a2fd90cb5 (v2.6.36-rc3-1020-g93aa456)
commit 8aff3f67fa47f7d3211aea8bbef999554d6f65e5
Author: Jan Engelhardt <jengelh@medozas.de>
Date:   Wed Nov 3 23:55:18 2010 +0100

netfilter: ip6_tables: fix information leak to userspace

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
 net/ipv6/netfilter/ip6_tables.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
index c683e9e..d13f893 100644
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -1137,6 +1137,7 @@ static int get_info(struct net *net, void __user *user,
 			private = &tmp;
 		}
 #endif
+		memset(&info, 0, sizeof(info));
 		info.valid_hooks = t->valid_hooks;
 		memcpy(info.hook_entry, private->hook_entry,
 		       sizeof(info.hook_entry));
-- 
# Created with git-export-patch

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

* Re: [PATCH 0/5] netfilter: netfilter fixes
  2010-11-03 22:12 [PATCH 0/5] netfilter: netfilter fixes kaber
                   ` (4 preceding siblings ...)
  2010-11-03 22:12 ` [PATCH 5/5] ipv4: netfilter: ip_tables: " kaber
@ 2010-11-04  1:54 ` David Miller
  5 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2010-11-04  1:54 UTC (permalink / raw)
  To: kaber; +Cc: netfilter-devel, netdev

From: kaber@trash.net
Date: Wed,  3 Nov 2010 23:12:47 +0100

> Please apply or pull from:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-2.6.git

Pulled, thanks a lot Patrick.

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

* Re: [PATCH 5/5] ipv4: netfilter: ip_tables: fix information leak to userland
  2010-11-03 22:55   ` Jan Engelhardt
@ 2010-11-04  1:55     ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2010-11-04  1:55 UTC (permalink / raw)
  To: jengelh; +Cc: kaber, netfilter-devel, netdev

From: Jan Engelhardt <jengelh@medozas.de>
Date: Wed, 3 Nov 2010 23:55:58 +0100 (CET)

> netfilter: ip6_tables: fix information leak to userspace
> 
> Signed-off-by: Jan Engelhardt <jengelh@medozas.de>

Good catch, applied, thanks Jan.

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

end of thread, other threads:[~2010-11-04  1:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-03 22:12 [PATCH 0/5] netfilter: netfilter fixes kaber
2010-11-03 22:12 ` [PATCH 1/5] netfilter: nf_conntrack: allow nf_ct_alloc_hashtable() to get highmem pages kaber
2010-11-03 22:12 ` [PATCH 2/5] netfilter: nf_nat: fix compiler warning with CONFIG_NF_CT_NETLINK=n kaber
2010-11-03 22:12 ` [PATCH 3/5] netfilter: fix nf_conntrack_l4proto_register() kaber
2010-11-03 22:12 ` [PATCH 4/5] ipv4: netfilter: arp_tables: fix information leak to userland kaber
2010-11-03 22:12 ` [PATCH 5/5] ipv4: netfilter: ip_tables: " kaber
2010-11-03 22:55   ` Jan Engelhardt
2010-11-04  1:55     ` David Miller
2010-11-04  1:54 ` [PATCH 0/5] netfilter: netfilter fixes David Miller

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).