Skip to content

Commit bdd3957

Browse files
edumazetkuba-moo
authored andcommitted
net: bridge: prevent too big nested attributes in br_fill_linkxstats()
After commit ff205bf ("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: a60c090 ("bridge: netlink: export per-vlan stats") Reported-by: syzbot+a35f9259d08f907c06e6@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/6a0b0da3.050a0220.175f0c.0000.GAE@google.com/ Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Acked-by: Nikolay Aleksandrov <razor@blackwall.org> Link: https://patch.msgid.link/20260520114207.1394241-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 979c017 commit bdd3957

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

net/bridge/br_netlink.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,7 @@ static int br_fill_linkxstats(struct sk_buff *skb,
18241824
const struct net_device *dev,
18251825
int *prividx, int attr)
18261826
{
1827+
unsigned int limit = U16_MAX - nla_total_size(0);
18271828
struct nlattr *nla __maybe_unused;
18281829
struct net_bridge_port *p = NULL;
18291830
struct net_bridge_vlan_group *vg;
@@ -1841,6 +1842,7 @@ static int br_fill_linkxstats(struct sk_buff *skb,
18411842
p = br_port_get_rtnl(dev);
18421843
if (!p)
18431844
return 0;
1845+
limit -= nla_total_size_64bit(sizeof(p->stp_xstats));
18441846
br = p->br;
18451847
vg = nbp_vlan_group(p);
18461848
break;
@@ -1855,13 +1857,21 @@ static int br_fill_linkxstats(struct sk_buff *skb,
18551857
if (vg) {
18561858
u16 pvid;
18571859

1860+
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING
1861+
limit -= nla_total_size_64bit(sizeof(struct br_mcast_stats));
1862+
#endif
18581863
pvid = br_get_pvid(vg);
18591864
list_for_each_entry(v, &vg->vlan_list, vlist) {
18601865
struct bridge_vlan_xstats vxi;
18611866
struct pcpu_sw_netstats stats;
18621867

18631868
if (++vl_idx < *prividx)
18641869
continue;
1870+
1871+
if (skb_tail_pointer(skb) - (unsigned char *)nest +
1872+
nla_total_size(sizeof(vxi)) >= limit)
1873+
goto nla_put_failure;
1874+
18651875
memset(&vxi, 0, sizeof(vxi));
18661876
vxi.vid = v->vid;
18671877
vxi.flags = v->flags;

net/core/rtnetlink.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6328,8 +6328,9 @@ static int rtnl_stats_get(struct sk_buff *skb, struct nlmsghdr *nlh,
63286328
NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0,
63296329
0, &filters, &idxattr, &prividx, extack);
63306330
if (err < 0) {
6331-
/* -EMSGSIZE implies BUG in if_nlmsg_stats_size */
6332-
WARN_ON(err == -EMSGSIZE);
6331+
/* -EMSGSIZE implies BUG in if_nlmsg_stats_size
6332+
* or a too big nested attribute.
6333+
*/
63336334
kfree_skb(nskb);
63346335
} else {
63356336
err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid);

0 commit comments

Comments
 (0)