Commit d8a66aa2 authored by David Ahern's avatar David Ahern Committed by David S. Miller
Browse files

net/mpls: Implement handler for strict data checking on dumps



Without CONFIG_INET enabled compiles fail with:

net/mpls/af_mpls.o: In function `mpls_dump_routes':
af_mpls.c:(.text+0xed0): undefined reference to `ip_valid_fib_dump_req'

The preference is for MPLS to use the same handler as ipv4 and ipv6
to allow consistency when doing a dump for AF_UNSPEC which walks
all address families invoking the route dump handler. If INET is
disabled then fallback to an MPLS version which can be tighter on
the data checks.

Fixes: e8ba330a ("rtnetlink: Update fib dumps for strict data checking")
Reported-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Reported-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 83b59b46
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -2031,6 +2031,40 @@ nla_put_failure:
	return -EMSGSIZE;
}

#if IS_ENABLED(CONFIG_INET)
static int mpls_valid_fib_dump_req(const struct nlmsghdr *nlh,
				   struct netlink_ext_ack *extack)
{
	return ip_valid_fib_dump_req(nlh, extack);
}
#else
static int mpls_valid_fib_dump_req(const struct nlmsghdr *nlh,
				   struct netlink_ext_ack *extack)
{
	struct rtmsg *rtm;

	if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*rtm))) {
		NL_SET_ERR_MSG_MOD(extack, "Invalid header for FIB dump request");
		return -EINVAL;
	}

	rtm = nlmsg_data(nlh);
	if (rtm->rtm_dst_len || rtm->rtm_src_len  || rtm->rtm_tos   ||
	    rtm->rtm_table   || rtm->rtm_protocol || rtm->rtm_scope ||
	    rtm->rtm_type    || rtm->rtm_flags) {
		NL_SET_ERR_MSG_MOD(extack, "Invalid values in header for FIB dump request");
		return -EINVAL;
	}

	if (nlmsg_attrlen(nlh, sizeof(*rtm))) {
		NL_SET_ERR_MSG_MOD(extack, "Invalid data after header in FIB dump request");
		return -EINVAL;
	}

	return 0;
}
#endif

static int mpls_dump_routes(struct sk_buff *skb, struct netlink_callback *cb)
{
	const struct nlmsghdr *nlh = cb->nlh;
@@ -2042,7 +2076,7 @@ static int mpls_dump_routes(struct sk_buff *skb, struct netlink_callback *cb)
	ASSERT_RTNL();

	if (cb->strict_check) {
		int err = ip_valid_fib_dump_req(nlh, cb->extack);
		int err = mpls_valid_fib_dump_req(nlh, cb->extack);

		if (err < 0)
			return err;