From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Netfilter Development Mailinglist <netfilter-devel@lists.netfilter.org>
Cc: Patrick McHardy <kaber@trash.net>
Subject: [PATCH 3/10][CTNETLINK] Fix race condition on conntrack creation
Date: Fri, 07 Jul 2006 04:13:10 +0200 [thread overview]
Message-ID: <44ADC336.1060004@netfilter.org> (raw)
[-- 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;
next reply other threads:[~2006-07-07 2:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-07 2:13 Pablo Neira Ayuso [this message]
2006-07-07 4:45 ` [PATCH 3/10][CTNETLINK] Fix race condition on conntrack creation Patrick McHardy
2006-07-07 12:51 ` Pablo Neira Ayuso
2006-07-10 4:31 ` Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44ADC336.1060004@netfilter.org \
--to=pablo@netfilter.org \
--cc=kaber@trash.net \
--cc=netfilter-devel@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.