Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kernel/bpf/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -15645,7 +15645,8 @@ static int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)
}

/* check dest operand */
if (opcode == BPF_NEG) {
if (opcode == BPF_NEG &&
regs[insn->dst_reg].type == SCALAR_VALUE) {
err = check_reg_arg(env, insn->dst_reg, DST_OP_NO_MARK);
err = err ?: adjust_scalar_min_max_vals(env, insn,
&regs[insn->dst_reg],
Expand Down
18 changes: 18 additions & 0 deletions tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ l0_%=: exit; \
: __clobber_all);
}

SEC("socket")
__description("map_ptr illegal alu op, map_ptr = -map_ptr")
__failure __msg("R0 invalid mem access 'scalar'")
__failure_unpriv __msg_unpriv("R0 pointer arithmetic prohibited")
__flag(BPF_F_ANY_ALIGNMENT)
__naked void map_ptr_illegal_alu_op(void)
{
asm volatile (" \
r0 = %[map_hash_48b] ll; \
r0 = -r0; \
r1 = 22; \
*(u64*)(r0 + 0) = r1; \
exit; \
" :
: __imm_addr(map_hash_48b)
: __clobber_all);
}

SEC("flow_dissector")
__description("flow_keys illegal alu op with variable offset")
__failure __msg("R7 pointer arithmetic on flow_keys prohibited")
Expand Down
Loading