Skip to content

Commit e8a63d4

Browse files
Sean Andersonkuba-moo
authored andcommitted
selftests: net: csum: Fix checksums for packets with non-zero padding
Padding is not included in UDP and TCP checksums. Therefore, reduce the length of the checksummed data to include only the data in the IP payload. This fixes spurious reported checksum failures like rx: pkt: sport=33000 len=26 csum=0xc850 verify=0xf9fe pkt: bad csum Technically it is possible for there to be trailing bytes after the UDP data but before the Ethernet padding (e.g. if sizeof(ip) + sizeof(udp) + udp.len < ip.len). However, we don't generate such packets. Fixes: 91a7de8 ("selftests/net: add csum offload test") Signed-off-by: Sean Anderson <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3f62ea5 commit e8a63d4

File tree

1 file changed

+14
-2
lines changed
  • tools/testing/selftests/net/lib

1 file changed

+14
-2
lines changed

tools/testing/selftests/net/lib/csum.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,16 @@ static int recv_verify_packet_ipv4(void *nh, int len)
654654
{
655655
struct iphdr *iph = nh;
656656
uint16_t proto = cfg_encap ? IPPROTO_UDP : cfg_proto;
657+
uint16_t ip_len;
657658

658659
if (len < sizeof(*iph) || iph->protocol != proto)
659660
return -1;
660661

662+
ip_len = ntohs(iph->tot_len);
663+
if (ip_len > len || ip_len < sizeof(*iph))
664+
return -1;
665+
666+
len = ip_len;
661667
iph_addr_p = &iph->saddr;
662668
if (proto == IPPROTO_TCP)
663669
return recv_verify_packet_tcp(iph + 1, len - sizeof(*iph));
@@ -669,16 +675,22 @@ static int recv_verify_packet_ipv6(void *nh, int len)
669675
{
670676
struct ipv6hdr *ip6h = nh;
671677
uint16_t proto = cfg_encap ? IPPROTO_UDP : cfg_proto;
678+
uint16_t ip_len;
672679

673680
if (len < sizeof(*ip6h) || ip6h->nexthdr != proto)
674681
return -1;
675682

683+
ip_len = ntohs(ip6h->payload_len);
684+
if (ip_len > len - sizeof(*ip6h))
685+
return -1;
686+
687+
len = ip_len;
676688
iph_addr_p = &ip6h->saddr;
677689

678690
if (proto == IPPROTO_TCP)
679-
return recv_verify_packet_tcp(ip6h + 1, len - sizeof(*ip6h));
691+
return recv_verify_packet_tcp(ip6h + 1, len);
680692
else
681-
return recv_verify_packet_udp(ip6h + 1, len - sizeof(*ip6h));
693+
return recv_verify_packet_udp(ip6h + 1, len);
682694
}
683695

684696
/* return whether auxdata includes TP_STATUS_CSUM_VALID */

0 commit comments

Comments
 (0)