Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp633326iog; Mon, 13 Jun 2022 09:32:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uTvDa6OoZ/kfLfJN09KRwz1Gg3vGXApUun5WKwrJMlEYdbMuy4wLUHL3nYUZ93OWRYrC/1 X-Received: by 2002:a17:90b:4b05:b0:1e4:2964:b261 with SMTP id lx5-20020a17090b4b0500b001e42964b261mr597786pjb.205.1655137972923; Mon, 13 Jun 2022 09:32:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655137972; cv=none; d=google.com; s=arc-20160816; b=X6V3qLHF6gKXaFUhMVfyPf4fxQYWlSgoq3AQ4xFhoZ6PHL+Rb3IaTCfPSTN+1XF89T bHQJxws5SlSFkU1eR53U8VUKGBORlvz8Xc8+L3cpeEtqUWL5YM2xLjI4F2He0KeJZnwI FLWRvWa72irJRzG6HeU6iQeETS5kxnqqVw8LUQKEvs6jKQdtXXX4Yw02xR28bjOAg4Y0 /aoBjtkFsoN/cZzioJ4TK6S7S6gysdNkf/S9fFZLRF6xEQTTgKXd3FDWU9og6QXohXet 7iUQ3GbWKUrRyjycSUXoJx+qAO2T09Gx9WRUuhdje+MXoSF1hdOrgRASHb9A2/BRZ1IK w3pA== 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=Yj3CI7wLwQIvY/HnbLAsQBy9WdzZk4DvR0dOUJlbeI0=; b=IWYt8nbyqVu5y+pHNYeagHGTXRl8vXyy7JlBr4ESufHzAq+dPhxnH/yVHmA/gvTtgU BPVmc4CtEl6OLxhjcGEb8UPkNPRPo/s0Dwzaf1+n2CDYmN+2hdPC/RjZ0L2kErp66et3 lsAuTfh6sw8/2LQaQCSTmix79IQMO8Z3JfOTj2H/zH1bGsMAC2/YxcdLRoo12SMAZyZo /AuKZ+1M7BOz28czqKP0mu/hzEvgAGhygA8Pu1oEMlSm61Qy4h3JjVkzcqgFZ7cg+aS+ ovGojEyIc+MaHZfAmn/5NyqISkQWcqEMSdws9LHTT5+By8c6MDut3GX95B7Sj32P30Dm h58g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JmB7736e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a17090a2a0d00b001e84ad1f823si13223752pjd.107.2022.06.13.09.32.39; Mon, 13 Jun 2022 09:32:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JmB7736e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380906AbiFMOHH (ORCPT + 99 others); Mon, 13 Jun 2022 10:07:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380286AbiFMOAC (ORCPT ); Mon, 13 Jun 2022 10:00:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC858D6BA; Mon, 13 Jun 2022 04:38:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0D7B7B80ECD; Mon, 13 Jun 2022 11:38:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D1D0C34114; Mon, 13 Jun 2022 11:37:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655120278; bh=va27Whq9MlqmSQeciQ1mgy6bmhWVQAuq24GMVFNoUUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JmB7736erJ7Ed5bGWwxeQSuLDL8iSNjFmOlJvjbS8y7w/jjvH3+KUkKLub3Zp05KO i7r3oNZv2El1dRwtkH4w8L2JzD6RX9TTg5FMJKQ44gfmvCD0rbtD/bWgG+ECYNLSAc 5HzYFS6gA3YwkFQxx+0p1OGwaYCDb5WWuF5QsfFc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Frode Nordahl , Ilya Maximets , Jakub Kicinski Subject: [PATCH 5.18 315/339] net: openvswitch: fix misuse of the cached connection on tuple changes Date: Mon, 13 Jun 2022 12:12:20 +0200 Message-Id: <20220613094936.303552729@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094926.497929857@linuxfoundation.org> References: <20220613094926.497929857@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilya Maximets commit 2061ecfdf2350994e5b61c43e50e98a7a70e95ee upstream. If packet headers changed, the cached nfct is no longer relevant for the packet and attempt to re-use it leads to the incorrect packet classification. This issue is causing broken connectivity in OpenStack deployments with OVS/OVN due to hairpin traffic being unexpectedly dropped. The setup has datapath flows with several conntrack actions and tuple changes between them: actions:ct(commit,zone=8,mark=0/0x1,nat(src)), set(eth(src=00:00:00:00:00:01,dst=00:00:00:00:00:06)), set(ipv4(src=172.18.2.10,dst=192.168.100.6,ttl=62)), ct(zone=8),recirc(0x4) After the first ct() action the packet headers are almost fully re-written. The next ct() tries to re-use the existing nfct entry and marks the packet as invalid, so it gets dropped later in the pipeline. Clearing the cached conntrack entry whenever packet tuple is changed to avoid the issue. The flow key should not be cleared though, because we should still be able to match on the ct_state if the recirculation happens after the tuple change but before the next ct() action. Cc: stable@vger.kernel.org Fixes: 7f8a436eaa2c ("openvswitch: Add conntrack action") Reported-by: Frode Nordahl Link: https://mail.openvswitch.org/pipermail/ovs-discuss/2022-May/051829.html Link: https://bugs.launchpad.net/ubuntu/+source/ovn/+bug/1967856 Signed-off-by: Ilya Maximets Link: https://lore.kernel.org/r/20220606221140.488984-1-i.maximets@ovn.org Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/openvswitch/actions.c | 6 ++++++ net/openvswitch/conntrack.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -373,6 +373,7 @@ static void set_ip_addr(struct sk_buff * update_ip_l4_checksum(skb, nh, *addr, new_addr); csum_replace4(&nh->check, *addr, new_addr); skb_clear_hash(skb); + ovs_ct_clear(skb, NULL); *addr = new_addr; } @@ -420,6 +421,7 @@ static void set_ipv6_addr(struct sk_buff update_ipv6_checksum(skb, l4_proto, addr, new_addr); skb_clear_hash(skb); + ovs_ct_clear(skb, NULL); memcpy(addr, new_addr, sizeof(__be32[4])); } @@ -660,6 +662,7 @@ static int set_nsh(struct sk_buff *skb, static void set_tp_port(struct sk_buff *skb, __be16 *port, __be16 new_port, __sum16 *check) { + ovs_ct_clear(skb, NULL); inet_proto_csum_replace2(check, skb, *port, new_port, false); *port = new_port; } @@ -699,6 +702,7 @@ static int set_udp(struct sk_buff *skb, uh->dest = dst; flow_key->tp.src = src; flow_key->tp.dst = dst; + ovs_ct_clear(skb, NULL); } skb_clear_hash(skb); @@ -761,6 +765,8 @@ static int set_sctp(struct sk_buff *skb, sh->checksum = old_csum ^ old_correct_csum ^ new_csum; skb_clear_hash(skb); + ovs_ct_clear(skb, NULL); + flow_key->tp.src = sh->source; flow_key->tp.dst = sh->dest; --- a/net/openvswitch/conntrack.c +++ b/net/openvswitch/conntrack.c @@ -1342,7 +1342,9 @@ int ovs_ct_clear(struct sk_buff *skb, st nf_ct_put(ct); nf_ct_set(skb, NULL, IP_CT_UNTRACKED); - ovs_ct_fill_key(skb, key, false); + + if (key) + ovs_ct_fill_key(skb, key, false); return 0; }