All of lore.kernel.org
 help / color / mirror / Atom feed
* netfilter 00/03: netfilter fixes
@ 2009-07-16 12:26 Patrick McHardy
  2009-07-16 12:26 ` netfilter 01/03: add netfilter git to MAINTAINERS Patrick McHardy
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Patrick McHardy @ 2009-07-16 12:26 UTC (permalink / raw)
  To: davem; +Cc: netdev, Patrick McHardy, netfilter-devel

Hi Dave,

following are two netfilter fixes for 2.6.31 and a MAINTAINERS update:

- a fix for the nf_conntrack_alloc() race from Eric
- a fix for incorrect invocation of nf_log_packet() in the new osf match
- a patch to add my netfilter git tree to MAINTAINERS

Please apply or pull from:

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

Thanks!


 Documentation/RCU/rculist_nulls.txt |    7 ++++++-
 MAINTAINERS                         |    1 +
 net/netfilter/nf_conntrack_core.c   |   21 ++++++++++++++++++---
 net/netfilter/xt_osf.c              |    5 +++--
 4 files changed, 28 insertions(+), 6 deletions(-)

Eric Dumazet (1):
      netfilter: nf_conntrack: nf_conntrack_alloc() fixes

Joe Perches (1):
      netfilter: add netfilter git to MAINTAINERS

Patrick McHardy (1):
      netfilter: xt_osf: fix nf_log_packet() arguments

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

* netfilter 01/03: add netfilter git to MAINTAINERS
  2009-07-16 12:26 netfilter 00/03: netfilter fixes Patrick McHardy
@ 2009-07-16 12:26 ` Patrick McHardy
  2009-07-16 12:26 ` netfilter 02/03: xt_osf: fix nf_log_packet() arguments Patrick McHardy
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Patrick McHardy @ 2009-07-16 12:26 UTC (permalink / raw)
  To: davem; +Cc: netdev, Patrick McHardy, netfilter-devel

commit 3f1f7cf08ddf10ef7fbf06d881582c95b9747f4e
Author: Joe Perches <joe@perches.com>
Date:   Wed Jul 1 11:32:10 2009 +0200

    netfilter: add netfilter git to MAINTAINERS
    
    Signed-off-by: Joe Perches <joe@perches.com>
    Signed-off-by: Patrick McHardy <kaber@trash.net>

diff --git a/MAINTAINERS b/MAINTAINERS
index fa2a16d..a5042de 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4044,6 +4044,7 @@ L:	netfilter@vger.kernel.org
 L:	coreteam@netfilter.org
 W:	http://www.netfilter.org/
 W:	http://www.iptables.org/
+T:	git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-2.6.git
 S:	Supported
 F:	include/linux/netfilter*
 F:	include/linux/netfilter/

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

* netfilter 02/03: xt_osf: fix nf_log_packet() arguments
  2009-07-16 12:26 netfilter 00/03: netfilter fixes Patrick McHardy
  2009-07-16 12:26 ` netfilter 01/03: add netfilter git to MAINTAINERS Patrick McHardy
