Skip to content

Commit da273b3

Browse files
Eric Dumazetkuba-moo
authored andcommitted
ipv6: fix possible UAF in ip6_finish_output2()
If skb_expand_head() returns NULL, skb has been freed and associated dst/idev could also have been freed. We need to hold rcu_read_lock() to make sure the dst and associated idev are alive. Fixes: 5796015 ("ipv6: allocate enough headroom in ip6_finish_output2()") Signed-off-by: Eric Dumazet <[email protected]> Cc: Vasily Averin <[email protected]> Reviewed-by: David Ahern <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent faa389b commit da273b3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/ipv6/ip6_output.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
7070

7171
/* Be paranoid, rather than too clever. */
7272
if (unlikely(hh_len > skb_headroom(skb)) && dev->header_ops) {
73+
/* Make sure idev stays alive */
74+
rcu_read_lock();
7375
skb = skb_expand_head(skb, hh_len);
7476
if (!skb) {
7577
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
78+
rcu_read_unlock();
7679
return -ENOMEM;
7780
}
81+
rcu_read_unlock();
7882
}
7983

8084
hdr = ipv6_hdr(skb);

0 commit comments

Comments
 (0)