Skip to content

Commit 17bd3bd

Browse files
nbd168kuba-moo
authored andcommitted
net: gso: fix tcp fraglist segmentation after pull from frag_list
Detect tcp gso fraglist skbs with corrupted geometry (see below) and pass these to skb_segment instead of skb_segment_list, as the first can segment them correctly. Valid SKB_GSO_FRAGLIST skbs - consist of two or more segments - the head_skb holds the protocol headers plus first gso_size - one or more frag_list skbs hold exactly one segment - all but the last must be gso_size Optional datapath hooks such as NAT and BPF (bpf_skb_pull_data) can modify these skbs, breaking these invariants. In extreme cases they pull all data into skb linear. For TCP, this causes a NULL ptr deref in __tcpv4_gso_segment_list_csum at tcp_hdr(seg->next). Detect invalid geometry due to pull, by checking head_skb size. Don't just drop, as this may blackhole a destination. Convert to be able to pass to regular skb_segment. Approach and description based on a patch by Willem de Bruijn. Link: https://lore.kernel.org/netdev/[email protected]/ Link: https://lore.kernel.org/netdev/[email protected]/ Fixes: bee88cd ("net: add support for segmenting TCP fraglist GSO packets") Cc: [email protected] Signed-off-by: Felix Fietkau <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 854e9bf commit 17bd3bd

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

net/ipv4/tcp_offload.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@ static struct sk_buff *tcp4_gso_segment(struct sk_buff *skb,
101101
if (!pskb_may_pull(skb, sizeof(struct tcphdr)))
102102
return ERR_PTR(-EINVAL);
103103

104-
if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST)
105-
return __tcp4_gso_segment_list(skb, features);
104+
if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST) {
105+
struct tcphdr *th = tcp_hdr(skb);
106+
107+
if (skb_pagelen(skb) - th->doff * 4 == skb_shinfo(skb)->gso_size)
108+
return __tcp4_gso_segment_list(skb, features);
109+
110+
skb->ip_summed = CHECKSUM_NONE;
111+
}
106112

107113
if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
108114
const struct iphdr *iph = ip_hdr(skb);

net/ipv6/tcpv6_offload.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,14 @@ static struct sk_buff *tcp6_gso_segment(struct sk_buff *skb,
159159
if (!pskb_may_pull(skb, sizeof(*th)))
160160
return ERR_PTR(-EINVAL);
161161

162-
if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST)
163-
return __tcp6_gso_segment_list(skb, features);
162+
if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST) {
163+
struct tcphdr *th = tcp_hdr(skb);
164+
165+
if (skb_pagelen(skb) - th->doff * 4 == skb_shinfo(skb)->gso_size)
166+
return __tcp6_gso_segment_list(skb, features);
167+
168+
skb->ip_summed = CHECKSUM_NONE;
169+
}
164170

165171
if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
166172
const struct ipv6hdr *ipv6h = ipv6_hdr(skb);

0 commit comments

Comments
 (0)