Skip to contentSkip to conversation

rtnetlink: fix if_nlmsg_stats_size() under estimation

PATCH Applied Eric Dumazet 3 participants 3 messages Oct 5, 2021 – Oct 6, 2021

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

PATCH 1/1 rtnetlink: fix if_nlmsg_stats_size() under estimation

From: Eric Dumazet <[email protected]>

rtnl_fill_statsinfo() is filling skb with one mandatory if_stats_msg structure.

nlmsg_put(skb, pid, seq, type, sizeof(struct if_stats_msg), flags);

But if_nlmsg_stats_size() never considered the needed storage.

This bug did not show up because alloc_skb(X) allocates skb with extra tailroom, because of added alignments. This could very well be changed in the future to have deterministic behavior.

Fixes 10c9ead9f3c6 ("rtnetlink: add new RTM_GETSTATS message to dump link stats")
Cc Roopa Prabhu <[email protected]>
---
 net/core/rtnetlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/rtnetlink.c +1 -1
index 972c8cb303a514758278307cd9fcb974e37f2b96..8ccce85562a1da2a5285aebd19a6a4cb7d6a163e 100644
@@ -5262,7 +5262,7 @@ static int rtnl_fill_statsinfo(struct sk_buff *skb, struct net_device *dev,
 static size_t if_nlmsg_stats_size(const struct net_device *dev,
 				  u32 filter_mask)
 {
-	size_t size = 0;
+	size_t size = NLMSG_ALIGN(sizeof(struct if_stats_msg));
 
 	if (stats_attr_valid(filter_mask, IFLA_STATS_LINK_64, 0))
 		size += nla_total_size_64bit(sizeof(struct rtnl_link_stats64));
Signature · 1 line
2.33.0.800.g4c38ced690-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

rtnl_fill_statsinfo() is filling skb with one mandatory if_stats_msg structure.

nlmsg_put(skb, pid, seq, type, sizeof(struct if_stats_msg), flags);

But if_nlmsg_stats_size() never considered the needed storage.

Quoted 8 lines

This bug did not show up because alloc_skb(X) allocates skb with extra tailroom, because of added alignments. This could very well be changed in the future to have deterministic behavior.

Fixes 10c9ead9f3c6 ("rtnetlink: add new RTM_GETSTATS message to dump link stats")
Cc Roopa Prabhu <[email protected]>

---

don't know how i missed this. Thanks for the patch Eric.

#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (refs/heads/master):

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

Quoted 9 lines · On Tue, 5 Oct 2021 14:04:17 -0700 you wrote:

From: Eric Dumazet <[email protected]>

rtnl_fill_statsinfo() is filling skb with one mandatory if_stats_msg structure.

nlmsg_put(skb, pid, seq, type, sizeof(struct if_stats_msg), flags);

But if_nlmsg_stats_size() never considered the needed storage.

[...]

Here is the summary with links:
- [net] rtnetlink: fix if_nlmsg_stats_size() under estimation

    https://git.kernel.org/netdev/net/c/d34367991933

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html