mirror of
https://github.com/torvalds/linux.git
synced 2026-06-02 03:24:19 +02:00
bpf: Factor out atomic_ptr_type_ok()
Factor out atomic_ptr_type_ok() as a helper function to be used later. Signed-off-by: Peilin Ye <yepeilin@google.com> Link: https://lore.kernel.org/r/e5ef8b3116f3fffce78117a14060ddce05eba52a.1740978603.git.yepeilin@google.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
f8ac5a4e1a
commit
66faaea94e
|
|
@ -6195,6 +6195,26 @@ static bool is_arena_reg(struct bpf_verifier_env *env, int regno)
|
|||
return reg->type == PTR_TO_ARENA;
|
||||
}
|
||||
|
||||
/* Return false if @regno contains a pointer whose type isn't supported for
|
||||
* atomic instruction @insn.
|
||||
*/
|
||||
static bool atomic_ptr_type_ok(struct bpf_verifier_env *env, int regno,
|
||||
struct bpf_insn *insn)
|
||||
{
|
||||
if (is_ctx_reg(env, regno))
|
||||
return false;
|
||||
if (is_pkt_reg(env, regno))
|
||||
return false;
|
||||
if (is_flow_key_reg(env, regno))
|
||||
return false;
|
||||
if (is_sk_reg(env, regno))
|
||||
return false;
|
||||
if (is_arena_reg(env, regno))
|
||||
return bpf_jit_supports_insn(insn, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static u32 *reg2btf_ids[__BPF_REG_TYPE_MAX] = {
|
||||
#ifdef CONFIG_NET
|
||||
[PTR_TO_SOCKET] = &btf_sock_ids[BTF_SOCK_TYPE_SOCK],
|
||||
|
|
@ -7652,11 +7672,7 @@ static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_i
|
|||
return -EACCES;
|
||||
}
|
||||
|
||||
if (is_ctx_reg(env, insn->dst_reg) ||
|
||||
is_pkt_reg(env, insn->dst_reg) ||
|
||||
is_flow_key_reg(env, insn->dst_reg) ||
|
||||
is_sk_reg(env, insn->dst_reg) ||
|
||||
(is_arena_reg(env, insn->dst_reg) && !bpf_jit_supports_insn(insn, true))) {
|
||||
if (!atomic_ptr_type_ok(env, insn->dst_reg, insn)) {
|
||||
verbose(env, "BPF_ATOMIC stores into R%d %s is not allowed\n",
|
||||
insn->dst_reg,
|
||||
reg_type_str(env, reg_state(env, insn->dst_reg)->type));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user