diff options
author | Patrick McHardy <kaber@trash.net> | 2009-06-22 14:14:16 +0200 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2009-06-22 14:14:16 +0200 |
commit | 5c8ec910e789a92229978d8fd1fce7b62e8ac711 (patch) | |
tree | d24884793a0804bf2f96afac2248189b358b8ae2 /net | |
parent | 8cc20198cfccd06cef705c14fd50bde603e2e306 (diff) | |
download | kernel_samsung_tuna-5c8ec910e789a92229978d8fd1fce7b62e8ac711.zip kernel_samsung_tuna-5c8ec910e789a92229978d8fd1fce7b62e8ac711.tar.gz kernel_samsung_tuna-5c8ec910e789a92229978d8fd1fce7b62e8ac711.tar.bz2 |
netfilter: nf_conntrack: fix confirmation race condition
New connection tracking entries are inserted into the hash before they
are fully set up, namely the CONFIRMED bit is not set and the timer not
started yet. This can theoretically lead to a race with timer, which
would set the timeout value to a relative value, most likely already in
the past.
Perform hash insertion as the final step to fix this.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/netfilter/nf_conntrack_core.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 5276a2d..b0b06c7 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -425,7 +425,6 @@ __nf_conntrack_confirm(struct sk_buff *skb) /* Remove from unconfirmed list */ hlist_nulls_del_rcu(&ct->tuplehash[IP_CT_DIR_ORIGINAL].hnnode); - __nf_conntrack_hash_insert(ct, hash, repl_hash); /* Timer relative to confirmation time, not original setting time, otherwise we'd get timer wrap in weird delay cases. */ @@ -433,8 +432,16 @@ __nf_conntrack_confirm(struct sk_buff *skb) add_timer(&ct->timeout); atomic_inc(&ct->ct_general.use); set_bit(IPS_CONFIRMED_BIT, &ct->status); + + /* Since the lookup is lockless, hash insertion must be done after + * starting the timer and setting the CONFIRMED bit. The RCU barriers + * guarantee that no other CPU can find the conntrack before the above + * stores are visible. + */ + __nf_conntrack_hash_insert(ct, hash, repl_hash); NF_CT_STAT_INC(net, insert); spin_unlock_bh(&nf_conntrack_lock); + help = nfct_help(ct); if (help && help->helper) nf_conntrack_event_cache(IPCT_HELPER, ct); |