Commit 82a01ab3 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

tcp: gso: really support BIG TCP

We missed that tcp_gso_segment() was assuming skb->len was smaller than 65535 :

oldlen = (u16)~skb->len;

This part came with commit 0718bcc0 ("[NET]: Fix CHECKSUM_HW GSO problems.")

This leads to wrong TCP checksum.

Adapt the code to accept arbitrary packet length.

v2:
  - use two csum_add() instead of csum_fold() (Alexander Duyck)
  - Change delta type to __wsum to reduce casts (Alexander Duyck)

Fixes: 09f3d1a3 ("ipv6/gso: remove temporary HBH/jumbo header")
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarAlexander Duyck <alexanderduyck@fb.com>
Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
Link: https://lore.kernel.org/r/20230605161647.3624428-1-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent a2f4c143
...@@ -60,12 +60,12 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, ...@@ -60,12 +60,12 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
struct tcphdr *th; struct tcphdr *th;
unsigned int thlen; unsigned int thlen;
unsigned int seq; unsigned int seq;
__be32 delta;
unsigned int oldlen; unsigned int oldlen;
unsigned int mss; unsigned int mss;
struct sk_buff *gso_skb = skb; struct sk_buff *gso_skb = skb;
__sum16 newcheck; __sum16 newcheck;
bool ooo_okay, copy_destructor; bool ooo_okay, copy_destructor;
__wsum delta;
th = tcp_hdr(skb); th = tcp_hdr(skb);
thlen = th->doff * 4; thlen = th->doff * 4;
...@@ -75,7 +75,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, ...@@ -75,7 +75,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
if (!pskb_may_pull(skb, thlen)) if (!pskb_may_pull(skb, thlen))
goto out; goto out;
oldlen = (u16)~skb->len; oldlen = ~skb->len;
__skb_pull(skb, thlen); __skb_pull(skb, thlen);
mss = skb_shinfo(skb)->gso_size; mss = skb_shinfo(skb)->gso_size;
...@@ -110,7 +110,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, ...@@ -110,7 +110,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
if (skb_is_gso(segs)) if (skb_is_gso(segs))
mss *= skb_shinfo(segs)->gso_segs; mss *= skb_shinfo(segs)->gso_segs;
delta = htonl(oldlen + (thlen + mss)); delta = (__force __wsum)htonl(oldlen + thlen + mss);
skb = segs; skb = segs;
th = tcp_hdr(skb); th = tcp_hdr(skb);
...@@ -119,8 +119,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, ...@@ -119,8 +119,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
if (unlikely(skb_shinfo(gso_skb)->tx_flags & SKBTX_SW_TSTAMP)) if (unlikely(skb_shinfo(gso_skb)->tx_flags & SKBTX_SW_TSTAMP))
tcp_gso_tstamp(segs, skb_shinfo(gso_skb)->tskey, seq, mss); tcp_gso_tstamp(segs, skb_shinfo(gso_skb)->tskey, seq, mss);
newcheck = ~csum_fold((__force __wsum)((__force u32)th->check + newcheck = ~csum_fold(csum_add(csum_unfold(th->check), delta));
(__force u32)delta));
while (skb->next) { while (skb->next) {
th->fin = th->psh = 0; th->fin = th->psh = 0;
...@@ -165,11 +164,11 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, ...@@ -165,11 +164,11 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
WARN_ON_ONCE(refcount_sub_and_test(-delta, &skb->sk->sk_wmem_alloc)); WARN_ON_ONCE(refcount_sub_and_test(-delta, &skb->sk->sk_wmem_alloc));
} }
delta = htonl(oldlen + (skb_tail_pointer(skb) - delta = (__force __wsum)htonl(oldlen +
(skb_tail_pointer(skb) -
skb_transport_header(skb)) + skb_transport_header(skb)) +
skb->data_len); skb->data_len);
th->check = ~csum_fold((__force __wsum)((__force u32)th->check + th->check = ~csum_fold(csum_add(csum_unfold(th->check), delta));
(__force u32)delta));
if (skb->ip_summed == CHECKSUM_PARTIAL) if (skb->ip_summed == CHECKSUM_PARTIAL)
gso_reset_checksum(skb, ~th->check); gso_reset_checksum(skb, ~th->check);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment