Skip to content

Commit 1945ddc

Browse files
Eric DumazetSasha Levin
Eric Dumazet
authored and
Sasha Levin
committed
net: add more sanity checks to qdisc_pkt_len_init()
[ Upstream commit ab9a9a9 ] One path takes care of SKB_GSO_DODGY, assuming skb->len is bigger than hdr_len. virtio_net_hdr_to_skb() does not fully dissect TCP headers, it only make sure it is at least 20 bytes. It is possible for an user to provide a malicious 'GSO' packet, total length of 80 bytes. - 20 bytes of IPv4 header - 60 bytes TCP header - a small gso_size like 8 virtio_net_hdr_to_skb() would declare this packet as a normal GSO packet, because it would see 40 bytes of payload, bigger than gso_size. We need to make detect this case to not underflow qdisc_skb_cb(skb)->pkt_len. Fixes: 1def923 ("net_sched: more precise pkt_len computation") Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent d820aec commit 1945ddc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

net/core/dev.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -3795,10 +3795,14 @@ static void qdisc_pkt_len_init(struct sk_buff *skb)
37953795
hdr_len += sizeof(struct udphdr);
37963796
}
37973797

3798-
if (shinfo->gso_type & SKB_GSO_DODGY)
3799-
gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
3800-
shinfo->gso_size);
3798+
if (unlikely(shinfo->gso_type & SKB_GSO_DODGY)) {
3799+
int payload = skb->len - hdr_len;
38013800

3801+
/* Malicious packet. */
3802+
if (payload <= 0)
3803+
return;
3804+
gso_segs = DIV_ROUND_UP(payload, shinfo->gso_size);
3805+
}
38023806
qdisc_skb_cb(skb)->pkt_len += (gso_segs - 1) * hdr_len;
38033807
}
38043808
}

0 commit comments

Comments
 (0)