Skip to content

Commit 4775cc1

Browse files
miniplidavem330
authored andcommitted
rtnl: stats - add missing netlink message size checks
We miss to check if the netlink message is actually big enough to contain a struct if_stats_msg. Add a check to prevent userland from sending us short messages that would make us access memory beyond the end of the message. Fixes: 10c9ead ("rtnetlink: add new RTM_GETSTATS message to dump...") Signed-off-by: Mathias Krause <minipli@googlemail.com> Cc: Roopa Prabhu <roopa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b2eb09a commit 4775cc1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

net/core/rtnetlink.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,6 +3898,9 @@ static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh)
38983898
u32 filter_mask;
38993899
int err;
39003900

3901+
if (nlmsg_len(nlh) < sizeof(*ifsm))
3902+
return -EINVAL;
3903+
39013904
ifsm = nlmsg_data(nlh);
39023905
if (ifsm->ifindex > 0)
39033906
dev = __dev_get_by_index(net, ifsm->ifindex);
@@ -3947,6 +3950,9 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb)
39473950

39483951
cb->seq = net->dev_base_seq;
39493952

3953+
if (nlmsg_len(cb->nlh) < sizeof(*ifsm))
3954+
return -EINVAL;
3955+
39503956
ifsm = nlmsg_data(cb->nlh);
39513957
filter_mask = ifsm->filter_mask;
39523958
if (!filter_mask)

0 commit comments

Comments
 (0)