Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp1032850lqo; Thu, 9 May 2024 02:44:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVAijFkkoNLQnDFtVRfkIVAyyCZSR6DFUfOjnWCW1koArfvTPi8FfMoK8fz5+GzcVvfrtpJVNXyaaoLxyShU68Z+QD127R50InvJccSkQ== X-Google-Smtp-Source: AGHT+IGElz3ifRayVagGeZfsCDcu0Sac9/ZZns/KuHQX64uAYGRepwGMeiLixbMC8C1DLUsaWnDY X-Received: by 2002:a17:902:db06:b0:1e3:cfc5:589e with SMTP id d9443c01a7336-1eeb07973e4mr64935395ad.64.1715247861773; Thu, 09 May 2024 02:44:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715247861; cv=pass; d=google.com; s=arc-20160816; b=eUutpSjkg+qTQtTx3gLe+CanqSVLEwR2WaoqY90EoWWBd6z5n5cp+MgEX2uaVazFnz S+Xvo5Jk5Rck10akQi9KiBl/tc1eBDRmlO4EhK9zd0VZBzmo5hsJWMs5jHHvLY07KT1s tSzOPvtOSKIGLrQxx13YowX6jmcNaCNW7ggdanpw5nZmQWCY8tDPm8KVZ3apIEAzOfLP jmVMeR0eJl2O+EF2XRqsAJh/o+s1BeYaHpZkS2txZiHST78+EpYD4+WP7eviXidHw2m/ 3KP01751a0dY77DIkM/stlk+qJERt9V3lsEKm1HsQ6W+eKNASvH49tibYz9iVy8hX8VY zIHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=qtjvGxfszCBphffrlETWXd0SmDdU4bL9w4HZvgxRF7Q=; fh=ycN8cz2/pLZBImIB0dLvor9wwUJ/Dzp5CZR4VmTHV/0=; b=oTJPpRMMJu/7ETJNzhyOE96nyT4OLSGK63pZqKMDWK0h5mcXYqhC9mgR/111bAuesN qN+m+AP2D7PQATOcoFs/p3P6za9dP1DKyoFibYlX/LoNVO+uHCbtQE+3EX4NpVjcoIsf 9cNXUw0m7QzHSETmNwY3GS4WD/6cr/RO7Vr5W/BlPcdd7UJ8MPU2aCMhZIoN1QBISp+r TGUoySNCBb5chktcuApuysRKjReJKIrOy3hxDVOBcOpAPMGKtTSXeuOm+n+q+JujuAtb 91dRcvUAHmMYiXA7dubWnQYhXg7Ta5hzdtY4ntNHXfMt+cUvMmYc8ER7xvHiosUeb9yT AH6w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=ovn.org); spf=pass (google.com: domain of linux-kernel+bounces-174362-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174362-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c15a44csi10982345ad.471.2024.05.09.02.44.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 02:44:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174362-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ovn.org); spf=pass (google.com: domain of linux-kernel+bounces-174362-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174362-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 52299B222E2 for ; Thu, 9 May 2024 09:42:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7454F14AD0E; Thu, 9 May 2024 09:42:03 +0000 (UTC) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 55E1F14A61E; Thu, 9 May 2024 09:41:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715247723; cv=none; b=YkED3UoH9Crv4WtJrfsrBwk8Nss8a1O/A7pgOvs8DJ331EFnyhsSx3MzVKMiUfXIqVZoSP2eFiNcnQLqZjGhBG4H3InVGvTZnrtrz5i1wGpviYuHsUUnOsj/ZuY04wTtQ80EnZzXjARmbLRCwBIsZ1z/Nk8BVV6pZpf7MEkwaUs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715247723; c=relaxed/simple; bh=TNe1rMP+ypl47hsJ4a40gMpHW3BIzrJt/nOYekkuWXQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZbaP81L7NX8TeHKyUXEWE3drm0JUy6b8W1JxQ/ftYB0gZuwHFrAYJS1wSjYuVxHH90shx9iHmJIwHT0rYDLCdCjDX+LfQDPVYWDsL3ITkE3WmF49sfVBqsjrN+3v9PeT4m6774jX8vS8PtUxb3AWZwyuiqU3f7Izx+iwQuv6x/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ovn.org; spf=pass smtp.mailfrom=ovn.org; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ovn.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ovn.org Received: by mail.gandi.net (Postfix) with ESMTPSA id 7FE32FF804; Thu, 9 May 2024 09:41:55 +0000 (UTC) From: Ilya Maximets To: netdev@vger.kernel.org Cc: Pravin B Shelar , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Joe Stringer , Jarno Rajahalme , dev@openvswitch.org, linux-kernel@vger.kernel.org, Ilya Maximets , Antonin Bas Subject: [PATCH net] net: openvswitch: fix overwriting ct original tuple for ICMPv6 Date: Thu, 9 May 2024 11:38:05 +0200 Message-ID: <20240509094228.1035477-1-i.maximets@ovn.org> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: i.maximets@ovn.org 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 --- 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. 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. */ -- 2.44.0