bpf: Replace (arg_type & MEM_RDONLY) with type_is_rdonly_mem
PATCH 1/1 bpf: Replace (arg_type & MEM_RDONLY) with type_is_rdonly_mem
From: Feng Yang <[email protected]>
The existing 'type_is_rdonly_mem' function is more formal in linux source
--- kernel/bpf/verifier.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/bpf/verifier.c +3 -3
@@ -7779,7 +7779,7 @@ static int process_dynptr_func(struct bpf_verifier_env *env, int regno, int insn err =mark_stack_slots_dynptr (env, reg, arg_type, insn_idx, clone_ref_obj_id); }else /* MEM_RDONLY and None case from above */ {/* For the reg->type == PTR_TO_STACK case, bpf_dynptr is never const */ -if (reg->type ==CONST_PTR_TO_DYNPTR && !(arg_type &MEM_RDONLY )) { +if (reg->type ==CONST_PTR_TO_DYNPTR && !type_is_rdonly_mem (arg_type)) {verbose (env,"cannot pass pointer to const bpf_dynptr, the helper mutates it\n" );return -EINVAL ; }
@@ -8324,7 +8324,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,* * Therefore we fold these flags depending on the arg_type before comparison. */ -if (arg_type &MEM_RDONLY ) +if (type_is_rdonly_mem (arg_type)) type &= ~MEM_RDONLY ;if (arg_type &PTR_MAYBE_NULL ) type &= ~PTR_MAYBE_NULL ;
@@ -8356,7 +8356,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,return 0 ;if (compatible == &mem_types) { -if (!(arg_type &MEM_RDONLY )) { +if (!type_is_rdonly_mem (arg_type)) { verbose(env, "%s() may write into memory pointed by R%d type=%s\n", func_id_name(meta->func_id),
Signature · 1 line
2.27.0
Quoted 5 lines · Feng Yang
From: Feng Yang <[email protected]>
The existing '
type_is_rdonly_mem' function is more formal in linux sourceSigned-off-by Feng Yang <[email protected]>
Looks ok, but I'm not sure this cleanup is worth it on its own..
Quoted 11 lines · Stanislav Fomichev
Quoted 5 lines · Feng Yang
From: Feng Yang <[email protected]>
The existing '
type_is_rdonly_mem' function is more formal in linux sourceSigned-off-by Feng Yang <[email protected]>Looks ok, but I'm not sure this cleanup is worth it on its own..
Yeah.
If we do this let's change type_is_rdonly_mem(u32 type) to enum as well.
pw-bot: cr
Quoted 5 lines
Yeah.
If we do this let's changetype_is_rdonly_mem(u32 type)to enum as well.pw-bot: cr
It needs to receive bpf_reg_type and bpf_arg_type, and base_type(u32 type) is also u32.