Received: by 10.223.185.116 with SMTP id b49csp5481612wrg; Wed, 7 Mar 2018 12:31:28 -0800 (PST) X-Google-Smtp-Source: AG47ELv58W1MB3MN4+khL+SZ2+CQ1sXEPv7VBsC6pYow3aGoZjn8psQkY6vCKHiIgFYxCuP4cgjr X-Received: by 10.98.172.18 with SMTP id v18mr23836273pfe.175.1520454688371; Wed, 07 Mar 2018 12:31:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520454688; cv=none; d=google.com; s=arc-20160816; b=xdZBBuHsnQF7B00uSxTEC28O+XNEJwGJzmwQ1fesiXWVUpHdavsRhLNaSnuDoUEzdv qoViSqvuRV+3fjrwDE+QcLn3/4NxwIzZCcdEDkKQY+MynIKqGeuLVbY4VIdbG6iX0snA 70D3LcsdYhgs1WFC3VyJbr2RnIowQgouShv2yBueSCvNpR51O1adwTUuBfttZcJImnGG s5lLlZDHVYW2MRym1ZJLpLwTKc+84eGkEx1qt/ddTIKDwRH8brFgHdrT5LVMbkrxfxZ1 R4haAA7MOlo8RUUfw+uGpak8KW69kH2fNr+CDJD9Pq/z9GIEnc21ea4pTWB+ogFFpME0 2jIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=z18lZHGGrRqHa6nCz+yARfGXrQYCbY3N0JTxt/MD4Og=; b=UoHSQs42PKe9Eksvd8P3mWcIjKk61um/+o5O5jDWYe/RFNUDwDzVyVCEzqUMRD+rr9 NvMY4igmyjI3o+88Ctkc1GhFnF+lyu/JfDXP81hFcSigLE3JAEGFPW2Y+GuNEPPcljtc E4hBCH+nsvqvLpEWMYE+eCT8hWr6zjhPbjfQf6DB6myLpzrpklC5T03LtfFJ27MfBkhB TIGnpePvZryGa2+w1XMGiwuqF9DvjNudhS4vjCtH4Chs1V3EwIOaGUOh6mRy9fvU1u1Y +sZ/P03Tru7IkZynvKGR+8t9uyzc6hdTCgz0A+gj+J7bSl11opQ/xmsXa27pyER3lTCH 42og== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h34-v6si13501877pld.26.2018.03.07.12.31.13; Wed, 07 Mar 2018 12:31:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964793AbeCGTm1 (ORCPT + 99 others); Wed, 7 Mar 2018 14:42:27 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42252 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934250AbeCGTmW (ORCPT ); Wed, 7 Mar 2018 14:42:22 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7B6DA109C; Wed, 7 Mar 2018 19:42:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianlin Shi , Stefano Brivio , David Ahern , "David S. Miller" Subject: [PATCH 4.15 040/122] fib_semantics: Dont match route with mismatching tclassid Date: Wed, 7 Mar 2018 11:37:32 -0800 Message-Id: <20180307191734.848176670@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191729.190879024@linuxfoundation.org> References: <20180307191729.190879024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stefano Brivio [ Upstream commit a8c6db1dfd1b1d18359241372bb204054f2c3174 ] In fib_nh_match(), if output interface or gateway are passed in the FIB configuration, we don't have to check next hops of multipath routes to conclude whether we have a match or not. However, we might still have routes with different realms matching the same output interface and gateway configuration, and this needs to cause the match to fail. Otherwise the first route inserted in the FIB will match, regardless of the realms: # ip route add 1.1.1.1 dev eth0 table 1234 realms 1/2 # ip route append 1.1.1.1 dev eth0 table 1234 realms 3/4 # ip route list table 1234 1.1.1.1 dev eth0 scope link realms 1/2 1.1.1.1 dev eth0 scope link realms 3/4 # ip route del 1.1.1.1 dev ens3 table 1234 realms 3/4 # ip route list table 1234 1.1.1.1 dev ens3 scope link realms 3/4 whereas route with realms 3/4 should have been deleted instead. Explicitly check for fc_flow passed in the FIB configuration (this comes from RTA_FLOW extracted by rtm_to_fib_config()) and fail matching if it differs from nh_tclassid. The handling of RTA_FLOW for multipath routes later in fib_nh_match() is still needed, as we can have multiple RTA_FLOW attributes that need to be matched against the tclassid of each next hop. v2: Check that fc_flow is set before discarding the match, so that the user can still select the first matching rule by not specifying any realm, as suggested by David Ahern. Reported-by: Jianlin Shi Signed-off-by: Stefano Brivio Acked-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/fib_semantics.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -646,6 +646,11 @@ int fib_nh_match(struct fib_config *cfg, fi->fib_nh, cfg, extack)) return 1; } +#ifdef CONFIG_IP_ROUTE_CLASSID + if (cfg->fc_flow && + cfg->fc_flow != fi->fib_nh->nh_tclassid) + return 1; +#endif if ((!cfg->fc_oif || cfg->fc_oif == fi->fib_nh->nh_oif) && (!cfg->fc_gw || cfg->fc_gw == fi->fib_nh->nh_gw)) return 0;