Hi Madhav,

On Wed Sep 16, 2026 at 1:25 PM CEST, Madhav Khosla wrote:
> csum_partial() computes num_u16 = len >> 1 and only sums that many
> 16-bit words, so the last byte of an odd-length buffer never gets
> added to the checksum. RFC 1071 says it should be padded with a zero
> byte and summed as one more word, not dropped.
>
> This backs build_ip_csum(), build_udp_v4_csum() and
> build_udp_v6_csum(), used by flow_dissector_classification.c and
> xdp_metadata.c to hand-build packets. No current caller builds an
> odd-length payload, so nothing fails today, but a future one would
> get a silently wrong checksum.
>
> Also bump flow_dissector_classification's TEST_PACKET_LEN from 100 to
> 99 so this actually gets exercised instead of staying latent.

Great, thanks for the update.

> Without the fix and with TEST_PACKET_LEN=99, flow_dissector_classification
> fails under vmtest.sh:
>
>     test_flow_dissector_classification:FAIL:test third port unexpected
>     test third port: actual 0 != expected 10
>     #137/6   flow_dissector_classification/ipv6:FAIL
>     #137     flow_dissector_classification:FAIL
>     Summary: 1/0 PASSED, 0 SKIPPED, 1/6 FAILED
>
> Kernel just drops the packet over a bad checksum. With the fix, both
> flow_dissector_classification and xdp_metadata pass.
>
> v1 -> v2:
> - comment style: opening /* on its own line, per BPF selftests style
> - Retarget the Fixes tag to bcc00987bc56. commit f4504af68575
>   ("selftests/bpf: move ip checksum helper to network helpers") moved
>   the helper, but sizeof(iphdr) is always a multiple of 32 bit words /
>   4 Bytes (iph->ihl counts in 4-byte words), so the odd-length path
>   was never reachable through build_ip_csum(). csum_partial() first
>   gets called with a length that isn't guaranteed even in
>   bcc00987bc56, via build_udp_v4_csum()/build_udp_v6_csum().
> - TEST_PACKET_LEN 100 -> 99 so an existing test catches this instead
>   of the bug staying unexercised

Could you please move the patch changelog under --- so it does not end
up in the commit once it is merged ? You can also drop the Link tag, one
will automatically be added on the latest revision once it is merged.

Up to some extent, you could also move the ./test_progs sample output in
the comments under --- as well.

> Fixes: bcc00987bc56 ("selftests/bpf: add network helpers to generate udp 
> checksums")

You chose to use bcc00987bc56 rather than e2a46d54d7a1, but I guess it
is ok.

> Link: https://lore.kernel.org/bpf/[email protected]/T/#t
> Signed-off-by: Madhav Khosla <[email protected]>

Thanks,

Alexis

-- 
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


Reply via email to