Skip to contentSkip to conversation

net: bridge: prevent too big nested attributes in br_fill_linkxstats()

PATCH Applied Eric Dumazet 4 participants 4 messages May 20 – May 21

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

PATCH v2 1/1 net: bridge: prevent too big nested attributes in br_fill_linkxstats()

After commit ff205bf8c554 ("netlink: add one debug check in nla_nest_end()") syzbot found that br_fill_linkxstats() can send corrupted netlink packets.

Make sure the nested attribute size is bounded.

Fixes a60c090361ea ("bridge: netlink: export per-vlan stats")
Reported-by [email protected]

---
Cc: Nikolay Aleksandrov <[email protected]>
Cc: Ido Schimmel <[email protected]>
---
v2: remove the WARN_ON(err == -EMSGSIZE) in rtnl_stats_get() (Ido)
adjust limit (Ido)
v1: https://lore.kernel.org/netdev/[email protected]/

 net/bridge/br_netlink.c | 10 ++++++++++
 net/core/rtnetlink.c    |  5 +++--
 2 files changed, 13 insertions(+), 2 deletions(-)
net/bridge/br_netlink.c +10 -0
index 6fd5386a1d646542c184702e13cc2e6c8ee1820d..c04a4d0889ae412a9fc3e2458faa41200f26b098 100644
@@ -1824,6 +1824,7 @@ static int br_fill_linkxstats(struct sk_buff *skb,
 			      const struct net_device *dev,
 			      int *prividx, int attr)
 {
+	unsigned int limit = U16_MAX - nla_total_size(0);
 	struct nlattr *nla __maybe_unused;
 	struct net_bridge_port *p = NULL;
 	struct net_bridge_vlan_group *vg;
@@ -1841,6 +1842,7 @@ static int br_fill_linkxstats(struct sk_buff *skb,
 		p = br_port_get_rtnl(dev);
 		if (!p)
 			return 0;
+		limit -= nla_total_size_64bit(sizeof(p->stp_xstats));
 		br = p->br;
 		vg = nbp_vlan_group(p);
 		break;
@@ -1855,6 +1857,9 @@ static int br_fill_linkxstats(struct sk_buff *skb,
 	if (vg) {
 		u16 pvid;
 
+#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
+		limit -= nla_total_size_64bit(sizeof(struct br_mcast_stats));
+#endif
 		pvid = br_get_pvid(vg);
 		list_for_each_entry(v, &vg->vlan_list, vlist) {
 			struct bridge_vlan_xstats vxi;
@@ -1862,6 +1867,11 @@ static int br_fill_linkxstats(struct sk_buff *skb,
 
 			if (++vl_idx < *prividx)
 				continue;
+
+			if (skb_tail_pointer(skb) - (unsigned char *)nest +
+			    nla_total_size(sizeof(vxi)) >= limit)
+				goto nla_put_failure;
+
 			memset(&vxi, 0, sizeof(vxi));
 			vxi.vid = v->vid;
 			vxi.flags = v->flags;
net/core/rtnetlink.c +3 -2
index df042da422ef3137ed67efaf8d243cc6b1fec6c7..511c25bf6f2a25563b7dd8d618fb46c9297d2ed7 100644
@@ -6328,8 +6328,9 @@ static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh,
 				  NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0,
 				  0, &filters, &idxattr, &prividx, extack);
 	if (err < 0) {
-		/* -EMSGSIZE implies BUG in if_nlmsg_stats_size */
-		WARN_ON(err == -EMSGSIZE);
+		/* -EMSGSIZE implies BUG in if_nlmsg_stats_size
+		 * or a too big nested attribute.
+		 */
 		kfree_skb(nskb);
 	} else {
 		err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid);
Signature · 1 line
2.54.0.631.ge1b05301d1-goog
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Eric Dumazet

After commit ff205bf8c554 ("netlink: add one debug check in nla_nest_end()") syzbot found that br_fill_linkxstats() can send corrupted netlink packets.

Make sure the nested attribute size is bounded.

Fixes a60c090361ea ("bridge: netlink: export per-vlan stats")
Reported-by [email protected]
maintainer Acked-by on v2 1/1
#2 lore raw
In reply to Eric Dumazet
Quoted 17 lines · Eric Dumazet

After commit ff205bf8c554 ("netlink: add one debug check in nla_nest_end()") syzbot found that br_fill_linkxstats() can send corrupted netlink packets.

Make sure the nested attribute size is bounded.

Fixes a60c090361ea ("bridge: netlink: export per-vlan stats")
Reported-by [email protected]

---
Cc: Nikolay Aleksandrov <[email protected]>
Cc: Ido Schimmel <[email protected]>
---
v2: remove the WARN_ON(err == -EMSGSIZE) in rtnl_stats_get() (Ido)
adjust limit (Ido)
v1: https://lore.kernel.org/netdev/[email protected]/

Quoted 4 lines
 net/bridge/br_netlink.c | 10 ++++++++++
 net/core/rtnetlink.c    |  5 +++--
 2 files changed, 13 insertions(+), 2 deletions(-)

Thanks!

#3 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Wed, 20 May 2026 11:42:07 +0000 you wrote:

After commit ff205bf8c554 ("netlink: add one debug check in nla_nest_end()") syzbot found that br_fill_linkxstats() can send corrupted netlink packets.

Make sure the nested attribute size is bounded.

Fixes a60c090361ea ("bridge: netlink: export per-vlan stats")
Reported-by [email protected]

[...]

Here is the summary with links:
- [v2,net] net: bridge: prevent too big nested attributes in br_fill_linkxstats()

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

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html