Skip to content

Commit 8837c16

Browse files
etsalgregkh
authored andcommitted
bpf: Allow instructions with arena source and non-arena dest registers
[ Upstream commit ac61bff ] The compiler sometimes stores the result of a PTR_TO_ARENA and SCALAR operation into the scalar register rather than the pointer register. Relax the verifier to allow operations between a source arena register and a destination non-arena register, marking the destination's value as a PTR_TO_ARENA. Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Acked-by: Song Liu <song@kernel.org> Fixes: 6082b6c ("bpf: Recognize addr_space_cast instruction in the verifier.") Link: https://lore.kernel.org/r/20260412174546.18684-2-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f00037a commit 8837c16

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

kernel/bpf/verifier.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14434,11 +14434,20 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
1443414434
int err;
1443514435

1443614436
dst_reg = &regs[insn->dst_reg];
14437-
src_reg = NULL;
14437+
if (BPF_SRC(insn->code) == BPF_X)
14438+
src_reg = &regs[insn->src_reg];
14439+
else
14440+
src_reg = NULL;
1443814441

14439-
if (dst_reg->type == PTR_TO_ARENA) {
14442+
/* Case where at least one operand is an arena. */
14443+
if (dst_reg->type == PTR_TO_ARENA || (src_reg && src_reg->type == PTR_TO_ARENA)) {
1444014444
struct bpf_insn_aux_data *aux = cur_aux(env);
1444114445

14446+
if (dst_reg->type != PTR_TO_ARENA)
14447+
*dst_reg = *src_reg;
14448+
14449+
dst_reg->subreg_def = env->insn_idx + 1;
14450+
1444214451
if (BPF_CLASS(insn->code) == BPF_ALU64)
1444314452
/*
1444414453
* 32-bit operations zero upper bits automatically.
@@ -14454,7 +14463,6 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
1445414463
ptr_reg = dst_reg;
1445514464

1445614465
if (BPF_SRC(insn->code) == BPF_X) {
14457-
src_reg = &regs[insn->src_reg];
1445814466
if (src_reg->type != SCALAR_VALUE) {
1445914467
if (dst_reg->type != SCALAR_VALUE) {
1446014468
/* Combining two pointers by any ALU op yields

0 commit comments

Comments
 (0)