mirror of
https://github.com/edk2-porting/linux-next.git
synced 2025-01-01 10:13:58 +08:00
bpf: Make reference tracking generic
Instead of dealing with reg->ref_obj_id individually for every arg type that needs it, rely on the fact that ref_obj_id is zero if the register is not reference tracked. Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/bpf/20200921121227.255763-7-lmb@cloudflare.com
This commit is contained in:
parent
d7b9454a4f
commit
02f7c9585d
@ -4030,15 +4030,6 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
|
|||||||
/* Any sk pointer can be ARG_PTR_TO_SOCK_COMMON */
|
/* Any sk pointer can be ARG_PTR_TO_SOCK_COMMON */
|
||||||
if (!type_is_sk_pointer(type))
|
if (!type_is_sk_pointer(type))
|
||||||
goto err_type;
|
goto err_type;
|
||||||
if (reg->ref_obj_id) {
|
|
||||||
if (meta->ref_obj_id) {
|
|
||||||
verbose(env, "verifier internal error: more than one arg with ref_obj_id R%d %u %u\n",
|
|
||||||
regno, reg->ref_obj_id,
|
|
||||||
meta->ref_obj_id);
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
|
||||||
meta->ref_obj_id = reg->ref_obj_id;
|
|
||||||
}
|
|
||||||
} else if (arg_type == ARG_PTR_TO_SOCKET ||
|
} else if (arg_type == ARG_PTR_TO_SOCKET ||
|
||||||
arg_type == ARG_PTR_TO_SOCKET_OR_NULL) {
|
arg_type == ARG_PTR_TO_SOCKET_OR_NULL) {
|
||||||
expected_type = PTR_TO_SOCKET;
|
expected_type = PTR_TO_SOCKET;
|
||||||
@ -4087,13 +4078,6 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
|
|||||||
/* final test in check_stack_boundary() */;
|
/* final test in check_stack_boundary() */;
|
||||||
else if (type != expected_type)
|
else if (type != expected_type)
|
||||||
goto err_type;
|
goto err_type;
|
||||||
if (meta->ref_obj_id) {
|
|
||||||
verbose(env, "verifier internal error: more than one arg with ref_obj_id R%d %u %u\n",
|
|
||||||
regno, reg->ref_obj_id,
|
|
||||||
meta->ref_obj_id);
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
|
||||||
meta->ref_obj_id = reg->ref_obj_id;
|
|
||||||
} else if (arg_type_is_int_ptr(arg_type)) {
|
} else if (arg_type_is_int_ptr(arg_type)) {
|
||||||
expected_type = PTR_TO_STACK;
|
expected_type = PTR_TO_STACK;
|
||||||
if (!type_is_pkt_pointer(type) &&
|
if (!type_is_pkt_pointer(type) &&
|
||||||
@ -4125,6 +4109,16 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reg->ref_obj_id) {
|
||||||
|
if (meta->ref_obj_id) {
|
||||||
|
verbose(env, "verifier internal error: more than one arg with ref_obj_id R%d %u %u\n",
|
||||||
|
regno, reg->ref_obj_id,
|
||||||
|
meta->ref_obj_id);
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
meta->ref_obj_id = reg->ref_obj_id;
|
||||||
|
}
|
||||||
|
|
||||||
if (arg_type == ARG_CONST_MAP_PTR) {
|
if (arg_type == ARG_CONST_MAP_PTR) {
|
||||||
/* bpf_map_xxx(map_ptr) call: remember that map_ptr */
|
/* bpf_map_xxx(map_ptr) call: remember that map_ptr */
|
||||||
meta->map_ptr = reg->map_ptr;
|
meta->map_ptr = reg->map_ptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user