[PATCH] netfilter: Use hlist_add_head_rcu() in nf_conntrack_set_hashsize()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Dumazet
Date: Tuesday, March 24, 2009 - 12:54 pm

Eric Dumazet a écrit :

While working on this stuff, I found one suspect use of hlist_add_head()

Its not a hot path, I believe following patch would make sure nothing
wrong happens.

If a chain contains element A and B, then we might build a new table
with a new chain containing B and A (in this reverse order), and
a cpu could see A->next = B (new pointer),  B->next = A (old pointer)

Thanks

[PATCH] netfilter: Use hlist_add_head_rcu() in nf_conntrack_set_hashsize()

Using hlist_add_head() in nf_conntrack_set_hashsize() is quite dangerous.
Without any barrier, one CPU could see a loop while doing its lookup.
Its true new table cannot be seen by another cpu, but previous table is still
readable.

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>

diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 55befe5..54e983f 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1121,7 +1121,7 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
 					struct nf_conntrack_tuple_hash, hnode);
 			hlist_del_rcu(&h->hnode);
 			bucket = __hash_conntrack(&h->tuple, hashsize, rnd);
-			hlist_add_head(&h->hnode, &hash[bucket]);
+			hlist_add_head_rcu(&h->hnode, &hash[bucket]);
 		}
 	}
 	old_size = nf_conntrack_htable_size;


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
ucc_geth: nf_conntrack: table full, dropping packet., Joakim Tjernlund, (Mon Mar 23, 3:42 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Patrick McHardy, (Mon Mar 23, 5:15 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Joakim Tjernlund, (Mon Mar 23, 5:25 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Patrick McHardy, (Mon Mar 23, 5:29 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Joakim Tjernlund, (Mon Mar 23, 5:59 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Joakim Tjernlund, (Mon Mar 23, 10:42 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Patrick McHardy, (Mon Mar 23, 10:49 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Eric Dumazet, (Mon Mar 23, 10:49 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Joakim Tjernlund, (Mon Mar 23, 11:04 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Eric Dumazet, (Mon Mar 23, 11:08 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Joakim Tjernlund, (Tue Mar 24, 1:22 am)
Re: ucc_geth: nf_conntrack: table full, dropping packet., Joakim Tjernlund, (Tue Mar 24, 3:55 am)
Re: [PATCH] conntrack: Reduce conntrack count in nf_conntr ..., Joakim Tjernlund, (Tue Mar 24, 11:29 am)
[PATCH] netfilter: Use hlist_add_head_rcu() in nf_conntrac ..., Eric Dumazet, (Tue Mar 24, 12:54 pm)