@ 2009-07-16 12:26 ` Patrick McHardy
  2009-07-16 12:26 ` netfilter 03/03: nf_conntrack: nf_conntrack_alloc() fixes Patrick McHardy
  2009-07-17  0:37 ` netfilter 00/03: netfilter fixes David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Patrick McHardy @ 2009-07-16 12:26 UTC (permalink / raw)
  To: davem; +Cc: netdev, Patrick McHardy, netfilter-devel

commit aa6a03eb0ae859c1371555ef381de4c96ca1e4e6
Author: Patrick McHardy <kaber@trash.net>
Date:   Thu Jul 16 14:01:54 2009 +0200

    netfilter: xt_osf: fix nf_log_packet() arguments
    
    The first argument is the address family, the second one the hook
    number.
    
    Signed-off-by: Patrick McHardy <kaber@trash.net>

diff --git a/net/netfilter/xt_osf.c b/net/netfilter/xt_osf.c
index 863e409..0f482e2 100644
--- a/net/netfilter/xt_osf.c
+++ b/net/netfilter/xt_osf.c
@@ -330,7 +330,8 @@ static bool xt_osf_match_packet(const struct sk_buff *skb,
 			fcount++;
 
 			if (info->flags & XT_OSF_LOG)
-				nf_log_packet(p->hooknum, 0, skb, p->in, p->out, NULL,
+				nf_log_packet(p->family, p->hooknum, skb,
+					p->in, p->out, NULL,
 					"%s [%s:%s] : %pi4:%d -> %pi4:%d hops=%d\n",
 					f->genre, f->version, f->subtype,
 					&ip->saddr, ntohs(tcp->source),
@@ -345,7 +346,7 @@ static bool xt_osf_match_packet(const struct sk_buff *skb,
 	rcu_read_unlock();
 
 	if (!fcount && (info->flags & XT_OSF_LOG))
-		nf_log_packet(p->hooknum, 0, skb, p->in, p->out, NULL,
+		nf_log_packet(p->family, p->hooknum, skb, p->in, p->out, NULL,
 			"Remote OS is not known: %pi4:%u -> %pi4:%u\n",
 				&ip->saddr, ntohs(tcp->source),
 				&ip->daddr, ntohs(tcp->dest));

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

* netfilter 03/03: nf_conntrack: nf_conntrack_alloc() fixes
  2009-07-16 12:26 netfilter 00/03: netfilter fixes Patrick McHardy
  2009-07-16 12:26 ` netfilter 01/03: add netfilter git to MAINTAINERS Patrick McHardy
  2009-07-16 12:26 ` netfilter 02/03: xt_osf: fix nf_log_packet() arguments Patrick McHardy
@ 2009-07-16 12:26 ` Patrick McHardy
  2009-07-17  0:37 ` netfilter 00/03: netfilter fixes David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Patrick McHardy @ 2009-07-16 12:26 UTC (permalink / raw)
  To: davem; +Cc: netdev, Patrick McHardy, netfilter-devel

commit 941297f443f871b8c3372feccf27a8733f6ce9e9
Author: Eric Dumazet <eric.dumazet@gmail.com>
Date:   Thu Jul 16 14:03:40 2009 +0200

    netfilter: nf_conntrack: nf_conntrack_alloc() fixes
    
    When a slab cache uses SLAB_DESTROY_BY_RCU, we must be careful when allocating
    objects, since slab allocator could give a freed object still used by lockless
    readers.
    
    In particular, nf_conntrack RCU lookups rely on ct->tuplehash[xxx].hnnode.next
    being always valid (ie containing a valid 'nulls' value, or a valid pointer to next
    object in hash chain.)
    
    kmem_cache_zalloc() setups object with NULL values, but a NULL value is not valid
    for ct->tuplehash[xxx].hnnode.next.
    
    Fix is to call kmem_cache_alloc() and do the zeroing ourself.
    
    As spotted by Patrick, we also need to make sure lookup keys are committed to
    memory before setting refcount to 1, or a lockless reader could get a reference
    on the old version of the object. Its key re-check could then pass the barrier.
    
    Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
    Signed-off-by: Patrick McHardy <kaber@trash.net>

diff --git a/Documentation/RCU/rculist_nulls.txt b/Documentation/RCU/rculist_nulls.txt
index 93cb28d..18f9651 100644
--- a/Documentation/RCU/rculist_nulls.txt
+++ b/Documentation/RCU/rculist_nulls.txt
@@ -83,11 +83,12 @@ not detect it missed following items in original chain.
 obj = kmem_cache_alloc(...);
 lock_chain(); // typically a spin_lock()
 obj->key = key;
-atomic_inc(&obj->refcnt);
 /*
  * we need to make sure obj->key is updated before obj->next
+ * or obj->refcnt
  */
 smp_wmb();
+atomic_set(&obj->refcnt, 1);
 hlist_add_head_rcu(&obj->obj_node, list);
 unlock_chain(); // typically a spin_unlock()
 
@@ -159,6 +160,10 @@ out:
 obj = kmem_cache_alloc(cachep);
 lock_chain(); // typically a spin_lock()
 obj->key = key;
+/*
+ * changes to obj->key must be visible before refcnt one
+ */
+smp_wmb();
 atomic_set(&obj->refcnt, 1);
 /*
  * insert obj in RCU way (readers might be traversing chain)
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 7508f11..b5869b9 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -561,23 +561,38 @@ struct nf_conn *nf_conntrack_alloc(struct net *net,
 		}
 	}
 
-	ct = kmem_cache_zalloc(nf_conntrack_cachep, gfp);
+	/*
+	 * Do not use kmem_cache_zalloc(), as this cache uses
+	 * SLAB_DESTROY_BY_RCU.
+	 */
+	ct = kmem_cache_alloc(nf_conntrack_cachep, gfp);
 	if (ct == NULL) {
 		pr_debug("nf_conntrack_alloc: Can't alloc conntrack.\n");
 		atomic_dec(&net->ct.count);
 		return ERR_PTR(-ENOMEM);
 	}
-
+	/*
+	 * Let ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode.next
+	 * and ct->tuplehash[IP_CT_DIR_REPLY].hnnode.next unchanged.
+	 */
+	memset(&ct->tuplehash[IP_CT_DIR_MAX], 0,
+	       sizeof(*ct) - offsetof(struct nf_conn, tuplehash[IP_CT_DIR_MAX]));
 	spin_lock_init(&ct->lock);
-	atomic_set(&ct->ct_general.use, 1);
 	ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple = *orig;
+	ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode.pprev = NULL;
 	ct->tuplehash[IP_CT_DIR_REPLY].tuple = *repl;
+	ct->tuplehash[IP_CT_DIR_REPLY].hnnode.pprev = NULL;
 	/* Don't set timer yet: wait for confirmation */
 	setup_timer(&ct->timeout, death_by_timeout, (unsigned long)ct);
 #ifdef CONFIG_NET_NS
 	ct->ct_net = net;
 #endif
 
+	/*
+	 * changes to lookup keys must be done before setting refcnt to 1
+	 */
+	smp_wmb();
+	atomic_set(&ct->ct_general.use, 1);
 	return ct;
 }
 EXPORT_SYMBOL_GPL(nf_conntrack_alloc);

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

* Re: netfilter 00/03: netfilter fixes
  2009-07-16 12:26 netfilter 00/03: netfilter fixes Patrick McHardy
                   ` (2 preceding siblings ...)
  2009-07-16 12:26 ` netfilter 03/03: nf_conntrack: nf_conntrack_alloc() fixes Patrick McHardy
@ 2009-07-17  0:37 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2009-07-17  0:37 UTC (permalink / raw)
  To: kaber; +Cc: netdev, netfilter-devel

From: Patrick McHardy <kaber@trash.net>
Date: Thu, 16 Jul 2009 14:26:44 +0200 (MEST)

> following are two netfilter fixes for 2.6.31 and a MAINTAINERS update:
> 
> - a fix for the nf_conntrack_alloc() race from Eric
> - a fix for incorrect invocation of nf_log_packet() in the new osf match
> - a patch to add my netfilter git tree to MAINTAINERS
> 
> Please apply or pull from:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-2.6.git master

Pulled, thanks a lot Patrick!

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

end of thread, other threads:[~2009-07-17  0:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-16 12:26 netfilter 00/03: netfilter fixes Patrick McHardy
2009-07-16 12:26 ` netfilter 01/03: add netfilter git to MAINTAINERS Patrick McHardy
2009-07-16 12:26 ` netfilter 02/03: xt_osf: fix nf_log_packet() arguments Patrick McHardy
2009-07-16 12:26 ` netfilter 03/03: nf_conntrack: nf_conntrack_alloc() fixes Patrick McHardy
2009-07-17  0:37 ` netfilter 00/03: netfilter fixes David Miller

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.