]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
netlink: correct nlmsg size for multicast notifications
authorYuyang Huang <yuyanghuang@google.com>
Sat, 21 Dec 2024 10:00:07 +0000 (19:00 +0900)
committerJakub Kicinski <kuba@kernel.org>
Mon, 23 Dec 2024 18:26:43 +0000 (10:26 -0800)
Corrected the netlink message size calculation for multicast group
join/leave notifications. The previous calculation did not account for
the inclusion of both IPv4/IPv6 addresses and ifa_cacheinfo in the
payload. This fix ensures that the allocated message size is
sufficient to hold all necessary information.

This patch also includes the following improvements:
* Uses GFP_KERNEL instead of GFP_ATOMIC when holding the RTNL mutex.
* Uses nla_total_size(sizeof(struct in6_addr)) instead of
  nla_total_size(16).
* Removes unnecessary EXPORT_SYMBOL().

Fixes: 2c2b61d2138f ("netlink: add IGMP/MLD join/leave notifications")
Cc: Maciej Żenczykowski <maze@google.com>
Cc: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
Link: https://patch.msgid.link/20241221100007.1910089-1-yuyanghuang@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/igmp.c
net/ipv6/addrconf.c
net/ipv6/mcast.c

index 8a370ef37d3f6d0ea96280a75667f292637fbdf6..3da126cea884d348e77c91875326464e09e5a3b9 100644 (file)
@@ -1473,7 +1473,9 @@ static void inet_ifmcaddr_notify(struct net_device *dev,
        int err = -ENOMEM;
 
        skb = nlmsg_new(NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
-                       nla_total_size(sizeof(__be32)), GFP_ATOMIC);
+                       nla_total_size(sizeof(__be32)) +
+                       nla_total_size(sizeof(struct ifa_cacheinfo)),
+                       GFP_KERNEL);
        if (!skb)
                goto error;
 
@@ -1484,7 +1486,7 @@ static void inet_ifmcaddr_notify(struct net_device *dev,
                goto error;
        }
 
-       rtnl_notify(skb, net, 0, RTNLGRP_IPV4_MCADDR, NULL, GFP_ATOMIC);
+       rtnl_notify(skb, net, 0, RTNLGRP_IPV4_MCADDR, NULL, GFP_KERNEL);
        return;
 error:
        rtnl_set_sk_err(net, RTNLGRP_IPV4_MCADDR, err);
index 2e2684886953d55140cd3d4a1e024b5218331a49..4da409bc45777f60fd37bdee541c61165a51d22c 100644 (file)
@@ -5239,7 +5239,6 @@ int inet6_fill_ifmcaddr(struct sk_buff *skb,
        nlmsg_end(skb, nlh);
        return 0;
 }
-EXPORT_SYMBOL(inet6_fill_ifmcaddr);
 
 static int inet6_fill_ifacaddr(struct sk_buff *skb,
                               const struct ifacaddr6 *ifaca,
index 587831c148deec9524311ca42ebbf9c9de940fb7..9dfdb40988b0f8edd882c07b555ea0115ee95cab 100644 (file)
@@ -920,7 +920,9 @@ static void inet6_ifmcaddr_notify(struct net_device *dev,
        int err = -ENOMEM;
 
        skb = nlmsg_new(NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
-                       nla_total_size(16), GFP_ATOMIC);
+                       nla_total_size(sizeof(struct in6_addr)) +
+                       nla_total_size(sizeof(struct ifa_cacheinfo)),
+                       GFP_KERNEL);
        if (!skb)
                goto error;
 
@@ -931,7 +933,7 @@ static void inet6_ifmcaddr_notify(struct net_device *dev,
                goto error;
        }
 
-       rtnl_notify(skb, net, 0, RTNLGRP_IPV6_MCADDR, NULL, GFP_ATOMIC);
+       rtnl_notify(skb, net, 0, RTNLGRP_IPV6_MCADDR, NULL, GFP_KERNEL);
        return;
 error:
        rtnl_set_sk_err(net, RTNLGRP_IPV6_MCADDR, err);