Skip to content

Commit cddf2bd

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 9d51c86 commit cddf2bd

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
@@ -15705,11 +15705,20 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
1570515705
int err;
1570615706

1570715707
dst_reg = &regs[insn->dst_reg];
15708-
src_reg = NULL;
15708+
if (BPF_SRC(insn->code) == BPF_X)
15709+
src_reg = &regs[insn->src_reg];
15710+
else
15711+
src_reg = NULL;
1570915712

15710-
if (dst_reg->type == PTR_TO_ARENA) {
15713+
/* Case where at least one operand is an arena. */
15714+
if (dst_reg->type == PTR_TO_ARENA || (src_reg && src_reg->type == PTR_TO_ARENA)) {
1571115715
struct bpf_insn_aux_data *aux = cur_aux(env);
1571215716

15717+
if (dst_reg->type != PTR_TO_ARENA)
15718+
*dst_reg = *src_reg;
15719+
15720+
dst_reg->subreg_def = env->insn_idx + 1;
15721+
1571315722
if (BPF_CLASS(insn->code) == BPF_ALU64)
1571415723
/*
1571515724
* 32-bit operations zero upper bits automatically.
@@ -15725,7 +15734,6 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
1572515734
ptr_reg = dst_reg;
1572615735

1572715736
if (BPF_SRC(insn->code) == BPF_X) {
15728-
src_reg = &regs[insn->src_reg];
1572915737
if (src_reg->type != SCALAR_VALUE) {
1573015738
if (dst_reg->type != SCALAR_VALUE) {
1573115739
/* Combining two pointers by any ALU op yields

0 commit comments

Comments
 (0)