Skip to content

Commit 38498c0

Browse files
sinkapAlexei Starovoitov
authored andcommitted
selftests/bpf: Adjust verifier_map_ptr for the map's excl field
Adding the u32 excl field at offset 32 of struct bpf_map right after the sha[SHA256_DIGEST_SIZE] hash shifts the ops pointer from offset 32 to 40. Therefore, fix up the test case. # LDLIBS=-static PKG_CONFIG='pkg-config --static' ./vmtest.sh -- ./test_progs -t verifier_map_ptr [...] #637/1 verifier_map_ptr/bpf_map_ptr: read with negative offset rejected:OK #637/2 verifier_map_ptr/bpf_map_ptr: read with negative offset rejected @unpriv:OK #637/3 verifier_map_ptr/bpf_map_ptr: write rejected:OK #637/4 verifier_map_ptr/bpf_map_ptr: write rejected @unpriv:OK #637/5 verifier_map_ptr/bpf_map_ptr: read non-existent field rejected:OK #637/6 verifier_map_ptr/bpf_map_ptr: read non-existent field rejected @unpriv:OK #637/7 verifier_map_ptr/bpf_map_ptr: read ops field accepted:OK #637/8 verifier_map_ptr/bpf_map_ptr: read ops field accepted @unpriv:OK [...] Summary: 2/18 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: KP Singh <kpsingh@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/r/20260601150248.394863-7-daniel@iogearbox.net Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 6021443 commit 38498c0

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ __naked void bpf_map_ptr_write_rejected(void)
7070
: __clobber_all);
7171
}
7272

73-
/* The first element of struct bpf_map is a SHA256 hash of 32 bytes, accessing
74-
* into this array is valid. The opts field is now at offset 33.
73+
/*
74+
* struct bpf_map starts with the SHA256 hash sha[32] at offset 0 (a readable
75+
* byte array), followed by the u32 excl field at offset 32. Reading a u32 at
76+
* offset 33 runs past the end of excl and is rejected.
7577
*/
7678
SEC("socket")
7779
__description("bpf_map_ptr: read non-existent field rejected")
7880
__failure
79-
__msg("cannot access ptr member ops with moff 32 in struct bpf_map with off 33 size 4")
81+
__msg("access beyond the end of member excl (mend:36) in struct bpf_map with off 33 size 4")
8082
__failure_unpriv
8183
__msg_unpriv("access is allowed only to CAP_PERFMON and CAP_SYS_ADMIN")
8284
__flag(BPF_F_ANY_ALIGNMENT)

0 commit comments

Comments
 (0)