Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4005680pxu; Mon, 12 Oct 2020 07:10:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTP0naI7WA0gLW5vLgD0AgO61PpKNKTCUiJ9jbs0Scw+/1q3a23EZS7t6ep/hf96JBBNz6 X-Received: by 2002:a17:907:43c6:: with SMTP id i6mr2942798ejs.207.1602511837973; Mon, 12 Oct 2020 07:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602511837; cv=none; d=google.com; s=arc-20160816; b=Crj3TphmF0JuCHZ4ioFuF7H/Y9wveOpdDvBgUQTWH5gsZAnsLg431qH1jgUw47Cg8y O9h6TX4+Of0B00WJSMXkMtLqJFzpBDRoeiLJxzSwBiGHaa3HmbfP52AfgakfQpQAVLzp 1VArnQjWRWocdMvl7hb3hnkhXMBfAiCv77krqI0UAKTwhzaahhw0TtskQi/SyOIvLHEu 2ujJ4O8kdtXlbgGNnSXtm4pPUFUsxOhJKmTfG+0HkwNIVW/OgZ2c6NpJ0GyP6byPgKNr p8K1FhqmL909jR1GU0GMqS8/dW4Q2Rr13xCIASu0krCq8xZrObdY8+SqI51J+sS0YN3B g3Tg== 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=w1x+4D4eJPg9AK/I9J4MaZW+9Q9YoTXF7AHnNEdonIE=; b=nehgnEv0/OGb+mkpmYLu9UnGBtPRNWAgs54Egng7qCebXjOI4TBZ28vnTiySHBgWSS zTzXwLzPSXQsGTug6H3blBbxtYpZtECXoY5GBCyAlVQnTrlTH0Al2wVdbUXNaA8mm4PB L+E8ucXD01VnKA6sGdPiv2S2ubQxMQKjmsZ3D90iIl/+sV/CcRDkNN9Mnw/kmSyGHFZB vTsR37Tp1LohLrLLvWRo7liVRLbx+6V2tZvKG1o5Bsq3rCX8z5MYSg8/1vw7rE1ZmEGk g9CC6amM6mOh//r1UPltd/zoiNnYFfQFnjWmSYmPrxOPbzQQl7xNRSzZQOCx4DCeMBP7 YusQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KLm82e86; 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 z13si8935271ejf.718.2020.10.12.07.10.13; Mon, 12 Oct 2020 07:10:37 -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=KLm82e86; 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 S2391097AbgJLOGJ (ORCPT + 99 others); Mon, 12 Oct 2020 10:06:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:36796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730709AbgJLNeo (ORCPT ); Mon, 12 Oct 2020 09:34:44 -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 B4036215A4; Mon, 12 Oct 2020 13:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602509684; bh=8eEq4KYRpIi3cl/1hrvJIiVsf5tQ2gQ54ewuc+GUgO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KLm82e86TI5Hk1ciDigXJT6GkTC9JB1BEIrDcRrAMQ+OXTNfTOPjsfpd6g+ozZegi o/K5whPdjaPeSfAgYzvrCXO9RxlbPSfyBg0GVFy2TMzhlU7nyh+yLuyZ4PRYpoA6Hk FiMBKkSwRdNgrwVk7yzQA82J/7X+9LY9faBnWaBo= 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.9 40/54] openvswitch: handle DNAT tuple collision Date: Mon, 12 Oct 2020 15:27:02 +0200 Message-Id: <20201012132631.436683076@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132629.585664421@linuxfoundation.org> References: <20201012132629.585664421@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 @@ -709,15 +709,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. */