Skip to content

Commit a1e40ac

Browse files
wdebruijkuba-moo
authored andcommitted
gso: fix udp gso fraglist segmentation after pull from frag_list
Detect 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 UDP, this causes a NULL ptr deref in __udpv4_gso_segment_list_csum at udp_hdr(seg->next)->dest. 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. Link: https://lore.kernel.org/netdev/[email protected]/ Fixes: 9fd1ff5 ("udp: Support UDP fraglist GRO/GSO.") Signed-off-by: Willem de Bruijn <[email protected]> Cc: [email protected] Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 555f45d commit a1e40ac

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

net/ipv4/udp_offload.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,26 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
296296
return NULL;
297297
}
298298

299-
if (skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST)
300-
return __udp_gso_segment_list(gso_skb, features, is_ipv6);
299+
if (skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST) {
300+
/* Detect modified geometry and pass those to skb_segment. */
301+
if (skb_pagelen(gso_skb) - sizeof(*uh) == skb_shinfo(gso_skb)->gso_size)
302+
return __udp_gso_segment_list(gso_skb, features, is_ipv6);
303+
304+
/* Setup csum, as fraglist skips this in udp4_gro_receive. */
305+
gso_skb->csum_start = skb_transport_header(gso_skb) - gso_skb->head;
306+
gso_skb->csum_offset = offsetof(struct udphdr, check);
307+
gso_skb->ip_summed = CHECKSUM_PARTIAL;
308+
309+
uh = udp_hdr(gso_skb);
310+
if (is_ipv6)
311+
uh->check = ~udp_v6_check(gso_skb->len,
312+
&ipv6_hdr(gso_skb)->saddr,
313+
&ipv6_hdr(gso_skb)->daddr, 0);
314+
else
315+
uh->check = ~udp_v4_check(gso_skb->len,
316+
ip_hdr(gso_skb)->saddr,
317+
ip_hdr(gso_skb)->daddr, 0);
318+
}
301319

302320
skb_pull(gso_skb, sizeof(*uh));
303321

0 commit comments

Comments
 (0)