Skip to content

Commit 9840036

Browse files
Yan Zhaidavem330
authored andcommitted
gso: fix dodgy bit handling for GSO_UDP_L4
Commit 1fd5477 ("udp: allow header check for dodgy GSO_UDP_L4 packets.") checks DODGY bit for UDP, but for packets that can be fed directly to the device after gso_segs reset, it actually falls through to fragmentation: https://lore.kernel.org/all/CAJPywTKDdjtwkLVUW6LRA2FU912qcDmQOQGt2WaDo28KzYDg+A@mail.gmail.com/ This change restores the expected behavior of GSO_UDP_L4 packets. Fixes: 1fd5477 ("udp: allow header check for dodgy GSO_UDP_L4 packets.") Suggested-by: Willem de Bruijn <[email protected]> Signed-off-by: Yan Zhai <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Acked-by: Jason Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a822551 commit 9840036

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

net/ipv4/udp_offload.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,20 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
274274
__sum16 check;
275275
__be16 newlen;
276276

277-
if (skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST)
278-
return __udp_gso_segment_list(gso_skb, features, is_ipv6);
279-
280277
mss = skb_shinfo(gso_skb)->gso_size;
281278
if (gso_skb->len <= sizeof(*uh) + mss)
282279
return ERR_PTR(-EINVAL);
283280

281+
if (skb_gso_ok(gso_skb, features | NETIF_F_GSO_ROBUST)) {
282+
/* Packet is from an untrusted source, reset gso_segs. */
283+
skb_shinfo(gso_skb)->gso_segs = DIV_ROUND_UP(gso_skb->len - sizeof(*uh),
284+
mss);
285+
return NULL;
286+
}
287+
288+
if (skb_shinfo(gso_skb)->gso_type & SKB_GSO_FRAGLIST)
289+
return __udp_gso_segment_list(gso_skb, features, is_ipv6);
290+
284291
skb_pull(gso_skb, sizeof(*uh));
285292

286293
/* clear destructor to avoid skb_segment assigning it to tail */
@@ -388,8 +395,7 @@ static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb,
388395
if (!pskb_may_pull(skb, sizeof(struct udphdr)))
389396
goto out;
390397

391-
if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 &&
392-
!skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST))
398+
if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4)
393399
return __udp_gso_segment(skb, features, false);
394400

395401
mss = skb_shinfo(skb)->gso_size;

net/ipv6/udp_offload.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb,
4343
if (!pskb_may_pull(skb, sizeof(struct udphdr)))
4444
goto out;
4545

46-
if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 &&
47-
!skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST))
46+
if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4)
4847
return __udp_gso_segment(skb, features, true);
4948

5049
mss = skb_shinfo(skb)->gso_size;

0 commit comments

Comments
 (0)