diff mbox series

[net] udp: Compute L4 checksum as usual when not segmenting the skb

Message ID 20241010-uso-swcsum-fixup-v1-1-a63fbd0a414c@cloudflare.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] udp: Compute L4 checksum as usual when not segmenting the skb | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 6 this patch: 6
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 6 this patch: 6
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 11 this patch: 11
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 3 this patch: 3
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-10--18-00 (tests: 775)

Commit Message

Jakub Sitnicki Oct. 10, 2024, 12:14 p.m. UTC
If:

  1) the user requested USO, but
  2) there is not enough payload for GSO to kick in, and
  3) the egress device doesn't offer checksum offload, then

we want to compute the L4 checksum in software early on.

In the case when we taking the GSO path, but it has been requested, the
software checksum fallback in skb_segment doesn't get a chance to compute
the full checksum, if the egress device can't do it. As a result we end up
sending UDP datagrams with only a partial checksum filled in, which the
peer will discard.

Fixes: 10154dbded6d ("udp: Allow GSO transmit from devices with no checksum offload")
Reported-by: Ivan Babrou <ivan@cloudflare.com>
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Cc: stable@vger.kernel.org
---
This shouldn't have fallen through the cracks. I clearly need to extend the
net/udpgso selftests further to cover the whole TX path for software
USO+csum case. I will follow up with that but I wanted to get the fix out
in the meantime. Apologies for the oversight.
---
 net/ipv4/udp.c | 4 +++-
 net/ipv6/udp.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

Comments

Willem de Bruijn Oct. 10, 2024, 1:31 p.m. UTC | #1
Jakub Sitnicki wrote:
> If:
> 
>   1) the user requested USO, but
>   2) there is not enough payload for GSO to kick in, and
>   3) the egress device doesn't offer checksum offload, then
> 
> we want to compute the L4 checksum in software early on.
> 
> In the case when we taking the GSO path, but it has been requested, the

What does it refers to here?

> software checksum fallback in skb_segment doesn't get a chance to compute
> the full checksum, if the egress device can't do it. As a result we end up
> sending UDP datagrams with only a partial checksum filled in, which the
> peer will discard.
> 
> Fixes: 10154dbded6d ("udp: Allow GSO transmit from devices with no checksum offload")
> Reported-by: Ivan Babrou <ivan@cloudflare.com>
> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
> Cc: stable@vger.kernel.org
> ---
> This shouldn't have fallen through the cracks. I clearly need to extend the
> net/udpgso selftests further to cover the whole TX path for software
> USO+csum case. I will follow up with that but I wanted to get the fix out
> in the meantime. Apologies for the oversight.
> ---
>  net/ipv4/udp.c | 4 +++-
>  net/ipv6/udp.c | 4 +++-
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index 8accbf4cb295..2849b273b131 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -951,8 +951,10 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
>  			skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
>  			skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
>  								 cork->gso_size);
> +
> +			/* Don't checksum the payload, skb will get segmented */
> +			goto csum_partial;
>  		}
> -		goto csum_partial;

The issue here is that GSO packets with CHECKSUM_NONE will get fixed
software checksummed in skb_segment, but no such fallback path is
entered for regular packets, right?

We could setup CHECKSUM_PARTIAL and rely on validate_xmit_skb. But
might as well do the software checksumming right here, as your
patch does.

If I follow this all, ACK from me. Just want to make sure.
>  	}
>  
>  	if (is_udplite)  				 /*     UDP-Lite      */
> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
> index 52dfbb2ff1a8..0cef8ae5d1ea 100644
> --- a/net/ipv6/udp.c
> +++ b/net/ipv6/udp.c
> @@ -1266,8 +1266,10 @@ static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
>  			skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
>  			skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
>  								 cork->gso_size);
> +
> +			/* Don't checksum the payload, skb will get segmented */
> +			goto csum_partial;
>  		}
> -		goto csum_partial;
>  	}
>  
>  	if (is_udplite)
>
Jakub Sitnicki Oct. 10, 2024, 2 p.m. UTC | #2
On Thu, Oct 10, 2024 at 09:31 AM -04, Willem de Bruijn wrote:
> Jakub Sitnicki wrote:
>> If:
>> 
>>   1) the user requested USO, but
>>   2) there is not enough payload for GSO to kick in, and
>>   3) the egress device doesn't offer checksum offload, then
>> 
>> we want to compute the L4 checksum in software early on.
>> 
>> In the case when we taking the GSO path, but it has been requested, the
>
> What does it refers to here?

