Article View: linux.kernel.netdev
Article #27305[PATCH bpf 2/2] selftests/bpf: Test raw_tp test_run ctx padding for tail calls
From: Pragyansh Chaturvedi
Date: Sat, 05 Dec 2026 09:09
Date: Sat, 05 Dec 2026 09:09
113 lines
13456 bytes
13456 bytes
Add tailcall_raw_tp_ctx: a raw_tp caller that only tail-calls
(max_ctx_offset 0) and a target that reads 96 bytes of ctx and
returns 42 only if everything past the 8 bytes supplied by test_run
reads as zero. Without the ctx padding in bpf_prog_test_run_raw_tp()
the target reads out of bounds and almost surely returns 1 instead.
Signed-off-by: Pragyansh Chaturvedi <r41k0u@ubuntu.com>
---
.../selftests/bpf/prog_tests/tailcalls.c | 38 +++++++++++++++++++
.../selftests/bpf/progs/tailcall_raw_tp_ctx.c | 37 ++++++++++++++++++
2 files changed, 75 insertions(+)
create mode 100644 tools/testing/selftests/bpf/progs/tailcall_raw_tp_ctx.c
diff --git a/tools/testing/selftests/bpf/prog_tests/tailcalls.c b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
index 88d223110ec..be3bb858494 100644
--- a/tools/testing/selftests/bpf/prog_tests/tailcalls.c
+++ b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
@@ -17,6 +17,42 @@
#include "tailcall_callback.skel.h"
#include "tailcall_bpf2bpf2.skel.h"
#include "tailcall_bpf2bpf_fexit.skel.h"
+#include "tailcall_raw_tp_ctx.skel.h"
+
+/* test_tailcall_raw_tp_ctx checks that a raw_tp program run through
+ * BPF_PROG_TEST_RUN gets a zero-padded ctx when it can be reached by a
+ * tail call. The caller supplies 8 bytes of ctx and tail-calls a
+ * target that reads 96 bytes; without the padding the target reads
+ * out of bounds and (almost surely) non-zero memory, failing the
+ * retval check.
+ */
+static void test_tailcall_raw_tp_ctx(void)
+{
+ struct tailcall_raw_tp_ctx *skel;
+ __u64 ctx[12] = {};
+ int err, key = 0, prog_fd;
+
+ skel = tailcall_raw_tp_ctx__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "open_and_load"))
+ return;
+
+ prog_fd = bpf_program__fd(skel->progs.target);
+ err = bpf_map_update_elem(bpf_map__fd(skel->maps.jmp_table), &key,
+ &prog_fd, BPF_ANY);
+ if (!ASSERT_OK(err, "jmp_table"))
+ goto out;
+
+ /* raw_tp test_run does not accept repeat */
+ LIBBPF_OPTS(bpf_test_run_opts, topts,
+ .ctx_in = ctx,
+ .ctx_size_in = 8,
+ );
+ err = bpf_prog_test_run_opts(bpf_program__fd(skel->progs.caller), &topts);
+ ASSERT_OK(err, "test_run");
+ ASSERT_EQ(topts.retval, 42, "ctx padded with zeros");
+out:
+ tailcall_raw_tp_ctx__destroy(skel);
+}
/* test_tailcall_1 checks basic functionality by patching multiple locations
* in a single program for a single tail call slot with nop->jmp, jmp->nop
@@ -2138,4 +2174,6 @@ void test_tailcalls(void)
test_tailcall_bpf2bpf_fexit_links();
if (test__start_subtest("tailcall_large_stack"))
test_tailcall_large_stack();
+ if (test__start_subtest("tailcall_raw_tp_ctx"))
+ test_tailcall_raw_tp_ctx();
}
diff --git a/tools/testing/selftests/bpf/progs/tailcall_raw_tp_ctx.c b/tools/testing/selftests/bpf/progs/tailcall_raw_tp_ctx.c
new file mode 100644
index 00000000000..e8380d19892
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/tailcall_raw_tp_ctx.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+
+struct {
+ __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u32);
+} jmp_table SEC(".maps");
+
+SEC("raw_tracepoint/sched_switch")
+int caller(void *ctx)
+{
+ bpf_tail_call(ctx, &jmp_table, 0);
+ return 0;
+}
+
+SEC("raw_tracepoint/sched_switch")
+int target(void *ctx)
+{
+ __u64 *a = ctx;
+
+ /* The test runs the caller with an 8-byte ctx. Everything past
+ * the first u64 must read as zero: without the test_run ctx
+ * padding, these reads are out of bounds and leak whatever
+ * memory follows the small copy.
+ */
+#pragma clang loop unroll(full)
+ for (int i = 1; i < 12; i++) {
+ if (a[i])
+ return 1;
+ }
+ return 42;
+}
+
+char LICENSE[] SEC("license") = "GPL";
--
2.53.0
Technical Details
Message-ID:
<20261205090934.3813585-2-r41k0u@ubuntu.com>Path:
mbox-mo1.pugleaf.net!news-ams.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377907-linux-kernel-netdev=dewy.ruReferences:
<axPUDKyHAFXUXdp_@x1c> <20261205090934.3813585-1-r41k0u@ubuntu.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-ams.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377907-linux-kernel-netdev=dewy.ru
From: r41k0u@ubuntu.com (Pragyansh Chaturvedi)
Newsgroups: linux.kernel.netdev
Subject: [PATCH bpf 2/2] selftests/bpf: Test raw_tp test_run ctx padding for tail calls
Date: Sat, 5 Dec 2026 14:39:34 +0530
Organization: Usenet Network
Message-ID: <20261205090934.3813585-2-r41k0u@ubuntu.com>
References: <axPUDKyHAFXUXdp_@x1c>
<20261205090934.3813585-1-r41k0u@ubuntu.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2994355"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:elpWnu/Vxggryk06K1yWfKT0bpM= sha256:YevuBTXiTqbsG2NjiHC0mFDQ9jW2RtXRoWuO1xDgOo0=
sha1:Dw8Bl9TuDwBdqMDDHHjEeGAiHd8= sha256:GkuRjY/XU9hdkqt5P+meXLMOkCgw5a8ckedvQcys1es=
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 12F6F117DBC; Sat, 5 Dec 2026 12:10:27 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.299
X-Spam-Status: No, score=-3.299 tagged_above=-9999 required=6.31
tests=[HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
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 AvKSZRi4ShFw;
Sat, 5 Dec 2026 12:10:24 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-377907-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=ubuntu.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 85B13117DA3; Sat, 5 Dec 2026 12:10:20 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 3933C606F23; Sat, 5 Dec 2026 09:10:18 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796461816;
b=zzVMENjCEOOJLu4XEanE01oCV+UuIFYfpjOBDDNX0BB8mTOltk0beJoAXYEEAcPSzqxk
z9zGQJbVuXLdRWECiP4s0H8jB+k1KlSIPUjXOpAYiWlxmTtTlJV+enlGdzV2YySNhWHSI
jaG+xGdtvD5qJtNG2BtvryrgsXQdS53Tw3J3/j8jf5/jkwzVftjpeuQB9nJ7Vnx/o3zUQ
8skv/rUWzdgbYveQeiKREvbo8TGQBsituN0DJfKsjNHrPsp3lhP+1JHMdbvuIQ7MPEQUz
/pxmFVnnVmcIx/orU7PIomK2IW768WuDcrAzw4A4UM5osSRdmq2sICvtS0+ntmlcO3A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796461816;
h=X-Original-To:Received:DMARC-Filter:Received:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=zap3Y/TQx9f/VfuqN7DXqZU5WAnNpDAR+VIE9zcezWw=;
b=ORRnohvo23zeOcliYJRSnrpdyXHA+mgO3XK+HoEdYOyupaHnxBi4MRDbk0h0594hHK8J
4RSfvO1UHQAWpUPhE6YBsVpEW44RYcvksxf6Sr/umnEMFhutmY6i5/bKtju3cChqEMpsE
R1AbjGfshyk3A5FyWI46TrkiNyg5u+qPDVDi7hAwslxYpUqr3b5UKDFYuNSwn/gSQipVZ
AQf5x3JstTlS4I2S88XpblhiHalhWOmpMXlHh0KLmJZ6LCW4IY1ec4n0FoX6Ide8w8Ruz
DtMuHU/vr2H4HH0aDjNjIAhtcMZI37uFOCDEnJbCgKlkHJN2Mj2szyhfhbkTP+DbnzQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dmarc=fail header.from=ubuntu.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 830E5606A68B;
Sat, 5 Dec 2026 09:10:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796461815;
b=s0HBtfR5XKj3BpbG/y/7HcK+rYqRhYZDbacvF4kGhuA+ubEzPya7cAiDmch1daxYmyAW
Hv/n4JJsCRVlqd5Qp62Gy87UcF77p1tk7AirBEfuOK0CPqOq0lX0G12LsMYoRk7jucQOh
E3G4OWSeKagvaFpAQ1aD2yh/k9SZ3DCEBvvaRvvPWvf2lzQatg7lUSnUvwz5R0kPZKtRk
PAS12220bW1kIKv9d2NNh2XVmSHvCrd3M94Yaxhm1QrslqxzqUW504qeTE8uAWsx4Ors/
TxMvOAFpbhuU5bN12vJqkd65vfyMEojkes4FT0R/DiMR+q7E9cfZn3Q31OESTZZYliw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796461815;
h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Forwarded-Encrypted:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=zap3Y/TQx9f/VfuqN7DXqZU5WAnNpDAR+VIE9zcezWw=;
b=opRdiilxx/mYoA5fJWXzodfVNZlriBVqUd4ULXHf89ZM9axm4DYt5o2xaqvhVLJ9tGsl
26goAUvEZMzu+MFSWcQCV96Ba9K9IrfpwIOmLk3YtWuZntZ19tXyvFNf4ZhvgfEsxCmRQ
zWu6vs9vEX5iP/PDv9NAWZpz8h6dllEODz5BK0h1RyIAwObmSkeAUQrAWP4rmYEWkzEuD
ewoKHLLeAHLUQRmaetBuZ6+dSmHuBZSyb5ZX21D+fr+YArOuTPGdvhTtlqdVmh9dOHuDM
cLaRFPsphbNi/gH1L8Blzc7khV8EFUfhYntiHvCYr2S2QOuCZC0RBYz45zoFEXEesfA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=fail header.from=ubuntu.com;
spf=pass smtp.mailfrom=gmail.com;
arc=none smtp.remote-ip=74.125.82.180
X-Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89649606A32F
for <netdev@vger.kernel.org>; Sat, 5 Dec 2026 09:10:15 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 89649606A32F
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ubuntu.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-38692f62b22so3580255eec.0
for <netdev@vger.kernel.org>; Sat, 05 Dec 2026 01:10:15 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796461815; x=1797066615;
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=zap3Y/TQx9f/VfuqN7DXqZU5WAnNpDAR+VIE9zcezWw=;
b=QyAWSlNTSZCPg/2jv3yWC+J3TQFwcib5tr0crUT74ZFzfsF035W2R5trh5z1E22MAu
fUI2QJhJZP/3FNI4/QvzP6shECIk+tCy/EcOm8ToANUFRF3sbtoEr2OxSQHwDG/sLS7l
bWbn1HC/lea4GQ5/Z8Xf7noGYP+H6OqP3k2T6TCWFZ0NcShVRRsQghu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386:ebc5:3dfe with SMTP id 5a478bee46e88-387521b78e4mr6208889eec.22.1796461814630;
Sat, 05 Dec 2026 01:10:14 -0800 (PST)
X-Received: from x1c.tail178f29.ts.net ([2406:7400:bb:fb44:feef:834d:2032:98d5])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875207adecsm18481629eec.3.2026.12.05.01.10.09
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sat, 05 Dec 2026 01:10:14 -0800 (PST)
X-Cc: ast@kernel.org,
daniel@iogearbox.net,
andrii@kernel.org,
eddyz87@gmail.com,
varunrmallya@gmail.com,
kc@kcsrk.info,
yonghong.song@linux.dev,
memxor@gmail.com,
ngs@cse.iitm.ac.in,
netdev@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Pragyansh Chaturvedi <r41k0u@ubuntu.com>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261205090934.3813585-1-r41k0u@ubuntu.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list