From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
Nicholas Carlini <npc@anthropic.com>,
kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf v1 4/8] selftests/bpf: Test btf lookup helper sleepability
Date: Thu, 3 Sep 2026 23:47:50 +0200 [thread overview]
Message-ID: <20260903214758.2727663-5-memxor@gmail.com> (raw)
In-Reply-To: <20260903214758.2727663-1-memxor@gmail.com>
Add an expected failure case which calls
bpf_btf_find_by_name_kind() from a BPF timer callback. Without the
helper prototype being marked sleepable, the verifier accepts the
program and the load unexpectedly succeeds.
Also add a positive control which calls the helper directly from a
syscall program. This verifies that marking the helper sleepable only
rejects it in non-sleepable regions.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
.../bpf/progs/verifier_async_cb_context.c | 34 +++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_async_cb_context.c b/tools/testing/selftests/bpf/progs/verifier_async_cb_context.c
index a7c84d3fa4c7..e0926767bbd3 100644
--- a/tools/testing/selftests/bpf/progs/verifier_async_cb_context.c
+++ b/tools/testing/selftests/bpf/progs/verifier_async_cb_context.c
@@ -108,6 +108,30 @@ int timer_sys_close_prog(void *ctx)
return 0;
}
+static int timer_btf_find_cb(void *map, int *key, struct bpf_timer *timer)
+{
+ char name[] = "task_struct";
+
+ bpf_btf_find_by_name_kind(name, sizeof(name), BTF_KIND_STRUCT, 0);
+ return 0;
+}
+
+SEC("syscall")
+__failure __msg("sleepable helper bpf_btf_find_by_name_kind#{{[0-9]+}} in non-sleepable prog")
+int timer_btf_find_prog(void *ctx)
+{
+ struct timer_elem *val;
+ int key = 0;
+
+ val = bpf_map_lookup_elem(&timer_map, &key);
+ if (!val)
+ return 0;
+
+ bpf_timer_init(&val->t, &timer_map, 0);
+ bpf_timer_set_callback(&val->t, timer_btf_find_cb);
+ return 0;
+}
+
SEC("syscall")
__success
int syscall_sys_bpf_prog(void *ctx)
@@ -126,6 +150,16 @@ int syscall_sys_close_prog(void *ctx)
return 0;
}
+SEC("syscall")
+__success
+int syscall_btf_find_prog(void *ctx)
+{
+ char name[] = "task_struct";
+
+ bpf_btf_find_by_name_kind(name, sizeof(name), BTF_KIND_STRUCT, 0);
+ return 0;
+}
+
/* Workqueue tests */
struct wq_elem {
--
2.53.0
next prev parent reply other threads:[~2026-09-03 21:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 21:47 [PATCH bpf v1 0/8] Misc bug fixes - part 2 Kumar Kartikeya Dwivedi
2026-09-03 21:47 ` [PATCH bpf v1 1/8] bpf: Check ancestor frames for rbtree callbacks Kumar Kartikeya Dwivedi
2026-09-03 22:40 ` Eduard Zingerman
2026-09-03 22:56 ` bot+bpf-ci
2026-09-03 21:47 ` [PATCH bpf v1 2/8] selftests/bpf: Check rbtree callback restrictions in subprogs Kumar Kartikeya Dwivedi
2026-09-03 22:56 ` bot+bpf-ci
2026-09-03 21:47 ` [PATCH bpf v1 3/8] bpf: Mark bpf_btf_find_by_name_kind() as sleepable Kumar Kartikeya Dwivedi
2026-09-03 22:15 ` Eduard Zingerman
2026-09-03 21:47 ` Kumar Kartikeya Dwivedi [this message]
2026-09-03 21:47 ` [PATCH bpf v1 5/8] bpf: Mark faultable stack helpers " Kumar Kartikeya Dwivedi
2026-09-03 22:00 ` Eduard Zingerman
2026-09-03 22:56 ` bot+bpf-ci
2026-09-03 21:47 ` [PATCH bpf v1 6/8] selftests/bpf: Check faultable stack helper contexts Kumar Kartikeya Dwivedi
2026-09-03 22:56 ` bot+bpf-ci
2026-09-03 21:47 ` [PATCH bpf v1 7/8] bpf: Reject legacy packet loads from callbacks Kumar Kartikeya Dwivedi
2026-09-03 21:58 ` Eduard Zingerman
2026-09-04 2:22 ` Alexei Starovoitov
2026-09-03 21:47 ` [PATCH bpf v1 8/8] selftests/bpf: " Kumar Kartikeya Dwivedi
2026-09-04 2:30 ` [PATCH bpf v1 0/8] Misc bug fixes - part 2 patchwork-bot+netdevbpf
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=20260903214758.2727663-5-memxor@gmail.com \
--to=memxor@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=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=npc@anthropic.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.