Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4408171pxu; Mon, 12 Oct 2020 19:20:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhnTgXG6C/jgS/0m6QZ/+QDznFxEjVYZGw9MfidDZIpDHtrvAsFX2g+y4YaWFQfe0SxnY3 X-Received: by 2002:aa7:ca52:: with SMTP id j18mr16869175edt.147.1602555603546; Mon, 12 Oct 2020 19:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602555603; cv=none; d=google.com; s=arc-20160816; b=LDazbNF634bINqu83mbwrqb9gg7XeSG+nApPbJ7KqSJSJ3pdfLtnMoFtXVScQEqRAl wZQgMYCE/Udr4umSYguxSKM5aeM2jI29eDkUvTKLlXkV6svcduXxUz+xKRUwonEV6jSB Sbw1tcO+c7RFylnibOULDfn/qsg/90gvsJ5netEGHAOpI+cMVotPaceoAMk3ZS13NP6k 0PfOP0LPplAAG7TEytvyv0wDvZYPvTAQJKf54VIHxCWXOL6Db9o0oxd4LQDIVHxnBvW7 TXAMbNsBFddUSg90hvmzmjA4DIYWkDC13SaBpJkUTj+c55INRjnRZfDugdosdPHaqBjj 8zjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=a0gy78loLJjRmdEJ/85eQcb5vUYgqPgXw7SmlqmFkaw=; b=ORz6T22kj91K3NlOT/UTn4y62wl5egtWnmt6LK+uxWoqX64HeR1gReqpjZ1JUAOW+t +1Ib32NcRhnNtkkG3MzdKrXuUa62mUxLEV3B2SHrA6rXj0N/R1Q4VRMoSi0o91xhRK/8 HbeEtsVrp9ctfIJlESxrAehOk1WSjCRlEoVK97XtKZg0Ubypq3HnIX/HMxwBfAVgrFgk UwU5qJ6nun8zj5A1Iin0Ne+dAfuOjF8f9wNLwZn43wwAnOVCq0igT8CHEAj1wlfVI3oH LaOOIVWJCeLJMjBBSvgOAfYy2sy17jc3gSuG8cc9ldaGH6vEdTQS/I4efSX0WbsuPpWH nX8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="bq/+DQ30"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mb2si13646186ejb.352.2020.10.12.19.19.41; Mon, 12 Oct 2020 19:20:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="bq/+DQ30"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731520AbgJLOBn (ORCPT + 99 others); Mon, 12 Oct 2020 10:01:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:41546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731110AbgJLNiJ (ORCPT ); Mon, 12 Oct 2020 09:38:09 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 71A842076E; Mon, 12 Oct 2020 13:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602509889; bh=sfmSy6LL+4tYSFoOlPoeeJAW9zmQoNn7F0wsq8ijnvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bq/+DQ30r9/sP2S0S3hVOyQPbKoOtl6it5SHzUrScpu11hEfOabIbPLo0EhukzLsS XjCXPosnDJ1umVrTbmXIkFaQ6X8/6MZzxERYNUs8qE4o4ejM1+eL6S8H/9qpfbjr7w fduUeRYXKeryPZ9idwypaN+G4U8dk4ozGvorlzd4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Westphal , Dumitru Ceara , Jakub Kicinski Subject: [PATCH 4.14 52/70] openvswitch: handle DNAT tuple collision Date: Mon, 12 Oct 2020 15:27:08 +0200 Message-Id: <20201012132632.684171967@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132630.201442517@linuxfoundation.org> References: <20201012132630.201442517@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dumitru Ceara commit 8aa7b526dc0b5dbf40c1b834d76a667ad672a410 upstream. With multiple DNAT rules it's possible that after destination translation the resulting tuples collide. For example, two openvswitch flows: nw_dst=10.0.0.10,tp_dst=10, actions=ct(commit,table=2,nat(dst=20.0.0.1:20)) nw_dst=10.0.0.20,tp_dst=10, actions=ct(commit,table=2,nat(dst=20.0.0.1:20)) Assuming two TCP clients initiating the following connections: 10.0.0.10:5000->10.0.0.10:10 10.0.0.10:5000->10.0.0.20:10 Both tuples would translate to 10.0.0.10:5000->20.0.0.1:20 causing nf_conntrack_confirm() to fail because of tuple collision. Netfilter handles this case by allocating a null binding for SNAT at egress by default. Perform the same operation in openvswitch for DNAT if no explicit SNAT is requested by the user and allocate a null binding for SNAT for packets in the "original" direction. Reported-at: https://bugzilla.redhat.com/1877128 Suggested-by: Florian Westphal Fixes: 05752523e565 ("openvswitch: Interface with NAT.") Signed-off-by: Dumitru Ceara Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/openvswitch/conntrack.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/net/openvswitch/conntrack.c +++ b/net/openvswitch/conntrack.c @@ -881,15 +881,19 @@ static int ovs_ct_nat(struct net *net, s } err = ovs_ct_nat_execute(skb, ct, ctinfo, &info->range, maniptype); - if (err == NF_ACCEPT && - ct->status & IPS_SRC_NAT && ct->status & IPS_DST_NAT) { - if (maniptype == NF_NAT_MANIP_SRC) - maniptype = NF_NAT_MANIP_DST; - else - maniptype = NF_NAT_MANIP_SRC; + if (err == NF_ACCEPT && ct->status & IPS_DST_NAT) { + if (ct->status & IPS_SRC_NAT) { + if (maniptype == NF_NAT_MANIP_SRC) + maniptype = NF_NAT_MANIP_DST; + else + maniptype = NF_NAT_MANIP_SRC; - err = ovs_ct_nat_execute(skb, ct, ctinfo, &info->range, - maniptype); + err = ovs_ct_nat_execute(skb, ct, ctinfo, &info->range, + maniptype); + } else if (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL) { + err = ovs_ct_nat_execute(skb, ct, ctinfo, NULL, + NF_NAT_MANIP_SRC); + } } /* Mark NAT done if successful and update the flow key. */