* [PATCH net] net: avoid false positives in untrusted gso validation
@ 2019-02-19 4:37 Willem de Bruijn
2019-02-21 22:08 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Willem de Bruijn @ 2019-02-19 4:37 UTC (permalink / raw)
To: netdev; +Cc: davem, Willem de Bruijn
From: Willem de Bruijn <willemb@google.com>
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: d5be7f632bad ("net: validate untrusted gso packets without csum offload")
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
include/linux/virtio_net.h | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 71f2394abbf7..e0348cb0a1dd 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -61,10 +61,20 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
/* gso packets without NEEDS_CSUM do not set transport_offset.
* probe and drop if does not match one of the above types.
*/
- if (gso_type) {
+ if (gso_type && skb->network_header) {
+ if (!skb->protocol)
+ virtio_net_hdr_set_proto(skb, hdr);
+retry:
skb_probe_transport_header(skb, -1);
- if (!skb_transport_header_was_set(skb))
+ if (!skb_transport_header_was_set(skb)) {
+ /* UFO does not specify ipv4 or 6: try both */
+ if (gso_type & SKB_GSO_UDP &&
+ skb->protocol == htons(ETH_P_IP)) {
+ skb->protocol = htons(ETH_P_IPV6);
+ goto retry;
+ }
return -EINVAL;
+ }
}
}
--
2.21.0.rc0.258.g878e2cd30e-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: avoid false positives in untrusted gso validation
2019-02-19 4:37 [PATCH net] net: avoid false positives in untrusted gso validation Willem de Bruijn
@ 2019-02-21 22:08 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-02-21 22:08 UTC (permalink / raw)
To: willemdebruijn.kernel; +Cc: netdev, willemb
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: Mon, 18 Feb 2019 23:37:12 -0500
> From: Willem de Bruijn <willemb@google.com>
>
> 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: d5be7f632bad ("net: validate untrusted gso packets without csum offload")
> Signed-off-by: Willem de Bruijn <willemb@google.com>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-21 22:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-19 4:37 [PATCH net] net: avoid false positives in untrusted gso validation Willem de Bruijn
2019-02-21 22:08 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).