Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp668326ybg; Mon, 1 Jun 2020 11:12:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzpoctC6ovnN3H/laQFo+/Tkcxuhh6bVqIWsiyl5BGJ0eUgLSwKRPXlFmtPPuT95q2CIaz X-Received: by 2002:a05:6402:1d82:: with SMTP id dk2mr20861956edb.75.1591035164171; Mon, 01 Jun 2020 11:12:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591035164; cv=none; d=google.com; s=arc-20160816; b=Ad3UlrklMnNDiMmd9D67kztq1WkUOh4JJ37mudiqDLaPK7qiFUtFWlM1tSNfhZf+rj KvpOYt68BVtJ967/QTGh/KnJjpJwyFf9J9WUZMoW3QVl7w2SSX9zOFjGTTd4Jc3wqzx4 eLgRnGbLXUCicYhctbGmOdD+sBB1ALAJWh0RiTTOJXxj5nERoCmwJelpWr8QYj/rxfXg 6k3IcgIAE3VbELnkEfJZo1AweerIUSMuK8PRg8Qw/icrGbo9htu4AeDjRZHDNqtvKDk8 HgfvptxStwxtAk1EurJ4kSAqQyMiduJ4fTf9LDuu2S9HzlsvqgGWYlNNauVxxTRX+urN K6Ug== 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=cHDFXZZ4PEgRwSUSqceSQSFdXA0B+cFlTZejNpG82CM=; b=kL5jyF27p+fU7Y94cyPBY5asuRDLHrsA4qYv6YOmfGPZXcaRSwmBcdWKpXJnmfQszO ANDJQefOuPTlaJICUasfgOogsqT3z8UPeIK0KFPJH+mJbC4E0Yl2pdpDPOlaeeO6kvrh ohx3jV6lp0qLWZAHFB0VYH052SBnoVclTRnhb1GLG/YW+i/nEdgoWUj2rA6x9z+8R1iU l8g/vGkYrdOBeCZ40vfzFNFxWstuFLCs2yFYTceMEjVDHNra90oGCVRvQxw2cBX0yrpj WCw6lrFAenBgiGLoEzkS+vgrZmy4ZGWHDbfof0lE9UTkx9JtBR/ugTR8Br0Nv5ytkZWe LImg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Rf/UVkv+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw6si62764edb.390.2020.06.01.11.12.20; Mon, 01 Jun 2020 11:12:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Rf/UVkv+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730562AbgFASHQ (ORCPT + 99 others); Mon, 1 Jun 2020 14:07:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:52256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730033AbgFASGg (ORCPT ); Mon, 1 Jun 2020 14:06:36 -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 C60B92068D; Mon, 1 Jun 2020 18:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591034795; bh=20+5iZ1H51nyEgXnKUFVmNC29bl/C0FVNrLzX9WCgsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rf/UVkv+G2vrSlCSOD2NI5xhPuBL65u07Qg0Yzbodm6g2jCbc2d3n9CgutNbNyDbO DyASqP46d1+KUdBGnuCqWQXLzpLag6OtMcPK/VqI0Nq+CgramABwq4BzJwEB3IH7pq ghDZOuh0CaoPVhFtoMUemkyNz59nxbJ30m9x8OmA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sabrina Dubroca , David Ahern , "David S. Miller" Subject: [PATCH 5.4 003/142] net: dont return invalid table id error when we fall back to PF_UNSPEC Date: Mon, 1 Jun 2020 19:52:41 +0200 Message-Id: <20200601174038.389570989@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174037.904070960@linuxfoundation.org> References: <20200601174037.904070960@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 From: Sabrina Dubroca [ Upstream commit 41b4bd986f86331efc599b9a3f5fb86ad92e9af9 ] In case we can't find a ->dumpit callback for the requested (family,type) pair, we fall back to (PF_UNSPEC,type). In effect, we're in the same situation as if userspace had requested a PF_UNSPEC dump. For RTM_GETROUTE, that handler is rtnl_dump_all, which calls all the registered RTM_GETROUTE handlers. The requested table id may or may not exist for all of those families. commit ae677bbb4441 ("net: Don't return invalid table id error when dumping all families") fixed the problem when userspace explicitly requests a PF_UNSPEC dump, but missed the fallback case. For example, when we pass ipv6.disable=1 to a kernel with CONFIG_IP_MROUTE=y and CONFIG_IP_MROUTE_MULTIPLE_TABLES=y, the (PF_INET6, RTM_GETROUTE) handler isn't registered, so we end up in rtnl_dump_all, and listing IPv6 routes will unexpectedly print: # ip -6 r Error: ipv4: MR table does not exist. Dump terminated commit ae677bbb4441 introduced the dump_all_families variable, which gets set when userspace requests a PF_UNSPEC dump. However, we can't simply set the family to PF_UNSPEC in rtnetlink_rcv_msg in the fallback case to get dump_all_families == true, because some messages types (for example RTM_GETRULE and RTM_GETNEIGH) only register the PF_UNSPEC handler and use the family to filter in the kernel what is dumped to userspace. We would then export more entries, that userspace would have to filter. iproute does that, but other programs may not. Instead, this patch removes dump_all_families and updates the RTM_GETROUTE handlers to check if the family that is being dumped is their own. When it's not, which covers both the intentional PF_UNSPEC dumps (as dump_all_families did) and the fallback case, ignore the missing table id error. Fixes: cb167893f41e ("net: Plumb support for filtering ipv4 and ipv6 multicast route dumps") Signed-off-by: Sabrina Dubroca Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/ip_fib.h | 1 - net/ipv4/fib_frontend.c | 3 +-- net/ipv4/ipmr.c | 2 +- net/ipv6/ip6_fib.c | 2 +- net/ipv6/ip6mr.c | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -244,7 +244,6 @@ struct fib_dump_filter { u32 table_id; /* filter_set is an optimization that an entry is set */ bool filter_set; - bool dump_all_families; bool dump_routes; bool dump_exceptions; unsigned char protocol; --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -928,7 +928,6 @@ int ip_valid_fib_dump_req(struct net *ne else filter->dump_exceptions = false; - filter->dump_all_families = (rtm->rtm_family == AF_UNSPEC); filter->flags = rtm->rtm_flags; filter->protocol = rtm->rtm_protocol; filter->rt_type = rtm->rtm_type; @@ -1000,7 +999,7 @@ static int inet_dump_fib(struct sk_buff if (filter.table_id) { tb = fib_get_table(net, filter.table_id); if (!tb) { - if (filter.dump_all_families) + if (rtnl_msg_family(cb->nlh) != PF_INET) return skb->len; NL_SET_ERR_MSG(cb->extack, "ipv4: FIB table does not exist"); --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -2609,7 +2609,7 @@ static int ipmr_rtm_dumproute(struct sk_ mrt = ipmr_get_table(sock_net(skb->sk), filter.table_id); if (!mrt) { - if (filter.dump_all_families) + if (rtnl_msg_family(cb->nlh) != RTNL_FAMILY_IPMR) return skb->len; NL_SET_ERR_MSG(cb->extack, "ipv4: MR table does not exist"); --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -613,7 +613,7 @@ static int inet6_dump_fib(struct sk_buff if (arg.filter.table_id) { tb = fib6_get_table(net, arg.filter.table_id); if (!tb) { - if (arg.filter.dump_all_families) + if (rtnl_msg_family(cb->nlh) != PF_INET6) goto out; NL_SET_ERR_MSG_MOD(cb->extack, "FIB table does not exist"); --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -2498,7 +2498,7 @@ static int ip6mr_rtm_dumproute(struct sk mrt = ip6mr_get_table(sock_net(skb->sk), filter.table_id); if (!mrt) { - if (filter.dump_all_families) + if (rtnl_msg_family(cb->nlh) != RTNL_FAMILY_IP6MR) return skb->len; NL_SET_ERR_MSG_MOD(cb->extack, "MR table does not exist");