Guard against gso_segs overflows
Subsystems (4)
v3 cover Guard against gso_segs overflows
From: Alice Mikityanska <[email protected]>
This series is a follow-up on the discussion:
skb_segment is patched to avoid possible overflows in partial GSO. The primary possible source of too many GSO segments is also addressed:
virtio-net clamps gso_size to >=8 in TCP, as suggested by Eric.
v3 changes: Reordered the patches, added WARN to skb_segment.
v2: https://lore.kernel.org/netdev/[email protected]/
v2 changes: dropped new checks in fastpath from skb_gro_receive and __virtio_net_hdr_to_skb, replaced the latter with a silent clamp for gso_size, kept the cheap guard in skb_segment.
v1: https://lore.kernel.org/netdev/[email protected]/
Alice Mikityanska (2):
virtio-net: Ensure that TCP packets don't overflow gso_segs
net: Guard for gso_segs overflow in skb_segment
include/linux/virtio_net.h | 4 ++++ net/core/skbuff.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.55.0
PATCH v3 1/2 virtio-net: Ensure that TCP packets don't overflow gso_segs
From: Alice Mikityanska <[email protected]>
The user can specify any gso_size in a packet crafted with an AF_PACKET PACKET_VNET_HDR socket, even smaller than TCP_MIN_GSO_SIZE = 8. At the same time, GSO_MAX_SIZE = 8 * GSO_MAX_SEGS = 8 * 65535. When the user crafts a packet with gso_size < 8, there is a risk for partial GSO to overflow the 16-bit gso_segs field when dividing the SKB length by gso_size.
Adjust gso_size of TCP packets to be at least TCP_MIN_GSO_SIZE = 8. Keep gso_size of UDP GSO packets, as gso_size=1 is valid and explicitly tested at tools/testing/selftests/net/tun.c:649.
--- include/linux/virtio_net.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/virtio_net.h +4 -0
@@ -6,6 +6,7 @@#include <linux/ip.h> #include <linux/ipv6.h> #include <linux/udp.h> +#include <net/tcp.h> #include <uapi/linux/tcp.h> #include <uapi/linux/virtio_net.h>
@@ -179,6 +180,9 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,if (skb->ip_summed ==CHECKSUM_PARTIAL && skb->csum_offset != offsetof(struct tcphdr , check))return -EINVAL ; + +BUILD_BUG_ON (TCP_MIN_GSO_SIZE *GSO_MAX_SEGS <GSO_MAX_SIZE ); + gso_size =max (gso_size,TCP_MIN_GSO_SIZE );break ; }
Signature · 1 line
2.55.0
PATCH v3 2/2 net: Guard for gso_segs overflow in skb_segment
In reply to Alice MikityanskaFrom: Alice Mikityanska <[email protected]>
skb_segment calculates 32-bit partial_segs as len / gso_size, and then assigns it to the 16-bit gso_segs field. The division might overflow in some edge cases where the SKB is BIG TCP (65536 <= len <= 8*65535), and gso_size < TCP_MIN_GSO_SIZE = 8. While normally this can't happen due to TCP_MIN_GSO_SIZE, an AF_PACKET PACKET_VNET_HDR socket could generate such a malformed packet until the previous patch.
Blocking malformed virtio_net packets was implemented in the previous patch, but this patch clamps partial_segs in skb_segment itself for more generic robustness. Should len / gso_size happen to be bigger than 65535 in partial GSO, skb_segment will now just produce more than two output SKBs, all of which will be valid with gso_segs <= 65535.
In order to catch possible other cases of too many partial_segs, add a DEBUG_NET_WARN_ON_ONCE when len / gso_size happens to be too big.
--- net/core/skbuff.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/skbuff.c +2 -1
@@ -4871,7 +4871,8 @@ struct sk_buff *skb_segment(struct sk_buff *head_skb,* doesn't fit into an MSS sized block, so take care of that * now. */ - partial_segs = len / mss; +DEBUG_NET_WARN_ON_ONCE (len / mss >GSO_MAX_SEGS ); + partial_segs =min (len / mss,GSO_MAX_SEGS );if (partial_segs >1 ) mss *= partial_segs;else
Signature · 1 line
2.55.0
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Sat, 22 Aug 2026 15:01:15 +0300 you wrote:
From: Alice Mikityanska <[email protected]>
This series is a follow-up on the discussion:
skb_segmentis patched to avoid possible overflows in partial GSO. The primary possible source of too many GSO segments is also addressed:
virtio-net clampsgso_sizeto >=8 in TCP, as suggested by Eric.[...]
Here is the summary with links:
- [net,v3,1/2] virtio-net: Ensure that TCP packets don't overflow gso_segs
https://git.kernel.org/netdev/net/c/c27c449d455a - [net,v3,2/2] net: Guard for gso_segs overflow in skb_segment https://git.kernel.org/netdev/net/c/0b13256ce37b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html