Skip to content

Commit bbd6528

Browse files
edumazetdavem330
authored andcommitted
ipv6: fix possible use-after-free in ip6_xmit()
In the unlikely case ip6_xmit() has to call skb_realloc_headroom(), we need to call skb_set_owner_w() before consuming original skb, otherwise we risk a use-after-free. Bring IPv6 in line with what we do in IPv4 to fix this. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a7f3800 commit bbd6528

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

net/ipv6/ip6_output.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,10 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
219219
kfree_skb(skb);
220220
return -ENOBUFS;
221221
}
222+
if (skb->sk)
223+
skb_set_owner_w(skb2, skb->sk);
222224
consume_skb(skb);
223225
skb = skb2;
224-
/* skb_set_owner_w() changes sk->sk_wmem_alloc atomically,
225-
* it is safe to call in our context (socket lock not held)
226-
*/
227-
skb_set_owner_w(skb, (struct sock *)sk);
228226
}
229227
if (opt->opt_flen)
230228
ipv6_push_frag_opts(skb, opt, &proto);

0 commit comments

Comments
 (0)