Skip to content

Commit 2d5ff7e

Browse files
Eric Dumazetkuba-moo
Eric Dumazet
authored andcommitted
ipv6: prevent possible UAF in ip6_xmit()
If skb_expand_head() returns NULL, skb has been freed and the associated dst/idev could also have been freed. We must use rcu_read_lock() to prevent a possible UAF. Fixes: 0c9f227 ("ipv6: use skb_expand_head in ip6_xmit") 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 da273b3 commit 2d5ff7e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/ipv6/ip6_output.c

+4
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,15 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
287287
head_room += opt->opt_nflen + opt->opt_flen;
288288

289289
if (unlikely(head_room > skb_headroom(skb))) {
290+
/* Make sure idev stays alive */
291+
rcu_read_lock();
290292
skb = skb_expand_head(skb, head_room);
291293
if (!skb) {
292294
IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
295+
rcu_read_unlock();
293296
return -ENOBUFS;
294297
}
298+
rcu_read_unlock();
295299
}
296300

297301
if (opt) {

0 commit comments

Comments
 (0)