Skip to content

Commit d5be7f6

Browse files
wdebruijdavem330
authored andcommitted
net: validate untrusted gso packets without csum offload
Syzkaller again found a path to a kernel crash through bad gso input. By building an excessively large packet to cause an skb field to wrap. If VIRTIO_NET_HDR_F_NEEDS_CSUM was set this would have been dropped in skb_partial_csum_set. GSO packets that do not set checksum offload are suspicious and rare. Most callers of virtio_net_hdr_to_skb already pass them to skb_probe_transport_header. Move that test forward, change it to detect parse failure and drop packets on failure as those cleary are not one of the legitimate VIRTIO_NET_HDR_GSO types. Fixes: bfd5f4a ("packet: Add GSO/csum offload support.") Fixes: f43798c ("tun: Allow GSO using virtio_net_hdr") Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3b89ea9 commit d5be7f6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/linux/skbuff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2434,7 +2434,7 @@ static inline void skb_probe_transport_header(struct sk_buff *skb,
24342434

24352435
if (skb_flow_dissect_flow_keys_basic(skb, &keys, NULL, 0, 0, 0, 0))
24362436
skb_set_transport_header(skb, keys.control.thoff);
2437-
else
2437+
else if (offset_hint >= 0)
24382438
skb_set_transport_header(skb, offset_hint);
24392439
}
24402440

include/linux/virtio_net.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
5757

5858
if (!skb_partial_csum_set(skb, start, off))
5959
return -EINVAL;
60+
} else {
61+
/* gso packets without NEEDS_CSUM do not set transport_offset.
62+
* probe and drop if does not match one of the above types.
63+
*/
64+
if (gso_type) {
65+
skb_probe_transport_header(skb, -1);
66+
if (!skb_transport_header_was_set(skb))
67+
return -EINVAL;
68+
}
6069
}
6170

6271
if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {

0 commit comments

Comments
 (0)