From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 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== 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== 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 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 ; Sat, 5 Dec 2026 09:10:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 89649606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=ubuntu.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-38692f62b22so3580255eec.0 for ; 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+H6OqP3k2T6TCWFZ0NcShVRRsQghuavcLEoUD/hHRx IeKEmIu+XR8Z1NH/dtArTL5IlQ9buzXwP1LrmnhbMPMnurETBxMa/V6FPKb+7czJrUnb K7T8s24uZWvU+n9A0pW7FWYVpvmvl6AT8Ckrk4IGI49gHpL8oLGHL3cZbZUGyzW6rIa2 XUTA== X-Forwarded-Encrypted: i=1; AL+hErHqELoech7v5JFQ/p3J/j3h/g75hcBqjIeZ4OjZ7F7hedkwHEHU+jrcC3cNof4JaerEPnsuX+w=@vger.kernel.org X-Gm-Message-State: AB4q+uFKvcCKdCN724POo5ATMc4L4sYz03I6rfe8//edKmBGxYPhpNal ILMmpgLxHy/KfjmWK5R0pX//icfCjvPYqzTeHwrih0lSGDPtRkdOACOU X-Gm-Gg: AZFdTZey6iQLPKtV1Ic7dbbw+bFZb+Ov3sOGftng7JqWum4rVPPFI8f/qfdrtHjFHQS O/0tKiKy+Uk0D8fnK6SxTPUuswKZF0/tKcvRe8xvLAtquSLH1oCRPxs0RcPt7MJwnlDEcPr4BDe Q+Uwq9HmUkS1fuvFIWQcVEu6TYchMQuVdY5MCU6E41cprqpoESF3Jr055PucprYqpK2aTp386DQ INBArfbGdnCmLYp4oCvDBDQIGrv203ESsBEFWdcmpM3MsBG9ypeGhmw2YhjLbihPdJaXjhjvkS0 qeoCak7L1p7qoPkPvuXpDyY8eCk4Pq4z1bkk0tyNAKn5jypqkO8Hu6xBh1TgzdPjiVB3lK4OH9A eEWkmw0tS/I+EwKWOum2JjF/Gm2JAR4jSg8fPH0o8hliWJ4Xkuw32QNfv1sYznzCuklt62n4Dmf sWuu4XPwp5k1cg/Z8jaiQY7k+KTNjZ9nlD1umj9s/hrpI+HCMc5hQ3Bauz4TvyHTpQyNndrp5LU Kk9UT0zNAcDZJDTK2Py17PCiUNd6+FPclYSJUM75Fvxbre8O+1uiOS6HvnL/QRiRRoYhki+wimL S8GLDqguO73LXzMeTjdeqo6rdNa+LPDyH11EvXkaDg== X-Received: by 2002:a05:7301:4005:b0:386:ebc5:3dfe with SMTP id 5a478bee46e88-387521b78e4mr6208889eec.22.1796461814630; Sat, 05 Dec 2026 01:10:14 -0800 (PST) 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) From: Pragyansh Chaturvedi To: bpf@vger.kernel.org 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 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 Message-ID: <20261205090934.3813585-2-r41k0u@ubuntu.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261205090934.3813585-1-r41k0u@ubuntu.com> References: <20261205090934.3813585-1-r41k0u@ubuntu.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- .../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 +#include + +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