All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/10][CTNETLINK] Fix race condition on conntrack creation
@ 2006-07-07  2:13 Pablo Neira Ayuso
  2006-07-07  4:45 ` Patrick McHardy
  0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2006-07-07  2:13 UTC (permalink / raw)
  To: Netfilter Development Mailinglist; +Cc: Patrick McHardy

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]

Current conntrack creation path can run into rare race conditions, make
the creation process atomic.

As side-effect, this patch simplifies the conntrack core API.

This patch depends on [PATCH 4/10] and [PATCH 5/10]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

-- 
The dawn of the fourth age of Linux firewalling is coming; a time of 
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris

[-- Attachment #2: 03racy.patch --]
[-- Type: text/plain, Size: 1861 bytes --]

[CTNETLINK] Fix race condition on conntrack creation

Current conntrack creation path can run into rare race conditions, make
the creation process atomic.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Index: net-2.6/net/ipv4/netfilter/ip_conntrack_netlink.c
===================================================================
--- net-2.6.orig/net/ipv4/netfilter/ip_conntrack_netlink.c	2006-07-07 00:15:14.000000000 +0200
+++ net-2.6/net/ipv4/netfilter/ip_conntrack_netlink.c	2006-07-07 01:52:14.000000000 +0200
@@ -1059,13 +1059,12 @@ ctnetlink_create_conntrack(struct nfattr
 		ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
 #endif
 
-	ct->helper = ip_conntrack_helper_find_get(rtuple);
-
-	add_timer(&ct->timeout);
+	/* we do no want any races on hash insertion */
+	write_lock_bh(&ip_conntrack_lock);
+	ct->helper = ip_conntrack_helper_find(rtuple);
 	ip_conntrack_hash_insert(ct);
-
-	if (ct->helper)
-		ip_conntrack_helper_put(ct->helper);
+	add_timer(&ct->timeout);
+	write_unlock_bh(&ip_conntrack_lock);
 
 	DEBUGP("conntrack with id %u inserted\n", ct->id);
 	return 0;
Index: net-2.6/net/netfilter/nf_conntrack_netlink.c
===================================================================
--- net-2.6.orig/net/netfilter/nf_conntrack_netlink.c	2006-07-07 00:15:14.000000000 +0200
+++ net-2.6/net/netfilter/nf_conntrack_netlink.c	2006-07-07 01:52:32.000000000 +0200
@@ -1079,8 +1079,12 @@ ctnetlink_create_conntrack(struct nfattr
 		ct->mark = ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_MARK-1]));
 #endif
 
-	add_timer(&ct->timeout);
+	/* we do no want any races on hash insertion */
+	write_lock_bh(&nf_conntrack_lock);
+	ct->helper = nf_conntrack_helper_find(rtuple);
 	nf_conntrack_hash_insert(ct);
+	add_timer(&ct->timeout);
+	write_unlock_bh(&nf_conntrack_lock);
 
 	DEBUGP("conntrack with id %u inserted\n", ct->id);
 	return 0;

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

end of thread, other threads:[~2006-07-10  4:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-07  2:13 [PATCH 3/10][CTNETLINK] Fix race condition on conntrack creation Pablo Neira Ayuso
2006-07-07  4:45 ` Patrick McHardy
2006-07-07 12:51   ` Pablo Neira Ayuso
2006-07-10  4:31     ` Patrick McHardy

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.