Skip to contentSkip to conversation

rtnetlink: Fix message size calculation for link messages

PATCH Applied Thomas Graf 3 participants 3 messages Nov 12, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Cc Patrick McHardy <[email protected]>
net/core/rtnetlink.c +5 -4
Index: net-2.6/net/core/rtnetlink.c
===================================================================
@@ -347,16 +347,17 @@ static size_t rtnl_link_get_size(const s
 	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;
 }
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Thomas Graf

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.

Quoted 6 lines

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.

Cc Patrick McHardy <[email protected]>

Looks good to me, thanks Thomas.

maintainer Applied
#2 lore raw

From: Patrick McHardy <[email protected]>
Date: Fri, 12 Nov 2010 08:43:46 +0100

Quoted 14 lines · Thomas Graf
Quoted 13 lines

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.

Quoted 6 lines
Quoted 2 lines
Cc Patrick McHardy <[email protected]>

Looks good to me, thanks Thomas.

Applied, thanks.