selftests/bpf: Test Program Structure diagnostic context

Exercise each corrected Program Structure report. Place a
missing-table gotox after another instruction so its attribution
differs from the subprogram start.

Add malformed subprogram layouts for a branch crossing a subprogram
boundary and a subprogram that falls through its end. Both cases carry
BTF line records and assert that their structured reports include the
corresponding source function and file.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/cf2f420c2b21de440a7dc51b1565c0f06d4b539640ee5c03384e5d77bcfb5686@mail.kernel.org/
Link: https://lore.kernel.org/r/20260924170646.2366016-8-memxor@gmail.com
Link: https://lore.kernel.org/bpf/20260926133048.2962553-4-memxor@gmail.com
This commit is contained in:
Kumar Kartikeya Dwivedi 2026-09-26 15:30:45 +02:00 committed by Daniel Borkmann
parent d91052063b
commit 917cfd1ed5
2 changed files with 42 additions and 0 deletions

View File

@ -56,6 +56,46 @@ __naked void out_of_range_jump2(void)
" ::: __clobber_all);
}
static __naked __noinline __used int cross_subprog_target(void)
{
asm volatile (" \
r0 = 0; \
exit; \
" ::: __clobber_all);
}
SEC("socket")
__description("jump across subprogram boundary")
__failure __msg("jump out of range from insn 1")
__msg("jump_across_subprog_boundary @ verifier_cfg.c")
__naked void jump_across_subprog_boundary(void)
{
asm volatile (" \
call cross_subprog_target; \
goto +1; \
exit; \
" ::: __clobber_all);
}
static __naked __noinline __used int fallthrough_subprog(void)
{
asm volatile (" \
r0 = 0; \
" ::: __clobber_all);
}
SEC("socket")
__description("subprogram fallthrough")
__failure __msg("last insn is not an exit or jmp")
__msg("fallthrough_subprog @ verifier_cfg.c")
__naked void subprog_fallthrough(void)
{
asm volatile (" \
call fallthrough_subprog; \
exit; \
" ::: __clobber_all);
}
SEC("socket")
__description("invalid DW LDSX instruction in diagnostics")
__failure __msg("BUG_ldx_99")

View File

@ -101,9 +101,11 @@ __naked void jump_table_terminal_gotox_subprog(void)
*/
SEC("socket")
__failure __msg("no jump tables found for subprog starting at 0")
__msg(">>> 1 | (0d) gotox r0")
__naked void jump_table_no_jump_table(void)
{
asm volatile (" \
r0 = 0; \
.8byte %[gotox_r0]; \
r0 = 1; \
exit; \