Skip to content

Commit 38f02f2

Browse files
edumazetgregkh
authored andcommitted
ipv6: fix out of bound writes in __ip6_append_data()
[ Upstream commit 232cd35d0804cc241eb887bb8d4d9b3b9881c64a ] Andrey Konovalov and idaifish@gmail.com reported crashes caused by one skb shared_info being overwritten from __ip6_append_data() Andrey program lead to following state : copy -4200 datalen 2000 fraglen 2040 maxfraglen 2040 alloclen 2048 transhdrlen 0 offset 0 fraggap 6200 The skb_copy_and_csum_bits(skb_prev, maxfraglen, data + transhdrlen, fraggap, 0); is overwriting skb->head and skb_shared_info Since we apparently detect this rare condition too late, move the code earlier to even avoid allocating skb and risking crashes. Once again, many thanks to Andrey and syzkaller team. Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Andrey Konovalov <andreyknvl@google.com> Tested-by: Andrey Konovalov <andreyknvl@google.com> Reported-by: <idaifish@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3a85421 commit 38f02f2

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

net/ipv6/ip6_output.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,11 @@ static int __ip6_append_data(struct sock *sk,
14321432
*/
14331433
alloclen += sizeof(struct frag_hdr);
14341434

1435+
copy = datalen - transhdrlen - fraggap;
1436+
if (copy < 0) {
1437+
err = -EINVAL;
1438+
goto error;
1439+
}
14351440
if (transhdrlen) {
14361441
skb = sock_alloc_send_skb(sk,
14371442
alloclen + hh_len,
@@ -1481,13 +1486,9 @@ static int __ip6_append_data(struct sock *sk,
14811486
data += fraggap;
14821487
pskb_trim_unique(skb_prev, maxfraglen);
14831488
}
1484-
copy = datalen - transhdrlen - fraggap;
1485-
1486-
if (copy < 0) {
1487-
err = -EINVAL;
1488-
kfree_skb(skb);
1489-
goto error;
1490-
} else if (copy > 0 && getfrag(from, data + transhdrlen, offset, copy, fraggap, skb) < 0) {
1489+
if (copy > 0 &&
1490+
getfrag(from, data + transhdrlen, offset,
1491+
copy, fraggap, skb) < 0) {
14911492
err = -EFAULT;
14921493
kfree_skb(skb);
14931494
goto error;

0 commit comments

Comments
 (0)