Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2957530ybd; Fri, 28 Jun 2019 00:00:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqBtSkD7z61uDA3DbZiKOjeuMQB3s9hKpabgBtMxsXUBJE18+v9M31i1XMjHpXmPatCfH3 X-Received: by 2002:a63:fa57:: with SMTP id g23mr558602pgk.75.1561705218818; Fri, 28 Jun 2019 00:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561705218; cv=none; d=google.com; s=arc-20160816; b=LHiUmZqfUyWwQlBahf5l41iVAePCmWSR2WUm09F4cicdQtFwY4YOXhJ5j875NEfJQs NODf1uihP3dfDy+8w11Wus5pl4F+ocorFCwJWQGrru5GZ6gImHvr5eLvRpWmexw26VeY 0fAGojEHikyg+dZJEe6CBva3GXOBp7OzjuikBeUDpc2kOmojDZrEI+nYa74a0oHaWDp6 m1UCCsh2Jvc3yr/yij1G5ik7TPTTKdBXCFbQ8H0PH8MKCbMlb271H1dc8/ANcFNWw3+M uJoiwqhPlh3WG/3rX/l0GMpalq5AqWMAvPHz2ut4ghSd0DRrooS6S+9lf4B0d8rb01CE n6HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=bDiUV3bY1plpod4QgopO4gPmBOPc1PlXKeBgWnwoc0s=; b=03JQmTUO7VR7+s2R7AWNuZpELoPCM3G3RSERrB2L6g6wUcLhxw/ksTZSgY2cO5Oh/g rtCzVCdgv3KGxhCufzigDdrUOsnFRs+j3Vj5nrkF+OMhTnxw68muOHWqEklmtkI+QlW/ R2l/xfpA6PjbnaqvyJzagAxp9Y/7T8SyZieXXc4VQwSx6p1sT2zU2O6p7CEEooZF7Mig 24D9eHqLq7tw8zU3YNgkB8lQJ2p8F1z3U1n2evKfKQRLDDh05v1j9XyTBLDRZGmBWQBM NXLLLyUQHlLUszhCJj0PObYIIoQsHJqM8fDFPmF1/kOW3Vi50qjg0/yk96315sHkiPPo e5aA== 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 t186si1597696pfb.19.2019.06.28.00.00.02; Fri, 28 Jun 2019 00:00:18 -0700 (PDT) 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 S1727312AbfF1G7w (ORCPT + 99 others); Fri, 28 Jun 2019 02:59:52 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:51076 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726574AbfF1G7v (ORCPT ); Fri, 28 Jun 2019 02:59:51 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 54038D01547FC815F27D; Fri, 28 Jun 2019 14:59:48 +0800 (CST) Received: from huawei.com (10.175.100.202) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.439.0; Fri, 28 Jun 2019 14:59:41 +0800 From: Miaohe Lin To: , , , , , , , , , CC: , Subject: [PATCH v4] net: netfilter: Fix rpfilter dropping vrf packets by mistake Date: Fri, 28 Jun 2019 09:06:43 +0000 Message-ID: <1561712803-195184-1-git-send-email-linmiaohe@huawei.com> X-Mailer: git-send-email 1.8.3.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.100.202] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When firewalld is enabled with ipv4/ipv6 rpfilter, vrf ipv4/ipv6 packets will be dropped. Vrf device will pass through netfilter hook twice. One with enslaved device and another one with l3 master device. So in device may dismatch witch out device because out device is always enslaved device.So failed with the check of the rpfilter and drop the packets by mistake. Signed-off-by: Miaohe Lin --- net/ipv4/netfilter/ipt_rpfilter.c | 1 + net/ipv6/netfilter/ip6t_rpfilter.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/net/ipv4/netfilter/ipt_rpfilter.c b/net/ipv4/netfilter/ipt_rpfilter.c index 59031670b16a..cc23f1ce239c 100644 --- a/net/ipv4/netfilter/ipt_rpfilter.c +++ b/net/ipv4/netfilter/ipt_rpfilter.c @@ -78,6 +78,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par) flow.flowi4_mark = info->flags & XT_RPFILTER_VALID_MARK ? skb->mark : 0; flow.flowi4_tos = RT_TOS(iph->tos); flow.flowi4_scope = RT_SCOPE_UNIVERSE; + flow.flowi4_oif = l3mdev_master_ifindex_rcu(xt_in(par)); return rpfilter_lookup_reverse(xt_net(par), &flow, xt_in(par), info->flags) ^ invert; } diff --git a/net/ipv6/netfilter/ip6t_rpfilter.c b/net/ipv6/netfilter/ip6t_rpfilter.c index 6bcaf7357183..3c4a1772c15f 100644 --- a/net/ipv6/netfilter/ip6t_rpfilter.c +++ b/net/ipv6/netfilter/ip6t_rpfilter.c @@ -55,6 +55,10 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb, if (rpfilter_addr_linklocal(&iph->saddr)) { lookup_flags |= RT6_LOOKUP_F_IFACE; fl6.flowi6_oif = dev->ifindex; + /* Set flowi6_oif for vrf devices to lookup route in l3mdev domain. */ + } else if (netif_is_l3_master(dev) || netif_is_l3_slave(dev)) { + lookup_flags |= FLOWI_FLAG_SKIP_NH_OIF; + fl6.flowi6_oif = dev->ifindex; } else if ((flags & XT_RPFILTER_LOOSE) == 0) fl6.flowi6_oif = dev->ifindex; @@ -70,7 +74,9 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb, goto out; } - if (rt->rt6i_idev->dev == dev || (flags & XT_RPFILTER_LOOSE)) + if (rt->rt6i_idev->dev == dev || + l3mdev_master_ifindex_rcu(rt->rt6i_idev->dev) == dev->ifindex || + (flags & XT_RPFILTER_LOOSE)) ret = true; out: ip6_rt_put(rt); -- 2.21.GIT