diff mbox series

[iwl-net] selftests/net: Fix csum test for short packets

Message ID 20240821142409.958668-1-krzysztof.galazka@intel.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [iwl-net] selftests/net: Fix csum test for short packets | 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: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 2 blamed authors not CCed: kuba@kernel.org willemb@google.com; 6 maintainers not CCed: pabeni@redhat.com kuba@kernel.org edumazet@google.com willemb@google.com shuah@kernel.org linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 7 this patch: 7
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: 7 this patch: 7
netdev/checkpatch warning WARNING: 'lenght' may be misspelled - perhaps 'length'? WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: 1d0dc857b5d8 ("selftests: drv-net: add checksum tests")'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Galazka, Krzysztof Aug. 21, 2024, 2:24 p.m. UTC
For IPv4 and IPv6 packets shorter than minimum Ethernet
frame payload, recvmsg returns lenght including padding.
Use length from header for checksum verification to avoid
csum test failing on correct packets.

Fixes: 1d0dc857b5d8 (selftests: drv-net: add checksum tests)
Signed-off-by: Krzysztof Galazka <krzysztof.galazka@intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
---
 tools/testing/selftests/net/lib/csum.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Willem de Bruijn Aug. 21, 2024, 2:32 p.m. UTC | #1
Krzysztof Galazka wrote:
> For IPv4 and IPv6 packets shorter than minimum Ethernet
> frame payload, recvmsg returns lenght including padding.

nit: length

> Use length from header for checksum verification to avoid
> csum test failing on correct packets.
> 
> Fixes: 1d0dc857b5d8 (selftests: drv-net: add checksum tests)
> Signed-off-by: Krzysztof Galazka <krzysztof.galazka@intel.com>
> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>

This is not Intel driver specific, so can be sent straight to net

> ---
>  tools/testing/selftests/net/lib/csum.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/lib/csum.c b/tools/testing/selftests/net/lib/csum.c
> index b9f3fc3c3426..3dbaf2ecd59e 100644
> --- a/tools/testing/selftests/net/lib/csum.c
> +++ b/tools/testing/selftests/net/lib/csum.c
> @@ -658,6 +658,9 @@ static int recv_verify_packet_ipv4(void *nh, int len)
>  	if (len < sizeof(*iph) || iph->protocol != proto)
>  		return -1;
>  
> +	/* For short packets recvmsg returns length with padding, fix that */
> +	len = ntohs(iph->tot_len);
> +

Are you running into this while running the standard testsuite in
csum.py, or a specific custom invocation?

Since the checksum is an L3 feature, trusting the L3 length field for
this makes sense (as long as the packet wasn't truncated).

>  	iph_addr_p = &iph->saddr;
>  	if (proto == IPPROTO_TCP)
>  		return recv_verify_packet_tcp(iph + 1, len - sizeof(*iph));
> @@ -673,6 +676,9 @@ static int recv_verify_packet_ipv6(void *nh, int len)
>  	if (len < sizeof(*ip6h) || ip6h->nexthdr != proto)
>  		return -1;
>  
> +	/* For short packets recvmsg returns length with padding, fix that */
> +	len = sizeof(*ip6h) + ntohs(ip6h->payload_len);
> +
>  	iph_addr_p = &ip6h->saddr;
>  
>  	if (proto == IPPROTO_TCP)
> -- 
> 2.43.0
>
Simon Horman Aug. 21, 2024, 5:43 p.m. UTC | #2
On Wed, Aug 21, 2024 at 04:24:09PM +0200, Krzysztof Galazka wrote:
> For IPv4 and IPv6 packets shorter than minimum Ethernet
> frame payload, recvmsg returns lenght including padding.
> Use length from header for checksum verification to avoid
> csum test failing on correct packets.
> 
> Fixes: 1d0dc857b5d8 (selftests: drv-net: add checksum tests)

nit: I think the correct format for the tag is

Fixes: 1d0dc857b5d8 ("selftests: drv-net: add checksum tests")

> Signed-off-by: Krzysztof Galazka <krzysztof.galazka@intel.com>
> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>

...
Galazka, Krzysztof Aug. 27, 2024, 5:54 p.m. UTC | #3
On 2024-08-21 16:32, Willem de Bruijn wrote:
> Krzysztof Galazka wrote:
>> For IPv4 and IPv6 packets shorter than minimum Ethernet
>> frame payload, recvmsg returns lenght including padding.
> 
> nit: length
> 
>> Use length from header for checksum verification to avoid
>> csum test failing on correct packets.
>>
>> Fixes: 1d0dc857b5d8 (selftests: drv-net: add checksum tests)
>> Signed-off-by: Krzysztof Galazka <krzysztof.galazka@intel.com>
>> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
> 
> This is not Intel driver specific, so can be sent straight to net
> 
>> ---
>>   tools/testing/selftests/net/lib/csum.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/tools/testing/selftests/net/lib/csum.c b/tools/testing/selftests/net/lib/csum.c
>> index b9f3fc3c3426..3dbaf2ecd59e 100644
>> --- a/tools/testing/selftests/net/lib/csum.c
>> +++ b/tools/testing/selftests/net/lib/csum.c
>> @@ -658,6 +658,9 @@ static int recv_verify_packet_ipv4(void *nh, int len)
>>   	if (len < sizeof(*iph) || iph->protocol != proto)
>>   		return -1;
>>   
>> +	/* For short packets recvmsg returns length with padding, fix that */
>> +	len = ntohs(iph->tot_len);
>> +
> 
> Are you running into this while running the standard testsuite in
> csum.py, or a specific custom invocation?

It was with standard testsuite in csum.py. Not on every run but quite often.

> 
> Since the checksum is an L3 feature, trusting the L3 length field for
> this makes sense (as long as the packet wasn't truncated).

Ah, I haven't thought about truncated packets. I'll add condition to 
update length returned by recvmsg only if it's greater then expected.


Thanks,
Krzysiek
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/lib/csum.c b/tools/testing/selftests/net/lib/csum.c
index b9f3fc3c3426..3dbaf2ecd59e 100644
--- a/tools/testing/selftests/net/lib/csum.c
+++ b/tools/testing/selftests/net/lib/csum.c
@@ -658,6 +658,9 @@  static int recv_verify_packet_ipv4(void *nh, int len)
 	if (len < sizeof(*iph) || iph->protocol != proto)
 		return -1;
 
+	/* For short packets recvmsg returns length with padding, fix that */
+	len = ntohs(iph->tot_len);
+
 	iph_addr_p = &iph->saddr;
 	if (proto == IPPROTO_TCP)
 		return recv_verify_packet_tcp(iph + 1, len - sizeof(*iph));
@@ -673,6 +676,9 @@  static int recv_verify_packet_ipv6(void *nh, int len)
 	if (len < sizeof(*ip6h) || ip6h->nexthdr != proto)
 		return -1;
 
+	/* For short packets recvmsg returns length with padding, fix that */
+	len = sizeof(*ip6h) + ntohs(ip6h->payload_len);
+
 	iph_addr_p = &ip6h->saddr;
 
 	if (proto == IPPROTO_TCP)