[PATCH net] net: check untrusted gso_size at kernel entry

5 views
Skip to first unread message

Willem de Bruijn

unread,
May 25, 2020, 3:07:46 PM5/25/20
to net...@vger.kernel.org, da...@davemloft.net, Willem de Bruijn, syzbot
From: Willem de Bruijn <wil...@google.com>

Syzkaller again found a path to a kernel crash through bad gso input:
a packet with gso size exceeding len.

These packets are dropped in tcp_gso_segment and udp[46]_ufo_fragment.
But they may affect gso size calculations earlier in the path.

Now that we have thlen as of commit 9274124f023b ("net: stricter
validation of untrusted gso packets"), check gso_size at entry too.

Fixes: bfd5f4a3d605 ("packet: Add GSO/csum offload support.")
Reported-by: syzbot <syzk...@googlegroups.com>
Signed-off-by: Willem de Bruijn <wil...@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 6f6ade63b04c..88997022a4b5 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -31,6 +31,7 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
{
unsigned int gso_type = 0;
unsigned int thlen = 0;
+ unsigned int p_off = 0;
unsigned int ip_proto;

if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
@@ -68,7 +69,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
if (!skb_partial_csum_set(skb, start, off))
return -EINVAL;

- if (skb_transport_offset(skb) + thlen > skb_headlen(skb))
+ p_off = skb_transport_offset(skb) + thlen;
+ if (p_off > skb_headlen(skb))
return -EINVAL;
} else {
/* gso packets without NEEDS_CSUM do not set transport_offset.
@@ -92,17 +94,25 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
return -EINVAL;
}

- if (keys.control.thoff + thlen > skb_headlen(skb) ||
+ p_off = keys.control.thoff + thlen;
+ if (p_off > skb_headlen(skb) ||
keys.basic.ip_proto != ip_proto)
return -EINVAL;

skb_set_transport_header(skb, keys.control.thoff);
+ } else if (gso_type) {
+ p_off = thlen;
+ if (p_off > skb_headlen(skb))
+ return -EINVAL;
}
}

if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
u16 gso_size = __virtio16_to_cpu(little_endian, hdr->gso_size);

+ if (skb->len - p_off <= gso_size)
+ return -EINVAL;
+
skb_shinfo(skb)->gso_size = gso_size;
skb_shinfo(skb)->gso_type = gso_type;

--
2.27.0.rc0.183.gde8f92d652-goog

David Miller

unread,
May 26, 2020, 11:25:26 PM5/26/20
to willemdebr...@gmail.com, net...@vger.kernel.org, wil...@google.com, syzk...@googlegroups.com
From: Willem de Bruijn <willemdebr...@gmail.com>
Date: Mon, 25 May 2020 15:07:40 -0400

> From: Willem de Bruijn <wil...@google.com>
>
> Syzkaller again found a path to a kernel crash through bad gso input:
> a packet with gso size exceeding len.
>
> These packets are dropped in tcp_gso_segment and udp[46]_ufo_fragment.
> But they may affect gso size calculations earlier in the path.
>
> Now that we have thlen as of commit 9274124f023b ("net: stricter
> validation of untrusted gso packets"), check gso_size at entry too.
>
> Fixes: bfd5f4a3d605 ("packet: Add GSO/csum offload support.")
> Reported-by: syzbot <syzk...@googlegroups.com>
> Signed-off-by: Willem de Bruijn <wil...@google.com>

Applied and queued up for -stable, thanks Willem.

Sasha Levin

unread,
Jun 5, 2020, 8:25:27 AM6/5/20
to linux-...@vger.kernel.org, sta...@vger.kernel.org, Willem de Bruijn, syzbot, David S . Miller, Sasha Levin, virtual...@lists.linux-foundation.org
From: Willem de Bruijn <wil...@google.com>

[ Upstream commit 6dd912f82680761d8fb6b1bb274a69d4c7010988 ]

Syzkaller again found a path to a kernel crash through bad gso input:
a packet with gso size exceeding len.

These packets are dropped in tcp_gso_segment and udp[46]_ufo_fragment.
But they may affect gso size calculations earlier in the path.

Now that we have thlen as of commit 9274124f023b ("net: stricter
validation of untrusted gso packets"), check gso_size at entry too.

Fixes: bfd5f4a3d605 ("packet: Add GSO/csum offload support.")
Reported-by: syzbot <syzk...@googlegroups.com>
Signed-off-by: Willem de Bruijn <wil...@google.com>
Signed-off-by: David S. Miller <da...@davemloft.net>
Signed-off-by: Sasha Levin <sas...@kernel.org>
2.25.1

Sasha Levin

unread,
Jun 5, 2020, 8:25:49 AM6/5/20
to linux-...@vger.kernel.org, sta...@vger.kernel.org, Willem de Bruijn, syzbot, David S . Miller, Sasha Levin, virtual...@lists.linux-foundation.org

Sasha Levin

unread,
Jun 5, 2020, 8:26:04 AM6/5/20
to linux-...@vger.kernel.org, sta...@vger.kernel.org, Willem de Bruijn, syzbot, David S . Miller, Sasha Levin, virtual...@lists.linux-foundation.org
From: Willem de Bruijn <wil...@google.com>

[ Upstream commit 6dd912f82680761d8fb6b1bb274a69d4c7010988 ]

Syzkaller again found a path to a kernel crash through bad gso input:
a packet with gso size exceeding len.

These packets are dropped in tcp_gso_segment and udp[46]_ufo_fragment.
But they may affect gso size calculations earlier in the path.

Now that we have thlen as of commit 9274124f023b ("net: stricter
validation of untrusted gso packets"), check gso_size at entry too.

Fixes: bfd5f4a3d605 ("packet: Add GSO/csum offload support.")
Reported-by: syzbot <syzk...@googlegroups.com>
Signed-off-by: Willem de Bruijn <wil...@google.com>
Signed-off-by: David S. Miller <da...@davemloft.net>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
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 f36727098df8..1c296f370e46 100644

Sasha Levin

unread,
Jun 5, 2020, 8:26:15 AM6/5/20
to linux-...@vger.kernel.org, sta...@vger.kernel.org, Willem de Bruijn, syzbot, David S . Miller, Sasha Levin, virtual...@lists.linux-foundation.org
From: Willem de Bruijn <wil...@google.com>

[ Upstream commit 6dd912f82680761d8fb6b1bb274a69d4c7010988 ]

Syzkaller again found a path to a kernel crash through bad gso input:
a packet with gso size exceeding len.

These packets are dropped in tcp_gso_segment and udp[46]_ufo_fragment.
But they may affect gso size calculations earlier in the path.

Now that we have thlen as of commit 9274124f023b ("net: stricter
validation of untrusted gso packets"), check gso_size at entry too.

Fixes: bfd5f4a3d605 ("packet: Add GSO/csum offload support.")
Reported-by: syzbot <syzk...@googlegroups.com>
Signed-off-by: Willem de Bruijn <wil...@google.com>
Signed-off-by: David S. Miller <da...@davemloft.net>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
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 44e20c4b5141..a16e0bdf7751 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -31,6 +31,7 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
{
unsigned int gso_type = 0;
unsigned int thlen = 0;
+ unsigned int p_off = 0;
unsigned int ip_proto;

if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
@@ -68,7 +69,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
if (!skb_partial_csum_set(skb, start, off))
return -EINVAL;

- if (skb_transport_offset(skb) + thlen > skb_headlen(skb))
+ p_off = skb_transport_offset(skb) + thlen;
+ if (p_off > skb_headlen(skb))
return -EINVAL;
} else {
/* gso packets without NEEDS_CSUM do not set transport_offset.
@@ -90,17 +92,25 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,

Greg Kroah-Hartman

unread,
Jun 9, 2020, 1:50:00 PM6/9/20
to linux-...@vger.kernel.org, Greg Kroah-Hartman, sta...@vger.kernel.org, syzbot, Willem de Bruijn, David S. Miller
From: Willem de Bruijn <wil...@google.com>

[ Upstream commit 6dd912f82680761d8fb6b1bb274a69d4c7010988 ]

Syzkaller again found a path to a kernel crash through bad gso input:
a packet with gso size exceeding len.

These packets are dropped in tcp_gso_segment and udp[46]_ufo_fragment.
But they may affect gso size calculations earlier in the path.

Now that we have thlen as of commit 9274124f023b ("net: stricter
validation of untrusted gso packets"), check gso_size at entry too.

Fixes: bfd5f4a3d605 ("packet: Add GSO/csum offload support.")
Reported-by: syzbot <syzk...@googlegroups.com>
Signed-off-by: Willem de Bruijn <wil...@google.com>
Signed-off-by: David S. Miller <da...@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
---
include/linux/virtio_net.h | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -31,6 +31,7 @@ static inline int virtio_net_hdr_to_skb(
{
unsigned int gso_type = 0;
unsigned int thlen = 0;
+ unsigned int p_off = 0;
unsigned int ip_proto;

if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
@@ -68,7 +69,8 @@ static inline int virtio_net_hdr_to_skb(
if (!skb_partial_csum_set(skb, start, off))
return -EINVAL;

- if (skb_transport_offset(skb) + thlen > skb_headlen(skb))
+ p_off = skb_transport_offset(skb) + thlen;
+ if (p_off > skb_headlen(skb))
return -EINVAL;
} else {
/* gso packets without NEEDS_CSUM do not set transport_offset.
@@ -90,17 +92,25 @@ retry:

Greg Kroah-Hartman

unread,
Jun 9, 2020, 1:51:51 PM6/9/20
to linux-...@vger.kernel.org, Greg Kroah-Hartman, sta...@vger.kernel.org, syzbot, Willem de Bruijn, David S. Miller
@@ -92,17 +94,25 @@ retry:

Greg Kroah-Hartman

unread,
Jun 9, 2020, 1:52:07 PM6/9/20
to linux-...@vger.kernel.org, Greg Kroah-Hartman, sta...@vger.kernel.org, syzbot, Willem de Bruijn, David S. Miller

Greg Kroah-Hartman

unread,
Jun 9, 2020, 1:53:29 PM6/9/20
to linux-...@vger.kernel.org, Greg Kroah-Hartman, sta...@vger.kernel.org, syzbot, Willem de Bruijn, David S. Miller
Reply all
Reply to author
Forward
0 new messages