netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: accept UFOv6 packages in virtio_net_hdr_to_skb
@ 2021-12-20 14:49 Willem de Bruijn
  2021-12-21  3:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Willem de Bruijn @ 2021-12-20 14:49 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, nemeth, Willem de Bruijn, Andrew Melnichenko

From: Willem de Bruijn <willemb@google.com>

Skb with skb->protocol 0 at the time of virtio_net_hdr_to_skb may have
a protocol inferred from virtio_net_hdr with virtio_net_hdr_set_proto.

Unlike TCP, UDP does not have separate types for IPv4 and IPv6. Type
VIRTIO_NET_HDR_GSO_UDP is guessed to be IPv4/UDP. As of the below
commit, UFOv6 packets are dropped due to not matching the protocol as
obtained from dev_parse_header_protocol.

Invert the test to take that L2 protocol field as starting point and
pass both UFOv4 and UFOv6 for VIRTIO_NET_HDR_GSO_UDP.

Fixes: 924a9bc362a5 ("net: check if protocol extracted by virtio_net_hdr_set_proto is correct")
Link: https://lore.kernel.org/netdev/CABcq3pG9GRCYqFDBAJ48H1vpnnX=41u+MhQnayF1ztLH4WX0Fw@mail.gmail.com/
Reported-by: Andrew Melnichenko <andrew@daynix.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 include/linux/virtio_net.h | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 04e87f4b9417..22dd48c82560 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -7,6 +7,21 @@
 #include <uapi/linux/udp.h>
 #include <uapi/linux/virtio_net.h>
 
+static inline bool virtio_net_hdr_match_proto(__be16 protocol, __u8 gso_type)
+{
+	switch (gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
+	case VIRTIO_NET_HDR_GSO_TCPV4:
+		return protocol == cpu_to_be16(ETH_P_IP);
+	case VIRTIO_NET_HDR_GSO_TCPV6:
+		return protocol == cpu_to_be16(ETH_P_IPV6);
+	case VIRTIO_NET_HDR_GSO_UDP:
+		return protocol == cpu_to_be16(ETH_P_IP) ||
+		       protocol == cpu_to_be16(ETH_P_IPV6);
+	default:
+		return false;
+	}
+}
+
 static inline int virtio_net_hdr_set_proto(struct sk_buff *skb,
 					   const struct virtio_net_hdr *hdr)
 {
@@ -88,9 +103,12 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
 			if (!skb->protocol) {
 				__be16 protocol = dev_parse_header_protocol(skb);
 
-				virtio_net_hdr_set_proto(skb, hdr);
-				if (protocol && protocol != skb->protocol)
+				if (!protocol)
+					virtio_net_hdr_set_proto(skb, hdr);
+				else if (!virtio_net_hdr_match_proto(protocol, hdr->gso_type))
 					return -EINVAL;
+				else
+					skb->protocol = protocol;
 			}
 retry:
 			if (!skb_flow_dissect_flow_keys_basic(NULL, skb, &keys,
-- 
2.34.1.173.g76aa8bc2d0-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net: accept UFOv6 packages in virtio_net_hdr_to_skb
  2021-12-20 14:49 [PATCH net] net: accept UFOv6 packages in virtio_net_hdr_to_skb Willem de Bruijn
@ 2021-12-21  3:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-21  3:10 UTC (permalink / raw)
  To: Willem de Bruijn; +Cc: netdev, davem, kuba, nemeth, willemb, andrew

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 20 Dec 2021 09:49:01 -0500 you wrote:
> From: Willem de Bruijn <willemb@google.com>
> 
> Skb with skb->protocol 0 at the time of virtio_net_hdr_to_skb may have
> a protocol inferred from virtio_net_hdr with virtio_net_hdr_set_proto.
> 
> Unlike TCP, UDP does not have separate types for IPv4 and IPv6. Type
> VIRTIO_NET_HDR_GSO_UDP is guessed to be IPv4/UDP. As of the below
> commit, UFOv6 packets are dropped due to not matching the protocol as
> obtained from dev_parse_header_protocol.
> 
> [...]

Here is the summary with links:
  - [net] net: accept UFOv6 packages in virtio_net_hdr_to_skb
    https://git.kernel.org/netdev/net/c/7e5cced9ca84

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-21  3:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-20 14:49 [PATCH net] net: accept UFOv6 packages in virtio_net_hdr_to_skb Willem de Bruijn
2021-12-21  3:10 ` patchwork-bot+netdevbpf

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).