Skip to content

Commit 369cf77

Browse files
Thomas Grafdavem330
authored andcommitted
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 <[email protected]> Acked-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8877870 commit 369cf77

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

net/core/rtnetlink.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,17 @@ static size_t rtnl_link_get_size(const struct net_device *dev)
347347
if (!ops)
348348
return 0;
349349

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

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

358358
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));
360361

361362
return size;
362363
}

0 commit comments

Comments
 (0)