Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2773712ybi; Mon, 1 Jul 2019 18:53:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3qFLOf1HrA8kw6+lFaoRbIHeC+iTXGG3KikoZcDaLi98R8I12qQ5Xx8dMgRTm3Fx/UDjx X-Received: by 2002:a17:902:b7c1:: with SMTP id v1mr32252003plz.85.1562032383674; Mon, 01 Jul 2019 18:53:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562032383; cv=none; d=google.com; s=arc-20160816; b=q/bLa77vFZI/Kuuq+RDJgpJSW57s3lLPs2UqJU9gWAoSS2/HElc94f4s17KwCC1YBi 0RbXro6OMJj8eQI+eC/cPh9B9dv5i+0gTM6dkRs+cIyvIhUc8Fnl4fLhmyKdV/12FO7Y KRrCQjKoCU3rwJskufoEL2TQIc1RtrptCFuMgBV1YSbOG3rc2A3iHh62gLifl6or0ix3 1VUyuazATspGyZV1KXWbjppx7b+Fd3t6MQuY6J/lA/33d2MZwgem3/2d66kmOv9RoGLo 3Kd3El2SBwkLhbXqD7UQF8avNbqoNYqoF7yantZx2jO45VjZmuBSJ/g5u+RddiTedbog avTg== 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=in9mFEAZujNOvB/RdG50OuKiDeHP/q+zwLYAtYDFyFM=; b=EQAU2H0pj3nBHSDKFfu/xn2WqG766f7wm9vgANQPJyZf4tFnzkrOP44sFLnazm6G8y QsS7WaQ1RYi9Yj7RM4cFKadXVKxZwxI6IisaD/d60YehT+asNe8dTEWe2eaTDnkk9+Z+ WRXZ4NxADvxU8jDxltr15wjoMmdsLlEdr1w4U7jVQAiPDa8iByddbQ5NYiceioMFwTkB 9wLsXJuxhAI/uKQREWFKdFmwnOOsNXaX9c1xTyc3a3u2niPX+eibtUGG/yssl33EbZ1U pV2lU9l83sCuYy3qfhf7mJ+NIByHCDXeSDvJjYX6wYMDginzn/4CiVD6Vnt5oR7Ux1D0 g5GQ== 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 a17si979626pjs.98.2019.07.01.18.52.48; Mon, 01 Jul 2019 18:53:03 -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 S1727017AbfGBBw1 (ORCPT + 99 others); Mon, 1 Jul 2019 21:52:27 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60266 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726486AbfGBBw0 (ORCPT ); Mon, 1 Jul 2019 21:52:26 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 290B0A9BBE054957DE66; Tue, 2 Jul 2019 09:52:24 +0800 (CST) Received: from huawei.com (10.175.100.202) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.439.0; Tue, 2 Jul 2019 09:52:18 +0800 From: Miaohe Lin To: , , , , , , , , , CC: , Subject: [PATCH v5] net: netfilter: Fix rpfilter dropping vrf packets by mistake Date: Tue, 2 Jul 2019 03:59:36 +0000 Message-ID: <1562039976-203880-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, 7 insertions(+), 2 deletions(-) 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..d800801a5dd2 100644 --- a/net/ipv6/netfilter/ip6t_rpfilter.c +++ b/net/ipv6/netfilter/ip6t_rpfilter.c @@ -55,7 +55,9 @@ 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; - } else if ((flags & XT_RPFILTER_LOOSE) == 0) + /* Set flowi6_oif for vrf devices to lookup route in l3mdev domain. */ + } else if (netif_is_l3_master(dev) || netif_is_l3_slave(dev) || + (flags & XT_RPFILTER_LOOSE) == 0) fl6.flowi6_oif = dev->ifindex; rt = (void *)ip6_route_lookup(net, &fl6, skb, lookup_flags); @@ -70,7 +72,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