From patchwork Sun Jul 28 20:54:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick McHardy X-Patchwork-Id: 262620 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3158F2C012C for ; Mon, 29 Jul 2013 07:02:47 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751452Ab3G1VCo (ORCPT ); Sun, 28 Jul 2013 17:02:44 -0400 Received: from stinky.trash.net ([213.144.137.162]:45250 "EHLO stinky.trash.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751453Ab3G1VCn (ORCPT ); Sun, 28 Jul 2013 17:02:43 -0400 Received: from macbook.localnet (unknown [127.0.0.1]) by stinky.trash.net (Postfix) with ESMTP id 3BC409D2E0; Sun, 28 Jul 2013 22:54:19 +0200 (MEST) From: Patrick McHardy To: pablo@netfilter.org Cc: netfilter-devel@vger.kernel.org Subject: [PATCH 3/5] netfilter: nf_nat: fix locking in nf_nat_seq_adjust() Date: Sun, 28 Jul 2013 22:54:09 +0200 Message-Id: <1375044851-12471-4-git-send-email-kaber@trash.net> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1375044851-12471-1-git-send-email-kaber@trash.net> References: <1375044851-12471-1-git-send-email-kaber@trash.net> Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org nf_nat_seq_adjust() needs to grab nf_nat_setofs_lock to protect against concurrent changes to the sequence adjustment data. Signed-off-by: Patrick McHardy --- net/netfilter/nf_nat_helper.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nf_nat_helper.c b/net/netfilter/nf_nat_helper.c index 85e20a9..a7262ed 100644 --- a/net/netfilter/nf_nat_helper.c +++ b/net/netfilter/nf_nat_helper.c @@ -373,6 +373,7 @@ nf_nat_seq_adjust(struct sk_buff *skb, s16 seqoff, ackoff; struct nf_conn_nat *nat = nfct_nat(ct); struct nf_nat_seq *this_way, *other_way; + int res; dir = CTINFO2DIR(ctinfo); @@ -383,6 +384,7 @@ nf_nat_seq_adjust(struct sk_buff *skb, return 0; tcph = (void *)skb->data + protoff; + spin_lock_bh(&nf_nat_seqofs_lock); if (after(ntohl(tcph->seq), this_way->correction_pos)) seqoff = this_way->offset_after; else @@ -407,7 +409,10 @@ nf_nat_seq_adjust(struct sk_buff *skb, tcph->seq = newseq; tcph->ack_seq = newack; - return nf_nat_sack_adjust(skb, protoff, tcph, ct, ctinfo); + res = nf_nat_sack_adjust(skb, protoff, tcph, ct, ctinfo); + spin_unlock_bh(&nf_nat_seqofs_lock); + + return res; } /* Setup NAT on this expected conntrack so it follows master. */