From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: [PATCH RFC v2 net-next 09/25] rtnetlink: Update inet6_dump_ifinfo to support NLM_F_DUMP_PROPER_HDR Date: Mon, 1 Oct 2018 17:28:35 -0700 Message-ID: <20181002002851.5002-10-dsahern@kernel.org> References: <20181002002851.5002-1-dsahern@kernel.org> Cc: christian@brauner.io, jbenc@redhat.com, stephen@networkplumber.org, David Ahern To: netdev@vger.kernel.org, davem@davemloft.net Return-path: Received: from mail.kernel.org ([198.145.29.99]:35216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbeJBHJS (ORCPT ); Tue, 2 Oct 2018 03:09:18 -0400 In-Reply-To: <20181002002851.5002-1-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org List-ID: From: David Ahern Update inet6_dump_ifinfo to check for NLM_F_DUMP_PROPER_HDR in the netlink message header. If the flag is set, the dump request is expected to have an ifinfomsg struct as the header. All elements of the struct are expected to be 0 and no attributes can be appended. Signed-off-by: David Ahern --- net/ipv6/addrconf.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 3382737df2a8..eb6fd5fbac80 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -5626,8 +5626,34 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, return -EMSGSIZE; } +static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh, + struct netlink_ext_ack *extack) +{ + struct ifinfomsg *ifm; + + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { + NL_SET_ERR_MSG(extack, "Invalid header"); + return -EINVAL; + } + + if (nlh->nlmsg_len > nlmsg_msg_size(sizeof(*ifm))) { + NL_SET_ERR_MSG(extack, "Invalid data after header"); + return -EINVAL; + } + + ifm = nlmsg_data(nlh); + if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || + ifm->ifi_change || ifm->ifi_index) { + NL_SET_ERR_MSG(extack, "Invalid values in header for dump request"); + return -EINVAL; + } + + return 0; +} + static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) { + const struct nlmsghdr *nlh = cb->nlh; struct net *net = sock_net(skb->sk); int h, s_h; int idx = 0, s_idx; @@ -5635,6 +5661,16 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) struct inet6_dev *idev; struct hlist_head *head; + /* only requests using NLM_F_DUMP_PROPER_HDR can pass data to + * influence the dump + */ + if (nlh->nlmsg_flags & NLM_F_DUMP_PROPER_HDR) { + int err = inet6_valid_dump_ifinfo(nlh, cb->extack); + + if (err) + return err; + } + s_h = cb->args[0]; s_idx = cb->args[1]; @@ -5650,7 +5686,7 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) goto cont; if (inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, + nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI) < 0) goto out; cont: -- 2.11.0