Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2292455pxb; Mon, 11 Jan 2021 06:13:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPSvNFO2FiMakEoIcNG0lEy+vAhp/4/oZEFaKWtCL5YzYrf4nd2BCDR6ncCn8h7TWeYSdw X-Received: by 2002:a17:906:3094:: with SMTP id 20mr10744963ejv.218.1610374390173; Mon, 11 Jan 2021 06:13:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610374390; cv=none; d=google.com; s=arc-20160816; b=eSU4rx2UGKXvAAshkC13gnQHrJjFcVgwEWdRTImk/imKr7Tq7FKL8l7rd96mkVcg/S KEXYg322VFvhgkPYAccbykxTh/ay4Nrkvm9RP7wJ5PXsMky0OZzeyquhKi3BDVjSonUU YBXWqK2DMoK1egvhSQSQt5l4+6KcAuAYvsNh7QhFt/5GRH2nxcuFP+9GXYXRnBiivqhL m8fxC0U33tKBofZQbDa8M0zlxVT6IhnYHV/qg8pexoJe02TErAYO2ZloKI9y/CXeiJR7 gBm+yHysEScr3Afchfpa3KdWDuNAoJ0Y9Wb7NRGO++dSAMHOQLa0sZbOk0WOmN4YvyPr yGwA== 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=/WWxG8A7mRm7ND+WYv0t18xPdCEDqAxMBLh1hrtA/pI=; b=kyythblP74uD7KVna+jjU42Qbiwpb3J2gku/D3VkRQs39kh7bkNPB8rmM/YKxB3htg iaXUlRxci3n6bQWZHcZLgbEF0yaLjc24FG/mITlv1mB/Rtwgjr1Iwuv8rBdD5amogQsW /rRpsleSeyrKztMO1jP8uQmBJLtCiqLe48ilPhGhAPx/V3CBf9ZvtZUT/5PJnyDIhd/s Gai5FslAywEMBCh+Yai80nUL5RSpkzrac2Bx6g7QMMt8deui0wYD3Wn5NJh9vReVJQv5 Lk2LRS6q9WfUJXRJ3qax7E2ROl7/nlU/eHaVXcjHwZbGmQL4j5VR59Cgp48Zc395QpA6 PCLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ph5LtIq0; 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=pass (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 en9si6498175ejb.519.2021.01.11.06.12.44; Mon, 11 Jan 2021 06:13:10 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=ph5LtIq0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730528AbhAKOJS (ORCPT + 99 others); Mon, 11 Jan 2021 09:09:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:50204 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729847AbhAKND3 (ORCPT ); Mon, 11 Jan 2021 08:03:29 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6F0C822AAF; Mon, 11 Jan 2021 13:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370173; bh=c0KachQ6QPtQ2YGOd7GrCsXbBmZMFNbVkZPOBmcsxXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ph5LtIq01eoyAJIfWdAtDQfugFzhl0KdoFz3EollULv9Xmxyig0hKjUEZkJ7LY6x8 PCFTko2D9Ryc7fzcmWEVZYUMulOcUP4v2e/MVLX8o2jko+GkmehbCePx1PQC2FTjbT s2i+ZBrx0UBu4X4W9r1vxG2GH7Oa/fe7VtNeMEGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Nault , "David S. Miller" Subject: [PATCH 4.9 10/45] ipv4: Ignore ECN bits for fib lookups in fib_compute_spec_dst() Date: Mon, 11 Jan 2021 14:00:48 +0100 Message-Id: <20210111130034.158968081@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130033.676306636@linuxfoundation.org> References: <20210111130033.676306636@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: Guillaume Nault [ Upstream commit 21fdca22eb7df2a1e194b8adb812ce370748b733 ] RT_TOS() only clears one of the ECN bits. Therefore, when fib_compute_spec_dst() resorts to a fib lookup, it can return different results depending on the value of the second ECN bit. For example, ECT(0) and ECT(1) packets could be treated differently. $ ip netns add ns0 $ ip netns add ns1 $ ip link add name veth01 netns ns0 type veth peer name veth10 netns ns1 $ ip -netns ns0 link set dev lo up $ ip -netns ns1 link set dev lo up $ ip -netns ns0 link set dev veth01 up $ ip -netns ns1 link set dev veth10 up $ ip -netns ns0 address add 192.0.2.10/24 dev veth01 $ ip -netns ns1 address add 192.0.2.11/24 dev veth10 $ ip -netns ns1 address add 192.0.2.21/32 dev lo $ ip -netns ns1 route add 192.0.2.10/32 tos 4 dev veth10 src 192.0.2.21 $ ip netns exec ns1 sysctl -wq net.ipv4.icmp_echo_ignore_broadcasts=0 With TOS 4 and ECT(1), ns1 replies using source address 192.0.2.21 (ping uses -Q to set all TOS and ECN bits): $ ip netns exec ns0 ping -c 1 -b -Q 5 192.0.2.255 [...] 64 bytes from 192.0.2.21: icmp_seq=1 ttl=64 time=0.544 ms But with TOS 4 and ECT(0), ns1 replies using source address 192.0.2.11 because the "tos 4" route isn't matched: $ ip netns exec ns0 ping -c 1 -b -Q 6 192.0.2.255 [...] 64 bytes from 192.0.2.11: icmp_seq=1 ttl=64 time=0.597 ms After this patch the ECN bits don't affect the result anymore: $ ip netns exec ns0 ping -c 1 -b -Q 6 192.0.2.255 [...] 64 bytes from 192.0.2.21: icmp_seq=1 ttl=64 time=0.591 ms Fixes: 35ebf65e851c ("ipv4: Create and use fib_compute_spec_dst() helper.") Signed-off-by: Guillaume Nault Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/fib_frontend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -292,7 +292,7 @@ __be32 fib_compute_spec_dst(struct sk_bu .flowi4_iif = LOOPBACK_IFINDEX, .flowi4_oif = l3mdev_master_ifindex_rcu(dev), .daddr = ip_hdr(skb)->saddr, - .flowi4_tos = RT_TOS(ip_hdr(skb)->tos), + .flowi4_tos = ip_hdr(skb)->tos & IPTOS_RT_MASK, .flowi4_scope = scope, .flowi4_mark = vmark ? skb->mark : 0, };