diff options
author | Thomas Graf <tgraf@infradead.org> | 2010-11-11 10:47:59 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-11-12 13:53:09 -0500 |
commit | 369cf77a6a3e41b1110506ddf43d45804103bfde (patch) | |
tree | 6bd88b669c8c68ac4d9008e00566ca15e43a6ff4 | |
parent | 8877870f8a8127b653f8c9a55c6b4de9f96f639b (diff) |
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: Thomas Graf <tgraf@infradead.org>
Acked-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/core/rtnetlink.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 8121268ddbdd..841c287ef40a 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c | |||
@@ -347,16 +347,17 @@ static size_t rtnl_link_get_size(const struct net_device *dev) | |||
347 | if (!ops) | 347 | if (!ops) |
348 | return 0; | 348 | return 0; |
349 | 349 | ||
350 | size = nlmsg_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */ | 350 | size = nla_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */ |
351 | nlmsg_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */ | 351 | nla_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */ |
352 | 352 | ||
353 | if (ops->get_size) | 353 | if (ops->get_size) |
354 | /* IFLA_INFO_DATA + nested data */ | 354 | /* IFLA_INFO_DATA + nested data */ |
355 | size += nlmsg_total_size(sizeof(struct nlattr)) + | 355 | size += nla_total_size(sizeof(struct nlattr)) + |
356 | ops->get_size(dev); | 356 | ops->get_size(dev); |
357 | 357 | ||
358 | if (ops->get_xstats_size) | 358 | if (ops->get_xstats_size) |
359 | size += ops->get_xstats_size(dev); /* IFLA_INFO_XSTATS */ | 359 | /* IFLA_INFO_XSTATS */ |
360 | size += nla_total_size(ops->get_xstats_size(dev)); | ||
360 | 361 | ||
361 | return size; | 362 | return size; |
362 | } | 363 | } |