Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3995889pxu; Mon, 12 Oct 2020 06:58:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvVRYACRLtuvAmspi5d3evR7nPVSiaY8W+rxwoyezWRXIi+nhj6ci1bAFicRDtABn6TGVl X-Received: by 2002:aa7:c54f:: with SMTP id s15mr14544740edr.107.1602511102846; Mon, 12 Oct 2020 06:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602511102; cv=none; d=google.com; s=arc-20160816; b=rQcpZ9zjTnSW573qnX9sIn7f4Z70S+VlpEgJ0U1ew+B4Hu4ASEAdgz2MTqOUR76AKq GMVg6iuxPLY7ori4YIPzfmDXsDitVZfCacj2o707tlDxHgtWUaxed6WbjmQFoMMUmJ76 q9hWY52CA5HLAHVevlCfGqM/ovGX7kFh3NoVvPxFMUfq4jp6/JOzepRvWKOqlunoxzhi jiR+znckIEYOooXgCnRgwMHJ0WsvcqU5Saeo1afolVKXcP85Qunxnd3jKPpulv7V8I+U nZiy8BNqf0dZR3H1Yo+EWC2bTcimJhI9uqEpkoLsrYMWCRAvtJ0vTsil29lEnifZdVrl UkXA== 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=ciIHF2DHRm5NdhCPIPYZVDP9yoDL+bW6sd4yr7Mjadc=; b=dyNZ6tQHbrIWtPSRoX3FpXpXeHQs7oLsKewjaBqUFiqIpn8wlxWicuARWO7fAGFKLH yUyAL/mB3uvZXmXgMCiaOcDssie8tzD8qJtxT3D1Qtz1EwTLBVs8SvnH/P2hN8Fy1zob irv8GvQ3VWdwPmouuOEIZu+so/VUjeWGzj9x4eze6KNxwVoqyCLZn/tjopNmjPeJ53Zj /kMLLxlldukw8NbV3RSyuJvJ1KOrSjAX//UhzkIzunRmeV3sM48o07ydlakxMpP4A2lT beFIGwHiPtOQ8Zs/dTQN806Wq2H1pS10lRwpICvId1L3oavMOxdNfAZYH3cA9zmismX/ aeEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2NCQAwUW; 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 n13si11936551eji.447.2020.10.12.06.58.00; Mon, 12 Oct 2020 06:58:22 -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=2NCQAwUW; 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 S2390327AbgJLNyJ (ORCPT + 99 others); Mon, 12 Oct 2020 09:54:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:47942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389748AbgJLNpy (ORCPT ); Mon, 12 Oct 2020 09:45:54 -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 06B97222EA; Mon, 12 Oct 2020 13:45:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510310; bh=BH12WriJ2R29/28OzkXlvaTGX8CcnD6kK+lU8IlAUlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2NCQAwUWBD6kRxDLZB3SsGVwPxv6Ylj4gV/ayq6WTeb1+/9KNR3OBbT0B/adAYt0U RG+Y0Y8WArxs/edGgmbeLPv4zOQaggs8Yalt1Gu1NwMNiUQWFXgLjxsX4WOqqT7p5d otzKJ4tmYb6SdqfoS8YP4Pdu5KhbSw80Ng+kBdvw= 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 5.8 044/124] openvswitch: handle DNAT tuple collision Date: Mon, 12 Oct 2020 15:30:48 +0200 Message-Id: <20201012133148.988672271@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012133146.834528783@linuxfoundation.org> References: <20201012133146.834528783@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 @@ -903,15 +903,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. */