That's a typo there. Will fix. It should have said:

  In the case when we *not* taking the GSO path, but it has been
  requested, ...

Pseudo code-wise something like:

  s.setsockopt(SOL_UDP, UDP_SEGMENT, 1200)
  s.sendto(b"x", ("192.0.2.1", 9))


>> software checksum fallback in skb_segment doesn't get a chance to compute
>> the full checksum, if the egress device can't do it. As a result we end up
>> sending UDP datagrams with only a partial checksum filled in, which the
>> peer will discard.
>> 
>> Fixes: 10154dbded6d ("udp: Allow GSO transmit from devices with no checksum offload")
>> Reported-by: Ivan Babrou <ivan@cloudflare.com>
>> Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
>> Cc: stable@vger.kernel.org
>> ---
>> This shouldn't have fallen through the cracks. I clearly need to extend the
>> net/udpgso selftests further to cover the whole TX path for software
>> USO+csum case. I will follow up with that but I wanted to get the fix out
>> in the meantime. Apologies for the oversight.
>> ---
>>  net/ipv4/udp.c | 4 +++-
>>  net/ipv6/udp.c | 4 +++-
>>  2 files changed, 6 insertions(+), 2 deletions(-)
>> 
>> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
>> index 8accbf4cb295..2849b273b131 100644
>> --- a/net/ipv4/udp.c
>> +++ b/net/ipv4/udp.c
>> @@ -951,8 +951,10 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
>>  			skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
>>  			skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
>>  								 cork->gso_size);
>> +
>> +			/* Don't checksum the payload, skb will get segmented */
>> +			goto csum_partial;
>>  		}
>> -		goto csum_partial;
>
> The issue here is that GSO packets with CHECKSUM_NONE will get fixed
> software checksummed in skb_segment, but no such fallback path is
> entered for regular packets, right?
>
> We could setup CHECKSUM_PARTIAL and rely on validate_xmit_skb. But
> might as well do the software checksumming right here, as your
> patch does.

Yes, all correct.

To add to it - I figured that marking the skb with CHECKSUM_PARTIAL,
when device doesn't offer csum offload, would be more confusing.

>
> If I follow this all, ACK from me. Just want to make sure.

Thanks. I will carry it in v2.

Will wait a bit before respinning it.
Maybe Ivan can get a chance to this patch.

>>  	}
>>  
>>  	if (is_udplite)  				 /*     UDP-Lite      */
>> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
>> index 52dfbb2ff1a8..0cef8ae5d1ea 100644
>> --- a/net/ipv6/udp.c
>> +++ b/net/ipv6/udp.c
>> @@ -1266,8 +1266,10 @@ static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
>>  			skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
>>  			skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
>>  								 cork->gso_size);
>> +
>> +			/* Don't checksum the payload, skb will get segmented */
>> +			goto csum_partial;
>>  		}
>> -		goto csum_partial;
>>  	}
>>  
>>  	if (is_udplite)
>>
diff mbox series

Patch

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 8accbf4cb295..2849b273b131 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -951,8 +951,10 @@  static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
 			skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
 			skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
 								 cork->gso_size);
+
+			/* Don't checksum the payload, skb will get segmented */
+			goto csum_partial;
 		}
-		goto csum_partial;
 	}
 
 	if (is_udplite)  				 /*     UDP-Lite      */
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 52dfbb2ff1a8..0cef8ae5d1ea 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -1266,8 +1266,10 @@  static int udp_v6_send_skb(struct sk_buff *skb, struct flowi6 *fl6,
 			skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
 			skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
 								 cork->gso_size);
+
+			/* Don't checksum the payload, skb will get segmented */
+			goto csum_partial;
 		}
-		goto csum_partial;
 	}
 
 	if (is_udplite)