Skip to content

Commit 232cd35

Browse files
Eric Dumazetdavem330
Eric Dumazet
authored andcommitted
ipv6: fix out of bound writes in __ip6_append_data()
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>
1 parent 6d18c73 commit 232cd35

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Diff for: net/ipv6/ip6_output.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,11 @@ static int __ip6_append_data(struct sock *sk,
14661466
*/
14671467
alloclen += sizeof(struct frag_hdr);
14681468

1469+
copy = datalen - transhdrlen - fraggap;
1470+
if (copy < 0) {
1471+
err = -EINVAL;
1472+
goto error;
1473+
}
14691474
if (transhdrlen) {
14701475
skb = sock_alloc_send_skb(sk,
14711476
alloclen + hh_len,
@@ -1515,13 +1520,9 @@ static int __ip6_append_data(struct sock *sk,
15151520
data += fraggap;
15161521
pskb_trim_unique(skb_prev, maxfraglen);
15171522
}
1518-
copy = datalen - transhdrlen - fraggap;
1519-
1520-
if (copy < 0) {
1521-
err = -EINVAL;
1522-
kfree_skb(skb);
1523-
goto error;
1524-
} else if (copy > 0 && getfrag(from, data + transhdrlen, offset, copy, fraggap, skb) < 0) {
1523+
if (copy > 0 &&
1524+
getfrag(from, data + transhdrlen, offset,
1525+
copy, fraggap, skb) < 0) {
15251526
err = -EFAULT;
15261527
kfree_skb(skb);
15271528
goto error;

0 commit comments

Comments
 (0)