]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: selftests: fix TCP packet checksum
authorJakub Kicinski <kuba@kernel.org>
Tue, 24 Jun 2025 18:32:58 +0000 (11:32 -0700)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 26 Jun 2025 08:50:49 +0000 (10:50 +0200)
The length in the pseudo header should be the length of the L3 payload
AKA the L4 header+payload. The selftest code builds the packet from
the lower layers up, so all the headers are pushed already when it
constructs L4. We need to subtract the lower layer headers from skb->len.

Fixes: 3e1e58d64c3d ("net: add generic selftest support")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reported-by: Oleksij Rempel <o.rempel@pengutronix.de>
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://patch.msgid.link/20250624183258.3377740-1-kuba@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/core/selftests.c

index 35f807ea995235bf2e08779eefa6a226c0885414..406faf8e5f3f9f09d9f508cee0f199e59ae736be 100644 (file)
@@ -160,8 +160,9 @@ static struct sk_buff *net_test_get_skb(struct net_device *ndev,
        skb->csum = 0;
        skb->ip_summed = CHECKSUM_PARTIAL;
        if (attr->tcp) {
-               thdr->check = ~tcp_v4_check(skb->len, ihdr->saddr,
-                                           ihdr->daddr, 0);
+               int l4len = skb->len - skb_transport_offset(skb);
+
+               thdr->check = ~tcp_v4_check(l4len, ihdr->saddr, ihdr->daddr, 0);
                skb->csum_start = skb_transport_header(skb) - skb->head;
                skb->csum_offset = offsetof(struct tcphdr, check);
        } else {