From: Qiliang Yuan <odys.yuan@gmail.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Luis Gerhorst <luis.gerhorst@fau.de>,
Henriette Herzog <henriette.herzog@rub.de>,
Anton Protopopov <a.s.protopopov@gmail.com>,
Xu Kuohai <xukuohai@huawei.com>,
Hengqi Chen <hengqi.chen@gmail.com>,
Shuah Khan <shuah@kernel.org>
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Qiliang Yuan <odys.yuan@gmail.com>
Subject: [PATCH bpf-next 5/5] selftests/bpf: Test log_true_size with an error from blinding
Date: Mon, 02 Nov 2026 07:37:05 -0500 [thread overview]
Message-ID: <20261102-bpf-blind-nops-fixes-v1-5-844300e42cdb@gmail.com> (raw)
In-Reply-To: <20261102-bpf-blind-nops-fixes-v1-0-844300e42cdb@gmail.com>
A prog of one function gets its constants blinded when its runtime is
selected, which can log an error.
No test checks that log_true_size counts such an error.
Load a prog whose jump goes over 11000 constants with bpf_jit_harden=2.
Blinding pushes the jump out of its 16-bit range, and the message must
be in the log and in log_true_size.
Reported-by: Alexei Starovoitov <ast@kernel.org>
Closes: https://lore.kernel.org/bpf/DMKHZS5B5CNO.186F6YH1T6YU4@gmail.com/
Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
---
.../selftests/bpf/prog_tests/blinding_log.c | 59 ++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/blinding_log.c b/tools/testing/selftests/bpf/prog_tests/blinding_log.c
new file mode 100644
index 0000000000000..658a8494dae5b
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/blinding_log.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0
+/* The verifier log of a prog whose constants are blinded */
+
+#include <test_progs.h>
+#include <linux/filter.h>
+#include "sysctl_helpers.h"
+
+#define NR_CONSTS 11000
+#define LOG_SIZE 65536
+
+/*
+ * A prog of one function gets its constants blinded when its runtime is
+ * selected. Each 'r0 += 1' becomes 3 insns, which pushes the jump over them
+ * out of its 16-bit range. Serial, because it sets bpf_jit_harden.
+ */
+void serial_test_blinding_log(void)
+{
+ const char *harden = "/proc/sys/net/core/bpf_jit_harden";
+ LIBBPF_OPTS(bpf_prog_load_opts, opts);
+ struct bpf_insn *insns;
+ char old[16] = {}, *log;
+ int i, cnt = 0, fd;
+
+ if (!is_jit_enabled()) {
+ printf("%s:SKIP:JIT is disabled\n", __func__);
+ test__skip();
+ return;
+ }
+
+ insns = calloc(NR_CONSTS + 3, sizeof(*insns));
+ log = calloc(1, LOG_SIZE);
+ if (!ASSERT_OK_PTR(insns, "insns") || !ASSERT_OK_PTR(log, "log"))
+ goto out;
+
+ insns[cnt++] = BPF_EMIT_CALL(BPF_FUNC_get_prandom_u32);
+ insns[cnt++] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, NR_CONSTS);
+ for (i = 0; i < NR_CONSTS; i++)
+ insns[cnt++] = BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 1);
+ insns[cnt++] = BPF_EXIT_INSN();
+
+ opts.log_buf = log;
+ opts.log_size = LOG_SIZE;
+ /* log stats only: level 1 logs each insn, which wraps the buffer */
+ opts.log_level = 4;
+ if (sysctl_set_or_fail(harden, old, "2"))
+ goto out;
+ fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL", insns, cnt, &opts);
+ sysctl_set_or_fail(harden, NULL, old);
+ /* don't mind whether the interpreter takes the prog or the load fails */
+ if (fd >= 0)
+ close(fd);
+
+ /* expect the message about the jump in the log and in log_true_size */
+ ASSERT_HAS_SUBSTR(log, "cannot be patched due to 16-bit range", "log");
+ ASSERT_EQ(opts.log_true_size, strlen(log) + 1, "log_true_size");
+out:
+ free(insns);
+ free(log);
+}
--
2.43.0
prev parent reply other threads:[~2026-11-02 12:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 12:37 [PATCH bpf-next 0/5] bpf: Fix three bugs around constant blinding and nop removal Qiliang Yuan
2026-11-02 12:37 ` [PATCH bpf-next 1/5] bpf: Put the line info back when the JIT falls back after blinding Qiliang Yuan
2026-11-02 12:37 ` [PATCH bpf-next 2/5] bpf: Keep the barrier of a nospec insn when removing nops Qiliang Yuan
2026-11-02 12:37 ` [PATCH bpf-next 3/5] bpf: Finalize the verifier log after the runtime is selected Qiliang Yuan
2026-11-02 12:37 ` [PATCH bpf-next 4/5] selftests/bpf: Cover a nospec jump that becomes a nop Qiliang Yuan
2026-11-02 12:37 ` Qiliang Yuan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261102-bpf-blind-nops-fixes-v1-5-844300e42cdb@gmail.com \
--to=odys.yuan@gmail.com \
--cc=a.s.protopopov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hengqi.chen@gmail.com \
--cc=henriette.herzog@rub.de \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=luis.gerhorst@fau.de \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=xukuohai@huawei.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®