Skip to content

Commit 0106b21

Browse files
committed
selftests/bpf: Fix verifier_typedef test on 32-bit
This BPF assembly test accesses a struct field using a fixed offset based on a 64-bit environment, without any debug info usable for relocation or rewriting of accesses. This fails on 32-bit armhf: tester_init:PASS:tester_log_buf 0 nsec process_subtest:PASS:obj_open_mem 0 nsec process_subtest:PASS:specs_alloc 0 nsec run_subtest:PASS:obj_open_mem 0 nsec libbpf: prog 'resolve_typedef': BPF program load failed: -EACCES libbpf: prog 'resolve_typedef': failed to load: -EACCES libbpf: failed to load object 'verifier_typedef' run_subtest:FAIL:unexpected_load_failure unexpected error: -13 (errno 13) VERIFIER LOG: ============= Global function resolve_typedef() doesn't return scalar. Only those are supported. 0: R1=ctx() R10=fp0 ; asm volatile (" \ @ verifier_typedef.c:12 0: (79) r1 = *(u64 *)(r1 +0) func 'bpf_fentry_test_sinfo' arg0 has btf_id 10943 type STRUCT 'skb_shared_info' 1: R1_w=ptr_skb_shared_info() 1: (79) r2 = *(u64 *)(r1 +56) access beyond the end of member netmem (mend:4) in struct skb_frag with off 0 size 8 processed 2 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 ============= torvalds#561/1 verifier_typedef/typedef: resolve:FAIL torvalds#561 verifier_typedef:FAIL Fix this by rewriting resolve_typedef() in C with explicit field references which can be run-time patched, resulting in 32-bit appropriate code: int resolve_typedef(unsigned long long * ctx): ; int BPF_PROG(resolve_typedef, struct skb_shared_info *si) 0: (b7) r2 = 44 ; int BPF_PROG(resolve_typedef, struct skb_shared_info *si) 1: (79) r1 = *(u64 *)(r1 +0) 2: (0f) r1 += r2 ; volatile netmem_ref tmp __attribute__((unused)) = si->frags->netmem; 3: (61) r1 = *(u32 *)(r1 +0) Fixes: 2597a25 ("selftests/bpf: Add test to exercise typedef walking") Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
1 parent 029ffbe commit 0106b21

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@
22

33
#include <vmlinux.h>
44
#include <bpf/bpf_helpers.h>
5+
#include <bpf/bpf_tracing.h>
56
#include "bpf_misc.h"
67

78
SEC("fentry/bpf_fentry_test_sinfo")
89
__description("typedef: resolve")
910
__success __retval(0)
10-
__naked void resolve_typedef(void)
11+
int BPF_PROG(resolve_typedef, struct skb_shared_info *si)
1112
{
12-
asm volatile (" \
13-
r1 = *(u64 *)(r1 +0); \
14-
r2 = *(u64 *)(r1 +%[frags_offs]); \
15-
r0 = 0; \
16-
exit; \
17-
" :
18-
: __imm_const(frags_offs,
19-
offsetof(struct skb_shared_info, frags))
20-
: __clobber_all);
13+
volatile netmem_ref tmp __attribute__((unused)) = si->frags->netmem;
14+
15+
return 0;
2116
}
2217

2318
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)