Skip to content

Commit 511a5db

Browse files
kkdwvdAlexei Starovoitov
authored andcommitted
selftests/bpf: Cover global subprog exception leaks
Add a verifier failure case where the caller holds a reference across a global subprog call that may throw. The program must be rejected because the exceptional path would skip the caller's reference release. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20260517075530.3461166-3-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 3d562d3 commit 511a5db

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

tools/testing/selftests/bpf/progs/exceptions_fail.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,28 @@ int reject_with_reference(void *ctx)
208208
return 0;
209209
}
210210

211+
__noinline int global_subprog_may_throw(struct __sk_buff *ctx)
212+
{
213+
if (ctx->len)
214+
bpf_throw(0);
215+
return 0;
216+
}
217+
218+
SEC("?tc")
219+
__failure __msg("Unreleased reference")
220+
int reject_global_subprog_throw_with_reference(struct __sk_buff *ctx)
221+
{
222+
struct foo *f;
223+
224+
f = bpf_obj_new(typeof(*f));
225+
if (!f)
226+
return 0;
227+
if (ctx->protocol)
228+
global_subprog_may_throw(ctx);
229+
bpf_obj_drop(f);
230+
return 0;
231+
}
232+
211233
__noinline static int subprog_ref(struct __sk_buff *ctx)
212234
{
213235
struct foo *f;

0 commit comments

Comments
 (0)