Skip to content

Commit 3cd5c89

Browse files
puranjaymohanAlexei Starovoitov
authored andcommitted
bpf: Let the verifier assign ids on stack fills
The next commit will allow clearing of scalar ids if no other register/stack slot has that id. This is because if only one register has a unique id, it can't participate in bounds propagation and is equivalent to having no id. But if the id of a stack slot is cleared by clear_singular_ids() in the next commit, reading that stack slot into a register will not establish a link because the stack slot's id is cleared. This can happen in a situation where a register is spilled and later loses its id due to a multiply operation (for example) and then the stack slot's id becomes singular and can be cleared. Make sure that scalar stack slots have an id before we read them into a register. Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Puranjay Mohan <puranjay@kernel.org> Link: https://lore.kernel.org/r/20260203165102.2302462-2-puranjay@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent d95d76a commit 3cd5c89

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

kernel/bpf/verifier.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5518,6 +5518,12 @@ static int check_stack_read_fixed_off(struct bpf_verifier_env *env,
55185518
*/
55195519
s32 subreg_def = state->regs[dst_regno].subreg_def;
55205520

5521+
if (env->bpf_capable && size == 4 && spill_size == 4 &&
5522+
get_reg_width(reg) <= 32)
5523+
/* Ensure stack slot has an ID to build a relation
5524+
* with the destination register on fill.
5525+
*/
5526+
assign_scalar_id_before_mov(env, reg);
55215527
copy_register_state(&state->regs[dst_regno], reg);
55225528
state->regs[dst_regno].subreg_def = subreg_def;
55235529

@@ -5563,6 +5569,11 @@ static int check_stack_read_fixed_off(struct bpf_verifier_env *env,
55635569
}
55645570
} else if (dst_regno >= 0) {
55655571
/* restore register state from stack */
5572+
if (env->bpf_capable)
5573+
/* Ensure stack slot has an ID to build a relation
5574+
* with the destination register on fill.
5575+
*/
5576+
assign_scalar_id_before_mov(env, reg);
55665577
copy_register_state(&state->regs[dst_regno], reg);
55675578
/* mark reg as written since spilled pointer state likely
55685579
* has its liveness marks cleared by is_state_visited()

0 commit comments

Comments
 (0)