Skip to content

Commit 841891e

Browse files
dsaherndavem330
authored andcommitted
rtnetlink: Update rtnl_stats_dump for strict data checking
Update rtnl_stats_dump for strict data checking. If the flag is set, the dump request is expected to have an if_stats_msg struct as the header. All elements of the struct are expected to be 0 except filter_mask which must be non-0 (legacy behavior). No attributes are supported. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2d011be commit 841891e

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

net/core/rtnetlink.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4680,6 +4680,7 @@ static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh,
46804680

46814681
static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb)
46824682
{
4683+
struct netlink_ext_ack *extack = cb->extack;
46834684
int h, s_h, err, s_idx, s_idxattr, s_prividx;
46844685
struct net *net = sock_net(skb->sk);
46854686
unsigned int flags = NLM_F_MULTI;
@@ -4696,13 +4697,32 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb)
46964697

46974698
cb->seq = net->dev_base_seq;
46984699

4699-
if (nlmsg_len(cb->nlh) < sizeof(*ifsm))
4700+
if (nlmsg_len(cb->nlh) < sizeof(*ifsm)) {
4701+
NL_SET_ERR_MSG(extack, "Invalid header for stats dump");
47004702
return -EINVAL;
4703+
}
47014704

47024705
ifsm = nlmsg_data(cb->nlh);
4706+
4707+
/* only requests using NLM_F_DUMP_PROPER_HDR can pass data to
4708+
* influence the dump. The legacy exception is filter_mask.
4709+
*/
4710+
if (cb->strict_check) {
4711+
if (ifsm->pad1 || ifsm->pad2 || ifsm->ifindex) {
4712+
NL_SET_ERR_MSG(extack, "Invalid values in header for stats dump request");
4713+
return -EINVAL;
4714+
}
4715+
if (nlmsg_attrlen(cb->nlh, sizeof(*ifsm))) {
4716+
NL_SET_ERR_MSG(extack, "Invalid attributes after stats header");
4717+
return -EINVAL;
4718+
}
4719+
}
4720+
47034721
filter_mask = ifsm->filter_mask;
4704-
if (!filter_mask)
4722+
if (!filter_mask) {
4723+
NL_SET_ERR_MSG(extack, "Filter mask must be set for stats dump");
47054724
return -EINVAL;
4725+
}
47064726

47074727
for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
47084728
idx = 0;

0 commit comments

Comments
 (0)