Article View: linux.kernel.netdev
Article #255[PATCH bpf 1/2] bpf: test_run: Fix false -EBADMSG after skb leaves CHECKSUM_COMPLETE
From: Maxim Skokov
Date: Wed, 07 Oct 2026 18:12
Date: Wed, 07 Oct 2026 18:12
55 lines
10931 bytes
10931 bytes
With BPF_F_TEST_SKB_CHECKSUM_COMPLETE, bpf_prog_test_run_skb() computes
skb->csum over the packet from the network header to the end and marks
the skb CHECKSUM_COMPLETE. After the program has run, it recomputes the
checksum and returns -EBADMSG if it does not match skb->csum.
bpf_skb_change_tail() resizes the skb with __skb_trim_rcsum() and
__skb_grow_rcsum(), which move a CHECKSUM_COMPLETE skb to CHECKSUM_NONE
and leave skb->csum as it is. The post-run check still compares against
that stale value, so a correct program fails with -EBADMSG. After a
trim, skb->csum still covers the removed bytes. After a grow, later
writes cannot update skb->csum, even with BPF_F_RECOMPUTE_CSUM, because
skb->csum is only adjusted for CHECKSUM_COMPLETE skbs.
skb->csum only holds the packet checksum while ip_summed is
CHECKSUM_COMPLETE. With CHECKSUM_NONE the stack does not rely on it and
validates the packet in software, so there is nothing to compare. Only
do the check if the skb is still CHECKSUM_COMPLETE after the run. A
program that keeps the skb CHECKSUM_COMPLETE but leaves skb->csum stale
still gets -EBADMSG.
Dropping the checksum offload is documented behaviour of
bpf_skb_change_tail() ("implicitly linearizes, unclones and drops
offloads"), and the stack does the same in other places, for example
skb_forward_csum(). The test harness has to accept CHECKSUM_NONE either
way, whether or not the helper is later taught to keep
CHECKSUM_COMPLETE.
Fixes: a3cfe84cca28 ("bpf: Add CHECKSUM_COMPLETE to bpf test progs")
Assisted-by: LLM
Signed-off-by: Maxim Skokov <skokovmaksimevg@gmail.com>
---
net/bpf/test_run.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 513354e928cb5..45718fa9adfd2 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -1237,7 +1237,12 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
memset(__skb_push(skb, hh_len), 0, hh_len);
}
- if (kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) {
+ /* A helper such as bpf_skb_change_tail() may have downgraded the skb
+ * from CHECKSUM_COMPLETE. skb->csum is then unused by the stack and
+ * there is nothing to validate.
+ */
+ if ((kattr->test.flags & BPF_F_TEST_SKB_CHECKSUM_COMPLETE) &&
+ skb->ip_summed == CHECKSUM_COMPLETE) {
const int off = skb_network_offset(skb);
int len = skb->len - off;
__wsum csum;
--
2.47.3
Technical Details
Message-ID:
<20261007181249.352831-2-skokovmaksimevg@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342434-linux-kernel-netdev=dewy.ruReferences:
<20261007181249.352831-1-skokovmaksimevg@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342434-linux-kernel-netdev=dewy.ru
From: skokovmaksimevg@gmail.com (Maxim Skokov)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf 1/2] bpf: test_run: Fix false -EBADMSG after skb leaves CHECKSUM_COMPLETE
Date: Wed, 7 Oct 2026 21:12:41 +0300
Organization: Usenet Network
Message-ID: <20261007181249.352831-2-skokovmaksimevg@gmail.com>
References: <20261007181249.352831-1-skokovmaksimevg@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="706681"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:FXKu/UI+9UmO7eG6Y98bBhzhrsM= sha256:+HMa6Iw6YICaBxnG9T8AeNR5B1vYfBD3dKfQLF2b5mo=
sha1:b9zCeY8tvtFZf9MYTCzYwGebemM= sha256:PP2KP6Cq5AVwZ3T5BJHpEwLb/yhMNULXOe00GiYg/0M=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 9FA6D10F1DD; Wed, 7 Oct 2026 21:14:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: 0.251
X-Spam-Status: No, score=0.251 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FORGED_GMAIL_RCVD=1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=no autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id QJpI52u-rZrG;
Wed, 7 Oct 2026 21:14:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-342434-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id B6F8010F1D4; Wed, 7 Oct 2026 21:14:22 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sea.lore.kernel.org (Postfix) with ESMTP id 9751B3688E; Wed, 7 Oct 2026 18:13:19 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id ED5714DDB4F;
Wed, 7 Oct 2026 18:13:18 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OeVHtaJo"
X-Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFD7A4DD3B2
for <netdev@vger.kernel.org>; Wed, 7 Oct 2026 18:13:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1791396798; cv=none; b=B1p2hCrf5qFfUERASonctifH2GqlSZz/dqvauQQoXH8xKZfMSxEBQv53ADWxlzkUmSEJyVoWyu12BYwu4ezSwRT/gvxzJZJFQyaLNQdw6ZNEBOP5tK+3eeAQQeWMbwtAW8XL+Wx6l5vKoxNLUgOZ+yCWz83t8AwK63quh+jxTyY=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1791396798; c=relaxed/simple;
bh=k183NUhj1qwHVJsFTyAHVX6htBfZ4hKlTE4Xzh8MQTk=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
MIME-Version; b=GMSmRhP/SfMZoV8e/OWWZfjDLyc7bIfDfLa/77H6rYgndM/UiGCiobyAOtonTXY5KXfDL7X/Bvwvr5/CGdG4pN/zLIjFPDcBFVyVw9NgEHltRqbx+zXmLlTgzlKTJ2ObrdCnG5OUNgME8+E6fK7aWIn6FPB7ww5kjGGpOORmNB0=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OeVHtaJo; arc=none smtp.client-ip=209.85.208.177
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-3a9ad623098so1589821fa.1
for <netdev@vger.kernel.org>; Wed, 07 Oct 2026 11:13:16 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1791396795; x=1792001595; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=1qSCjp+BKxpET3CUaJgBBRS2Eq6s578cQ0Ck4M7Ypvs=;
b=OeVHtaJo4Qp54sXfuZ1f3BJZODIVg5XBAmfAWY3/Wnv4qW1/G2a2dYg7ouoZWbuKQg
usi5SDZCFtI4IGE/iiGwqbIt8+c3gZSXD0S7/t5a7upEXOMZ0ZmTdze6vuvrEbsqahYQ
ZpGaDssE1ST/iGnr1KP01Fe6EbwEDKuYYXUE2xiOO4khY51nay1guS4HWJyYYq0pO257
kdHoqrAPJP1KUkQXcmbbQDci9gsxqNsbRdUYh0HfoMUkBUO5yOVg7t6mVMTJotG7cwsP
f11fYDjjTxf7mzZ/9KLe9LWi5WXxAgOpMH5SBn4xOX6jmJc7c2tTJI4RuMONDaKT7nr/
Dn4Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1791396795; x=1792001595;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=1qSCjp+BKxpET3CUaJgBBRS2Eq6s578cQ0Ck4M7Ypvs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JPn22lZksNQWb5JV0s2QfbkIUvGnTp3shZXtGBpIs
N7O5argEALfjNunhIwqfPsfyMLHai3KKgRZy9bQBE3l7FyIeg9j
X-Received: by 2002:a2e:be04:0:b0:3a6:568f:40dc with SMTP id 38308e7fff4ca-3a9a2bd9398mr7050691fa.2.1791396794682;
Wed, 07 Oct 2026 11:13:14 -0700 (PDT)
X-Received: from localhost.localdomain (95-24-167-79.broadband.corbina.ru. [95.24.167.79])
by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3a9a1d59661sm9000041fa.18.2026.10.07.11.13.10
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 07 Oct 2026 11:13:13 -0700 (PDT)
X-Cc: ast@kernel.org,
daniel@iogearbox.net,
andrii@kernel.org,
martin.lau@linux.dev,
eddyz87@gmail.com,
song@kernel.org,
yonghong.song@linux.dev,
jolsa@kernel.org,
memxor@gmail.com,
emil@etsalapatis.com,
ihor.solodrai@linux.dev,
davem@davemloft.net,
edumazet@kernel.org,
kuba@kernel.org,
pabeni@redhat.com,
horms@kernel.org,
shuah@kernel.org,
vadim.fedorenko@linux.dev,
netdev@vger.kernel.org,
linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org,
Maxim Skokov <skokovmaksimevg@gmail.com>
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261007181249.352831-1-skokovmaksimevg@gmail.com>
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>