bpf: Temporarily disable atomic operations in BPF arena
PATCH 1/1 bpf: Temporarily disable atomic operations in BPF arena
Currently, the x86 JIT handling PROBE_MEM32 tagged accesses is not equipped to handle atomic accesses into PTR_TO_ARENA, as no PROBE_MEM32 tagging is performed and no handling is enabled for them.
This will lead to unsafety as the offset into arena will dereferenced directly without turning it into a base + offset access into the arena region.
Since the changes to the x86 JIT will be fairly involved, for now, temporarily disallow use of PTR_TO_ARENA as the destination operand for atomics until support is added to the JIT backend.
--- kernel/bpf/verifier.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +9 -1
@@ -5682,6 +5682,13 @@ static bool is_flow_key_reg(struct bpf_verifier_env *env, int regno)return reg->type ==PTR_TO_FLOW_KEYS ; } +static bool is_arena_reg (struct bpf_verifier_env *env,int regno) +{ +const struct bpf_reg_state *reg =reg_state (env, regno); + +return reg->type ==PTR_TO_ARENA ; +} +static u32 *reg2btf_ids[__BPF_REG_TYPE_MAX] = { #ifdef CONFIG_NET [PTR_TO_SOCKET] = &btf_sock_ids[BTF_SOCK_TYPE_SOCK],
@@ -7019,7 +7026,8 @@ static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_iif (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_sk_reg (env, insn->dst_reg) || +is_arena_reg (env, insn->dst_reg)) {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));
Signature · 1 line
2.40.1
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Thu, 14 Mar 2024 17:49:31 +0000 you wrote:
Currently, the x86 JIT handling
PROBE_MEM32tagged accesses is not equipped to handle atomic accesses intoPTR_TO_ARENA, as noPROBE_MEM32tagging is performed and no handling is enabled for them.This will lead to unsafety as the offset into arena will dereferenced directly without turning it into a base + offset access into the arena region.
[...]
Here is the summary with links:
- [bpf] bpf: Temporarily disable atomic operations in BPF arena
https://git.kernel.org/bpf/bpf/c/44d79142ede8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html