Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp46924lqo; Thu, 9 May 2024 12:08:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXQxUokKZe7BZ+Q9QMX1IILtvlygvNVhQNsPs+oDOqX5lAXA7Y04VUSM9QOnkJ7v++0nvtCs70fEAbNNwKoCZbjjNXsLeqR6229vYzqCw== X-Google-Smtp-Source: AGHT+IEqIk+O/w2i0AO6oE6xQ1a1uPF4hmxj8fAZpBYFL/CK9hHuVbQ0B91IO1LQ5mXrz/GVQs7u X-Received: by 2002:a05:6512:3da1:b0:51f:1bf8:610c with SMTP id 2adb3069b0e04-5220fb77569mr368684e87.11.1715281684994; Thu, 09 May 2024 12:08:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715281684; cv=pass; d=google.com; s=arc-20160816; b=U7GQ2zuwH+y3hmU4em5yIqnOF5k58SgS8MdEZG8juOP+NFYqtUfusYIqXmVrY/SDWJ 7uXiC5pbXqJCPZKk4vEsc56prAj1m2y2avtgaoCZmYkYmcp4YhGXmnhZs2h1zZPptS7d GJaVggT7IKiwpBFEu9hu9oVVNf09LR2eyD76m47R5TRoJ2TesEmzFXI2F6eQ9rFMskdd KqthRnLlEZXuq2L8u1ZuscH3+E6z3h5eolNrhbdGkvYldH984ncA5T/zMo92AWl0fM5k SzZpIElgLwpKaDL9+FGoQGV/s+fJq2ZZCYSVn13eRFSsxPmavvKSURgzasPYSWfrvCBi bspA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=tww4Ddeatp59yRwNDk2ipeaPmVqICKWNDahWfPFhquU=; fh=0usr/oSitgdMzKU8bjbj++ibyXkA2shRvr0Dq7ofT8U=; b=nt+0A4AC0SBVXk6WBD0SmwYy+uDJQhPs9eQ8R4BLK+9NqMerDETPND2Av/LK6gNnyn 1bu1RTnMkghgVeh3Tfr1cMjwVPbCyrI0XPxYPbSiplJlAJipn5R+pBEhtO+ZTWyGgLY+ EjKuaof7Rdqji7Qy8CnG/ptlEQ9RRjRj5ETal8zu2pmfk1ZyBXcgHbxgKehxbNIHVYAB ZTw+abivqytSwrq7yNn1U4WpM7o72i/q5+/sVHemW/oWSMGNCTeq0hz4mZwI4+a9zaJJ w3lGtomPvtedWZ4CXIKKQ8tIDQdXMpIYkAMdut74pOQrwEoiqLiBFVQlVHnIbqbhsGT2 I8Cg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ao5qP9pj; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-174799-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174799-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c2c825si116353566b.1030.2024.05.09.12.08.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 12:08:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174799-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ao5qP9pj; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-174799-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174799-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B038D1F22BD8 for ; Thu, 9 May 2024 19:08:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AF557F484; Thu, 9 May 2024 19:07:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ao5qP9pj" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99F437E59A for ; Thu, 9 May 2024 19:07:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715281677; cv=none; b=H+4GsUAGQIlB6/gXeimx/1J1U+OW7UfBtVIYC57JGHgaofuiYnSIkrTZJOSQsrZYkg5MIkTADYAbvX2eQxh5e4i4RBua9pq81oLPfurImyKnkHOi7+2h81etjdHQ7LCqmSJLF4QLn5kWWYW61ZA+bZxG/htzbGooDE7ohI8AEiA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715281677; c=relaxed/simple; bh=+pWEJzXwwXVhUGCYVhqQW0Gh9E0v93VUDpXB1cBKXbw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=T3pRAaG8OIG2JTCuDP57vGlBY0Rarme2nJ9Ylb/d5gYAtU6vYtsTX7UKcq2EqCJHWjjnTWDr099iAy+yjEPdfbtHEzzP/ZcZJa4R7qpn5wdECPhoGHoQpw/fl8vgzCrKJ2iLXra8Sj0aHw5JWd51qfeiP2mQFburSpXq4MbnXk8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ao5qP9pj; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715281674; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tww4Ddeatp59yRwNDk2ipeaPmVqICKWNDahWfPFhquU=; b=Ao5qP9pjJFfQAcLhZDDdEbOCwRL4bwrZ4tcUPxMIxdsnDFyiBTvZh2LnjEpNSAMzydJALk /cT/mIU7bK63jt35lnymo0m1Ih1IhgGmRpJ9PqcFToDLD12uHjuuXKT4zsq9fq7gT1Ogt2 P6r5v6X+KyBebsfvOVVRAj2t2I2w37Y= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-224-5v9GxJXoMGGXEhR2EpBJow-1; Thu, 09 May 2024 15:07:51 -0400 X-MC-Unique: 5v9GxJXoMGGXEhR2EpBJow-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF4541C4C397; Thu, 9 May 2024 19:07:49 +0000 (UTC) Received: from RHTRH0061144 (unknown [10.22.10.50]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04776FA056; Thu, 9 May 2024 19:07:48 +0000 (UTC) From: Aaron Conole To: Ilya Maximets Cc: netdev@vger.kernel.org, dev@openvswitch.org, Antonin Bas , linux-kernel@vger.kernel.org, Eric Dumazet , Jakub Kicinski , Paolo Abeni , "David S. Miller" Subject: Re: [ovs-dev] [PATCH net] net: openvswitch: fix overwriting ct original tuple for ICMPv6 In-Reply-To: <20240509094228.1035477-1-i.maximets@ovn.org> (Ilya Maximets's message of "Thu, 9 May 2024 11:38:05 +0200") References: <20240509094228.1035477-1-i.maximets@ovn.org> Date: Thu, 09 May 2024 15:07:48 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Ilya Maximets writes: > OVS_PACKET_CMD_EXECUTE has 3 main attributes: > - OVS_PACKET_ATTR_KEY - Packet metadata in a netlink format. > - OVS_PACKET_ATTR_PACKET - Binary packet content. > - OVS_PACKET_ATTR_ACTIONS - Actions to execute on the packet. > > OVS_PACKET_ATTR_KEY is parsed first to populate sw_flow_key structure > with the metadata like conntrack state, input port, recirculation id, > etc. Then the packet itself gets parsed to populate the rest of the > keys from the packet headers. > > Whenever the packet parsing code starts parsing the ICMPv6 header, it > first zeroes out fields in the key corresponding to Neighbor Discovery > information even if it is not an ND packet. > > It is an 'ipv6.nd' field. However, the 'ipv6' is a union that shares > the space between 'nd' and 'ct_orig' that holds the original tuple > conntrack metadata parsed from the OVS_PACKET_ATTR_KEY. > > ND packets should not normally have conntrack state, so it's fine to > share the space, but normal ICMPv6 Echo packets or maybe other types of > ICMPv6 can have the state attached and it should not be overwritten. > > The issue results in all but the last 4 bytes of the destination > address being wiped from the original conntrack tuple leading to > incorrect packet matching and potentially executing wrong actions > in case this packet recirculates within the datapath or goes back > to userspace. > > ND fields should not be accessed in non-ND packets, so not clearing > them should be fine. Executing memset() only for actual ND packets to > avoid the issue. > > Initializing the whole thing before parsing is needed because ND packet > may not contain all the options. > > The issue only affects the OVS_PACKET_CMD_EXECUTE path and doesn't > affect packets entering OVS datapath from network interfaces, because > in this case CT metadata is populated from skb after the packet is > already parsed. > > Fixes: 9dd7f8907c37 ("openvswitch: Add original direction conntrack > tuple to sw_flow_key.") > Reported-by: Antonin Bas > Closes: https://github.com/openvswitch/ovs-issues/issues/327 > Signed-off-by: Ilya Maximets > --- Acked-by: Aaron Conole > Note: I'm working on a selftest for this issue, but it requires some > ground work first to add support for OVS_PACKET_CMD_EXECUTE into > opnevswitch selftests as well as parsing of ct tuples. So it is going > to be a separate patch set. I do have something already to do this for an issue in CMD_EXECUTE that I'm debugging (may be the same?). I can reply with my work off-list if you think it would be useful to you. > net/openvswitch/flow.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c > index 33b21a0c0548..8a848ce72e29 100644 > --- a/net/openvswitch/flow.c > +++ b/net/openvswitch/flow.c > @@ -561,7 +561,6 @@ static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key, > */ > key->tp.src = htons(icmp->icmp6_type); > key->tp.dst = htons(icmp->icmp6_code); > - memset(&key->ipv6.nd, 0, sizeof(key->ipv6.nd)); > > if (icmp->icmp6_code == 0 && > (icmp->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION || > @@ -570,6 +569,8 @@ static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key, > struct nd_msg *nd; > int offset; > > + memset(&key->ipv6.nd, 0, sizeof(key->ipv6.nd)); > + > /* In order to process neighbor discovery options, we need the > * entire packet. > */