Skip to content
This repository has been archived by the owner on Sep 11, 2019. It is now read-only.

Commit

Permalink
rtnetlink: stats: validate attributes in get as well as dumps
Browse files Browse the repository at this point in the history
Make sure NETLINK_GET_STRICT_CHK influences both GETSTATS doit
as well as the dump.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and davem330 committed Jan 19, 2019
1 parent 59c2805 commit 51bc860
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -4902,6 +4902,36 @@ static size_t if_nlmsg_stats_size(const struct net_device *dev,
return size;
}

static int rtnl_valid_stats_req(const struct nlmsghdr *nlh, bool strict_check,
bool is_dump, struct netlink_ext_ack *extack)
{
struct if_stats_msg *ifsm;

if (nlh->nlmsg_len < sizeof(*ifsm)) {
NL_SET_ERR_MSG(extack, "Invalid header for stats dump");
return -EINVAL;
}

if (!strict_check)
return 0;

ifsm = nlmsg_data(nlh);

/* only requests using strict checks can pass data to influence
* the dump. The legacy exception is filter_mask.
*/
if (ifsm->pad1 || ifsm->pad2 || (is_dump && ifsm->ifindex)) {
NL_SET_ERR_MSG(extack, "Invalid values in header for stats dump request");
return -EINVAL;
}
if (nlmsg_attrlen(nlh, sizeof(*ifsm))) {
NL_SET_ERR_MSG(extack, "Invalid attributes after stats header");
return -EINVAL;
}

return 0;
}

static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack)
{
Expand All @@ -4913,8 +4943,10 @@ static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh,
u32 filter_mask;
int err;

if (nlmsg_len(nlh) < sizeof(*ifsm))
return -EINVAL;
err = rtnl_valid_stats_req(nlh, netlink_strict_get_check(skb),
false, extack);
if (err)
return err;

ifsm = nlmsg_data(nlh);
if (ifsm->ifindex > 0)
Expand Down Expand Up @@ -4966,27 +4998,11 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb)

cb->seq = net->dev_base_seq;

if (nlmsg_len(cb->nlh) < sizeof(*ifsm)) {
NL_SET_ERR_MSG(extack, "Invalid header for stats dump");
return -EINVAL;
}
err = rtnl_valid_stats_req(cb->nlh, cb->strict_check, true, extack);
if (err)
return err;

ifsm = nlmsg_data(cb->nlh);

/* only requests using strict checks can pass data to influence
* the dump. The legacy exception is filter_mask.
*/
if (cb->strict_check) {
if (ifsm->pad1 || ifsm->pad2 || ifsm->ifindex) {
NL_SET_ERR_MSG(extack, "Invalid values in header for stats dump request");
return -EINVAL;
}
if (nlmsg_attrlen(cb->nlh, sizeof(*ifsm))) {
NL_SET_ERR_MSG(extack, "Invalid attributes after stats header");
return -EINVAL;
}
}

filter_mask = ifsm->filter_mask;
if (!filter_mask) {
NL_SET_ERR_MSG(extack, "Filter mask must be set for stats dump");
Expand Down

0 comments on commit 51bc860

Please sign in to comment.