Skip to content

Commit 503e4de

Browse files
DanielTimLeeanakryiko
authored andcommitted
bpf: Replace open code with for allocated object check
>From commit 282de14 ("bpf: Introduce allocated objects support"), With this allocated object with BPF program, (PTR_TO_BTF_ID | MEM_ALLOC) has been a way of indicating to check the type is the allocated object. commit d8939cb ("bpf: Loosen alloc obj test in verifier's reg_btf_record") >From the commit, there has been helper function for checking this, named type_is_ptr_alloc_obj(). But still, some of the code use open code to retrieve this info. This commit replaces the open code with the type_is_alloc(), and the type_is_ptr_alloc_obj() function. Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20230527122706.59315-1-danieltimlee@gmail.com
1 parent 4114866 commit 503e4de

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/bpf/verifier.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5894,7 +5894,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
58945894
* program allocated objects (which always have ref_obj_id > 0),
58955895
* but not for untrusted PTR_TO_BTF_ID | MEM_ALLOC.
58965896
*/
5897-
if (atype != BPF_READ && reg->type != (PTR_TO_BTF_ID | MEM_ALLOC)) {
5897+
if (atype != BPF_READ && !type_is_ptr_alloc_obj(reg->type)) {
58985898
verbose(env, "only read is supported\n");
58995899
return -EACCES;
59005900
}
@@ -7514,7 +7514,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,
75147514
if (base_type(arg_type) == ARG_PTR_TO_MEM)
75157515
type &= ~DYNPTR_TYPE_FLAG_MASK;
75167516

7517-
if (meta->func_id == BPF_FUNC_kptr_xchg && type & MEM_ALLOC)
7517+
if (meta->func_id == BPF_FUNC_kptr_xchg && type_is_alloc(type))
75187518
type &= ~MEM_ALLOC;
75197519

75207520
for (i = 0; i < ARRAY_SIZE(compatible->types); i++) {

0 commit comments

Comments
 (0)