Skip to content

Commit 0bf8e2f

Browse files
edumazetgregkh
authored andcommitted
ipv6: mcast: extend RCU protection in igmp6_send()
[ Upstream commit 087c1fa ] 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: Sasha Levin <sashal@kernel.org>
1 parent 789230e commit 0bf8e2f

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
@@ -2122,21 +2122,21 @@ static void mld_send_cr(struct inet6_dev *idev)
21222122

21232123
static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
21242124
{
2125-
struct net *net = dev_net(dev);
2126-
struct sock *sk = net->ipv6.igmp_sk;
2125+
const struct in6_addr *snd_addr, *saddr;
2126+
int err, len, payload_len, full_len;
2127+
struct in6_addr addr_buf;
21272128
struct inet6_dev *idev;
21282129
struct sk_buff *skb;
21292130
struct mld_msg *hdr;
2130-
const struct in6_addr *snd_addr, *saddr;
2131-
struct in6_addr addr_buf;
21322131
int hlen = LL_RESERVED_SPACE(dev);
21332132
int tlen = dev->needed_tailroom;
2134-
int err, len, payload_len, full_len;
21352133
u8 ra[8] = { IPPROTO_ICMPV6, 0,
21362134
IPV6_TLV_ROUTERALERT, 2, 0, 0,
21372135
IPV6_TLV_PADN, 0 };
2138-
struct flowi6 fl6;
21392136
struct dst_entry *dst;
2137+
struct flowi6 fl6;
2138+
struct net *net;
2139+
struct sock *sk;
21402140

21412141
if (type == ICMPV6_MGM_REDUCTION)
21422142
snd_addr = &in6addr_linklocal_allrouters;
@@ -2147,19 +2147,21 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
21472147
payload_len = len + sizeof(ra);
21482148
full_len = sizeof(struct ipv6hdr) + payload_len;
21492149

2150-
rcu_read_lock();
2151-
IP6_INC_STATS(net, __in6_dev_get(dev), IPSTATS_MIB_OUTREQUESTS);
2152-
rcu_read_unlock();
2150+
skb = alloc_skb(hlen + tlen + full_len, GFP_KERNEL);
21532151

2154-
skb = sock_alloc_send_skb(sk, hlen + tlen + full_len, 1, &err);
2152+
rcu_read_lock();
21552153

2154+
net = dev_net_rcu(dev);
2155+
idev = __in6_dev_get(dev);
2156+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTREQUESTS);
21562157
if (!skb) {
2157-
rcu_read_lock();
2158-
IP6_INC_STATS(net, __in6_dev_get(dev),
2159-
IPSTATS_MIB_OUTDISCARDS);
2158+
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
21602159
rcu_read_unlock();
21612160
return;
21622161
}
2162+
sk = net->ipv6.igmp_sk;
2163+
skb_set_owner_w(skb, sk);
2164+
21632165
skb->priority = TC_PRIO_CONTROL;
21642166
skb_reserve(skb, hlen);
21652167

@@ -2184,9 +2186,6 @@ static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type)
21842186
IPPROTO_ICMPV6,
21852187
csum_partial(hdr, len, 0));
21862188

2187-
rcu_read_lock();
2188-
idev = __in6_dev_get(skb->dev);
2189-
21902189
icmpv6_flow_init(sk, &fl6, type,
21912190
&ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr,
21922191
skb->dev->ifindex);

0 commit comments

Comments
 (0)