Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1076199ybl; Wed, 14 Aug 2019 10:18:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTYn68Bot8KJt362e021nSn6tHxZuS1sTG4WscFKb1PjKarJGZZZcKuMWhbimCV7aEhEm3 X-Received: by 2002:aa7:9473:: with SMTP id t19mr1046914pfq.141.1565803107799; Wed, 14 Aug 2019 10:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565803107; cv=none; d=google.com; s=arc-20160816; b=KD9SorWZW2c/7tRZNw9D44rOFUh01fFOcQ2yuVVjvBQl+BLXI2ElTtDmPzSfCPApji 0WDnOWaCXUeC1kYTBgDddpoFo032mOqLuvnbLtMvDmjCYFfP71XCaQdlaS/btrcv24q0 lOXJ1BB1SzLamVUrrPo7dwy1OuBauueqB5skkiTW8+o5S3qbhuu3ENm9Ppge9O88Qj6+ N5eDPa1dkpkFGkeH7t3ObzMRxuZl5De9NS4FWOFE1OF1XHVjpCS5z6MBJc+EQQY9GuL2 7yxK6UormqtXz9QZN4kJB95FNvfJ+C2Iw1amW7kdB5wLGyD/DX972AKG9szDpXW9RLxR MlfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=417zbcW0eX+ZqCHAf7iTU9jyyev7YaaIPWKEcbwz9dE=; b=i6B6hcPgsEP6n0vBUmoF+pMmkucQ/VUrdmmXzowJ/UrLFIvIbIo1PVkisfYzQftQnB dp862fv/zbwg1hpJ/rY7gc12o66ESG4m3N5R2iWfn2fiMPle2lyiT068ff94s2pTUULd tGdOoSkptvctX8JcpH9Wr2s4MoAp1L8T3i2IlZ0XCmVxUIaI5B1WijFyUDCpuz5CO2Lk iaFmXyru4ieEu9rssv6llmX3hsnZnqb8SqTozAm/rt1qfVXELtMpLkNSxwFuLdrFr3T9 i3Ibz0W1jhXJ/ZH+p9bkVi/2MetnV5yj90CGr3fgld4EkovRm6UOsC+lqLTRqjX/VUKP GstA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uJ6C4Sqd; 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 o33si171341pgb.381.2019.08.14.10.18.11; Wed, 14 Aug 2019 10:18:27 -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; dkim=pass header.i=@kernel.org header.s=default header.b=uJ6C4Sqd; 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 S1730853AbfHNRNO (ORCPT + 99 others); Wed, 14 Aug 2019 13:13:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:37356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730845AbfHNRNK (ORCPT ); Wed, 14 Aug 2019 13:13:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 62C752063F; Wed, 14 Aug 2019 17:13:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802789; bh=Z6s/XtvNbaHCrf2tmoE8qUQetFtUw2XFeMO+gdEQPPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJ6C4SqdORkg9a0Y6GlUp4up7V4mMPChXOOdqiNkkuYSPi7NcRcmtqONdRu6UfsOt YSm6cq0r0hrYYcwq/X4DA4//5qwlWK3LPv5EmY3ek4vyZdjrvI8jVkWPx6crdjplCz XqzddKmzrZflYp0aftKC8p0Wj9uC+s+KNEB5OZcE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaohe Lin , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 4.14 27/69] netfilter: Fix rpfilter dropping vrf packets by mistake Date: Wed, 14 Aug 2019 19:01:25 +0200 Message-Id: <20190814165747.385022641@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165744.822314328@linuxfoundation.org> References: <20190814165744.822314328@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit b575b24b8eee37f10484e951b62ce2a31c579775 ] 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 Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- 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 37fb9552e8589..341d1bd637af2 100644 --- a/net/ipv4/netfilter/ipt_rpfilter.c +++ b/net/ipv4/netfilter/ipt_rpfilter.c @@ -96,6 +96,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 40eb16bd97860..d535768bea0fd 100644 --- a/net/ipv6/netfilter/ip6t_rpfilter.c +++ b/net/ipv6/netfilter/ip6t_rpfilter.c @@ -58,7 +58,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, lookup_flags); @@ -73,7 +75,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.20.1