Commit 0106b21
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
1 file changed
+5
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
21 | 16 | | |
22 | 17 | | |
23 | 18 | | |
0 commit comments