Commit 369cf77a authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

rtnetlink: Fix message size calculation for link messages

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: default avatarThomas Graf <tgraf@infradead.org>
Acked-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8877870f
...@@ -347,16 +347,17 @@ static size_t rtnl_link_get_size(const struct net_device *dev) ...@@ -347,16 +347,17 @@ static size_t rtnl_link_get_size(const struct net_device *dev)
if (!ops) if (!ops)
return 0; return 0;
size = nlmsg_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */ size = nla_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */
nlmsg_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */ nla_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */
if (ops->get_size) if (ops->get_size)
/* IFLA_INFO_DATA + nested data */ /* IFLA_INFO_DATA + nested data */
size += nlmsg_total_size(sizeof(struct nlattr)) + size += nla_total_size(sizeof(struct nlattr)) +
ops->get_size(dev); ops->get_size(dev);
if (ops->get_xstats_size) 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; return size;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment