From patchwork Thu Jul 23 14:15:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick McHardy X-Patchwork-Id: 30139 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 413F1B7089 for ; Fri, 24 Jul 2009 00:16:42 +1000 (EST) Received: by ozlabs.org (Postfix) id 3397DDDD0B; Fri, 24 Jul 2009 00:16:42 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 846D1DDD1C for ; Fri, 24 Jul 2009 00:16:41 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752780AbZGWOPa (ORCPT ); Thu, 23 Jul 2009 10:15:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752701AbZGWOP3 (ORCPT ); Thu, 23 Jul 2009 10:15:29 -0400 Received: from stinky.trash.net ([213.144.137.162]:39713 "EHLO stinky.trash.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752036AbZGWOP1 (ORCPT ); Thu, 23 Jul 2009 10:15:27 -0400 Received: from x2.localnet (localhost [127.0.0.1]) by stinky.trash.net (Postfix) with ESMTP id 48CBCB2C54; Thu, 23 Jul 2009 16:15:27 +0200 (MEST) From: Patrick McHardy To: stable@kernel.org Cc: netdev@vger.kernel.org, Patrick McHardy , netfilter-devel@vger.kernel.org Message-Id: <20090723141526.19029.4804.sendpatchset@x2.localnet> In-Reply-To: <20090723141523.19029.89290.sendpatchset@x2.localnet> References: <20090723141523.19029.89290.sendpatchset@x2.localnet> Subject: netfilter -stable 02/08: nf_conntrack: fix confirmation race condition Date: Thu, 23 Jul 2009 16:15:27 +0200 (MEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org commit 0293f8bc787be0f6a0ff9dba877c2f87f43dc60f Author: Patrick McHardy Date: Fri Jul 3 10:33:04 2009 +0200 netfilter: nf_conntrack: fix confirmation race condition Upstream commit 5c8ec910: 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 --- 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 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 8020db6..c8bd559 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -385,7 +385,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. */ @@ -393,8 +392,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);