Skip to content

Commit

Permalink
rtnetlink: Fix message size calculation for link messages
Browse files Browse the repository at this point in the history
nlmsg_total_size() calculates the length of a netlink message
including header and alignment. nla_total_size() calculates the
space an individual attribute consumes which was meant to be used
in this context.

Also, ensure to account for the attribute header for the
IFLA_INFO_XSTATS attribute as implementations of get_xstats_size()
seem to assume that we do so.

The addition of two message headers minus the missing attribute
header resulted in a calculated message size that was larger than
required. Therefore we never risked running out of skb tailroom.

Signed-off-by: Thomas Graf <[email protected]>
Acked-by: Patrick McHardy <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Thomas Graf authored and davem330 committed Nov 12, 2010
1 parent 8877870 commit 369cf77
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,17 @@ static size_t rtnl_link_get_size(const struct net_device *dev)
if (!ops)
return 0;

size = nlmsg_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */
nlmsg_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */
size = nla_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */
nla_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */

if (ops->get_size)
/* IFLA_INFO_DATA + nested data */
size += nlmsg_total_size(sizeof(struct nlattr)) +
size += nla_total_size(sizeof(struct nlattr)) +
ops->get_size(dev);

if (ops->get_xstats_size)
size += ops->get_xstats_size(dev); /* IFLA_INFO_XSTATS */
/* IFLA_INFO_XSTATS */
size += nla_total_size(ops->get_xstats_size(dev));

return size;
}
Expand Down

0 comments on commit 369cf77

Please sign in to comment.