Skip to content

Commit 67082c8

Browse files
author
Hangbin Liu
committed
ipv6: mcast: extend RCU protection in igmp6_send()
JIRA: https://issues.redhat.com/browse/RHEL-81467 Upstream Status: net.git commit 087c1fa CVE: CVE-2025-21759 commit 087c1fa Author: Eric Dumazet <edumazet@google.com> Date: Fri Feb 7 13:58:40 2025 +0000 ipv6: mcast: extend RCU protection in igmp6_send() igmp6_send() can be called without RTNL or RCU being held. Extend RCU protection so that we can safely fetch the net pointer and avoid a potential UAF. Note that we no longer can use sock_alloc_send_skb() because ipv6.igmp_sk uses GFP_KERNEL allocations which can sleep. Instead use alloc_skb() and charge the net->ipv6.igmp_sk socket under RCU protection. Fixes: b8ad0cb ("[NETNS][IPV6] mcast - handle several network namespace") Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: David Ahern <dsahern@kernel.org> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20250207135841.1948589-9-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Hangbin Liu <haliu@redhat.com>
1 parent 79919c3 commit 67082c8

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

net/ipv6/mcast.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,21 +2125,21 @@ static void mld_send_cr(struct inet6_dev *idev)
21252125

21262126
static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
21272127
{
2128-
struct net *net = dev_net(dev);
2129-
struct sock *sk = net->ipv6.igmp_sk;
2128+
const struct in6_addr *snd_addr, *saddr;
2129+
int err, len, payload_len, full_len;
2130+
struct in6_addr addr_buf;
21302131
struct inet6_dev *idev;
21312132
struct sk_buff *skb;
21322133
struct mld_msg *hdr;
2133-
const struct in6_addr *snd_addr, *saddr;
2134-
struct in6_addr addr_buf;
21352134
int hlen = LL_RESERVED_SPACE(dev);
21362135
int tlen = dev->needed_tailroom;
2137-
int err, len, payload_len, full_len;
21382136
u8 ra[8] = { IPPROTO_ICMPV6, 0,
21392137
IPV6_TLV_ROUTERALERT, 2, 0, 0,
21402138
IPV6_TLV_PADN, 0 };
2141-
struct flowi6 fl6;
21422139
struct dst_entry *dst;
2140+
struct flowi6 fl6;
2141+
struct net *net;
2142+
struct sock *sk;
21432143

21442144
if (type == ICMPV6_MGM_REDUCTION)
21452145
snd_addr = &in6addr_linklocal_allrouters;
@@ -2150,19 +2150,21 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
21502150
payload_len = len + sizeof(ra);
21512151
full_len = sizeof(struct ipv6hdr) + payload_len;
21522152

2153-
rcu_read_lock();
2154-
IP6_INC_STATS(net, __in6_dev_get(dev), IPSTATS_MIB_OUTREQUESTS);
2155-
rcu_read_unlock();
2153+
skb = alloc_skb(hlen + tlen + full_len, GFP_KERNEL);
21562154

2157-
skb = sock_alloc_send_skb(sk, hlen + tlen + full_len, 1, &err);
2155+
rcu_read_lock();
21582156

2157+
net = dev_net_rcu(dev);
2158+
idev = __in6_dev_get(dev);
2159+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
21592160
if (!skb) {
2160-
rcu_read_lock();
2161-
IP6_INC_STATS(net, __in6_dev_get(dev),
2162-
IPSTATS_MIB_OUTDISCARDS);
2161+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
21632162
rcu_read_unlock();
21642163
return;
21652164
}
2165+
sk = net->ipv6.igmp_sk;
2166+
skb_set_owner_w(skb, sk);
2167+
21662168
skb->priority = TC_PRIO_CONTROL;
21672169
skb_reserve(skb, hlen);
21682170

@@ -2187,9 +2189,6 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
21872189
IPPROTO_ICMPV6,
21882190
csum_partial(hdr, len, 0));
21892191

2190-
rcu_read_lock();
2191-
idev = __in6_dev_get(skb->dev);
2192-
21932192
icmpv6_flow_init(sk, &fl6, type,
21942193
&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
21952194
skb->dev->ifindex);

0 commit comments

Comments
 (0)