Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7120483rwi; Mon, 24 Oct 2022 10:04:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6f87wybHdZa9A1GSZD6WAXzf+9CXYbGVVqynnEf9HA9va6r1SsSeJawGM049Gb2mlTVieG X-Received: by 2002:a17:907:3e9c:b0:78d:ce8b:8548 with SMTP id hs28-20020a1709073e9c00b0078dce8b8548mr29290172ejc.427.1666631047729; Mon, 24 Oct 2022 10:04:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666631047; cv=none; d=google.com; s=arc-20160816; b=KAIWK/Ride80reWeRiKNpgiZngJHNccHoTH7JfOasju88te5mbzEUms6gOAhkyx3Re 6Mnsl/P9GaFCHI4grWfNOcMGWMvZzN3T8av27VvQ+2Ud53oG9fYwIxocu4pHLF8t6sZS gsGanGsZEf3qsCtBivNq3HRJOZ6y+pmySVltWM3+gkF4dFTPInHYP5dZJE6sDnoBGhKM wPukEb6UZWnyAgSQWfBUH2shyJnX7Ota2HhDj6wVL+mGnjKew+sKR0hCz+Ms7t0Us0wk 2HXE8yjxYfhL0E8kiM0tipe96+IvOXe7350XRsF2XIkHu0FzeSTcOqUTOCk8Tyj+pn2F HFKQ== 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=iatDN1IBJcPRXwqvoftvcJncg5RYrCSHHP7XuKJA9ow=; b=oC+ZBrr6dRgvSWNrVuuGr1BooHx/6sbKwVn0wUxqXroS+szyXgtx8MbpJvcbjBIIRJ Y4p+Bkh3JO0F9payiua/Hf4NhrboxMDgD6fJIMCsHqscb+pcgn0+K9M1RFwpoeXeX68I j5ca4AN3ICMfGHM8S5y/cSj3rfRMlU1AhxK4to707vpwP79BcyYzzdPz1eZ70E0BKpok BJfWjSWrL3gn+w8UKPd00TJG3tN7NCiKxZ6Am2/c+mbrYPiOUALpKL9F/J440wLnK0FE m11DVIR1qcMs3nPMnpGVMPHtrVpWjVn/WVhPNziyLunJUUsOmFLuAjB8hP6VmKdJQ5Q/ TvuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yhOx63Xo; 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 ne36-20020a1709077ba400b007abafd4d7d8si50151ejc.706.2022.10.24.10.03.40; Mon, 24 Oct 2022 10:04:07 -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=yhOx63Xo; 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 S230417AbiJXRAg (ORCPT + 99 others); Mon, 24 Oct 2022 13:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232000AbiJXQ5x (ORCPT ); Mon, 24 Oct 2022 12:57:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4279946238; Mon, 24 Oct 2022 08:37:07 -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 422EBB811DD; Mon, 24 Oct 2022 11:59:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FFE9C433D6; Mon, 24 Oct 2022 11:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612767; bh=YmD/sxiRNcUAS4pk6CrV8Ul3dzvDsIvTgC6QwATOJDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yhOx63Xo+789rG3Tsg24k5TH8lrTjhRtaBSLE964phXBNpuHT/hyc/VB6FiPyFEN8 f3DRVViF4VnxlYWw1KN0mpqzarxUJ2OpmMd3MsGNTJwtP+3mbzP27L+ldPOCRF67oX 0X5UmXxLLA49nFwCTLfBnRilFJ2NMZIPsBtH/xBQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phil Sutter , Florian Westphal , Sasha Levin Subject: [PATCH 4.19 084/229] netfilter: nft_fib: Fix for rpath check with VRF devices Date: Mon, 24 Oct 2022 13:30:03 +0200 Message-Id: <20221024113001.783335287@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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 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: Phil Sutter [ Upstream commit 2a8a7c0eaa8747c16aa4a48d573aa920d5c00a5c ] Analogous to commit b575b24b8eee3 ("netfilter: Fix rpfilter dropping vrf packets by mistake") but for nftables fib expression: Add special treatment of VRF devices so that typical reverse path filtering via 'fib saddr . iif oif' expression works as expected. Fixes: f6d0cbcf09c50 ("netfilter: nf_tables: add fib expression") Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/ipv4/netfilter/nft_fib_ipv4.c | 3 +++ net/ipv6/netfilter/nft_fib_ipv6.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/net/ipv4/netfilter/nft_fib_ipv4.c b/net/ipv4/netfilter/nft_fib_ipv4.c index e50976e3c213..3b2e8ac45d4e 100644 --- a/net/ipv4/netfilter/nft_fib_ipv4.c +++ b/net/ipv4/netfilter/nft_fib_ipv4.c @@ -95,6 +95,9 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, else oif = NULL; + if (priv->flags & NFTA_FIB_F_IIF) + fl4.flowi4_oif = l3mdev_master_ifindex_rcu(oif); + if (nft_hook(pkt) == NF_INET_PRE_ROUTING && nft_fib_is_loopback(pkt->skb, nft_in(pkt))) { nft_fib_store_result(dest, priv, pkt, diff --git a/net/ipv6/netfilter/nft_fib_ipv6.c b/net/ipv6/netfilter/nft_fib_ipv6.c index 36be3cf0adef..fa71e40789ed 100644 --- a/net/ipv6/netfilter/nft_fib_ipv6.c +++ b/net/ipv6/netfilter/nft_fib_ipv6.c @@ -41,6 +41,9 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv, if (ipv6_addr_type(&fl6->daddr) & IPV6_ADDR_LINKLOCAL) { lookup_flags |= RT6_LOOKUP_F_IFACE; fl6->flowi6_oif = get_ifindex(dev ? dev : pkt->skb->dev); + } else if ((priv->flags & NFTA_FIB_F_IIF) && + (netif_is_l3_master(dev) || netif_is_l3_slave(dev))) { + fl6->flowi6_oif = dev->ifindex; } if (ipv6_addr_type(&fl6->saddr) & IPV6_ADDR_UNICAST) @@ -189,7 +192,8 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs, if (rt->rt6i_flags & (RTF_REJECT | RTF_ANYCAST | RTF_LOCAL)) goto put_rt_err; - if (oif && oif != rt->rt6i_idev->dev) + if (oif && oif != rt->rt6i_idev->dev && + l3mdev_master_ifindex_rcu(rt->rt6i_idev->dev) != oif->ifindex) goto put_rt_err; switch (priv->result) { -- 2.35.1