On 2026-09-20T08:26:10, Mingtian Li <[email protected]> wrote: > net: fix UDP checksum check for odd-length packets > > RFC 768 requires that when the UDP payload has an odd length, the last > byte is padded with a zero low byte for the checksum calculation, i.e. it > must be added as (byte << 8) only. > > Since commit 8524423da9af ("net: avoid address-of-packed-member error") > the byte is added twice: > > xsum += (sumptr[0] << 8) + sumptr[0]; > > That commit replaced the correctly masked > > sumdata = *(unsigned char *)sumptr; > sumdata = (sumdata << 8) & 0xff00; > xsum += sumdata; > > with the expression above, so with CONFIG_UDP_CHECKSUM enabled the > resulting sum for a valid packet is 0xffff + last_byte instead of > 0xffff, and every received UDP packet with an odd length whose last byte > is non-zero is wrongly rejected with > > UDP wrong checksum 000000bf 00009288 > > and dropped. This breaks e.g. TFTP download of any file with an odd > size whose final byte is not zero, because the last data block of such > a file has an odd UDP length and is rejected on every retransmission. > > Fix the calculation to add the byte as the high half only. > > Fixes: 8524423da9af ("net: avoid address-of-packed-member error") > Signed-off-by: Mingtian Li <[email protected]> > Cc: Jerome Forissier <[email protected]> > > net/net.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass <[email protected]>
