Skip to content

Commit 628e6d1

Browse files
edumazetkuba-moo
authored andcommitted
ndisc: use RCU protection in ndisc_alloc_skb()
ndisc_alloc_skb() can be called without RTNL or RCU being held. Add RCU protection to avoid possible UAF. Fixes: de09334 ("ndisc: Introduce ndisc_alloc_skb() helper.") Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: David Ahern <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 48145a5 commit 628e6d1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

net/ipv6/ndisc.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,11 @@ static struct sk_buff *ndisc_alloc_skb(struct net_device *dev,
418418
{
419419
int hlen = LL_RESERVED_SPACE(dev);
420420
int tlen = dev->needed_tailroom;
421-
struct sock *sk = dev_net(dev)->ipv6.ndisc_sk;
422421
struct sk_buff *skb;
423422

424423
skb = alloc_skb(hlen + sizeof(struct ipv6hdr) + len + tlen, GFP_ATOMIC);
425-
if (!skb) {
426-
ND_PRINTK(0, err, "ndisc: %s failed to allocate an skb\n",
427-
__func__);
424+
if (!skb)
428425
return NULL;
429-
}
430426

431427
skb->protocol = htons(ETH_P_IPV6);
432428
skb->dev = dev;
@@ -437,7 +433,9 @@ static struct sk_buff *ndisc_alloc_skb(struct net_device *dev,
437433
/* Manually assign socket ownership as we avoid calling
438434
* sock_alloc_send_pskb() to bypass wmem buffer limits
439435
*/
440-
skb_set_owner_w(skb, sk);
436+
rcu_read_lock();
437+
skb_set_owner_w(skb, dev_net_rcu(dev)->ipv6.ndisc_sk);
438+
rcu_read_unlock();
441439

442440
return skb;
443441
}

0 commit comments

Comments
 (0)