Skip to content

Commit 9e8db59

Browse files
wdebruijdavem330
authored andcommitted
net: avoid false positives in untrusted gso validation
GSO packets with vnet_hdr must conform to a small set of gso_types. The below commit uses flow dissection to drop packets that do not. But it has false positives when the skb is not fully initialized. Dissection needs skb->protocol and skb->network_header. Infer skb->protocol from gso_type as the two must agree. SKB_GSO_UDP can use both ipv4 and ipv6, so try both. Exclude callers for which network header offset is not known. Fixes: d5be7f6 ("net: validate untrusted gso packets without csum offload") Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 06cd170 commit 9e8db59

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

include/linux/virtio_net.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,20 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
6161
/* gso packets without NEEDS_CSUM do not set transport_offset.
6262
* probe and drop if does not match one of the above types.
6363
*/
64-
if (gso_type) {
64+
if (gso_type && skb->network_header) {
65+
if (!skb->protocol)
66+
virtio_net_hdr_set_proto(skb, hdr);
67+
retry:
6568
skb_probe_transport_header(skb, -1);
66-
if (!skb_transport_header_was_set(skb))
69+
if (!skb_transport_header_was_set(skb)) {
70+
/* UFO does not specify ipv4 or 6: try both */
71+
if (gso_type & SKB_GSO_UDP &&
72+
skb->protocol == htons(ETH_P_IP)) {
73+
skb->protocol = htons(ETH_P_IPV6);
74+
goto retry;
75+
}
6776
return -EINVAL;
77+
}
6878
}
6979
}
7080

0 commit comments

Comments
 (0)