BPF subprogram scalar arguments are checked separately even though the common argument checker enforces the same SCALAR_VALUE requirement. Start the migration by routing the scalar branch through check_func_arg() and update the verifier-log expectation. Use the BTF parameter index for metadata and the ABI slot index for register lookup. Route extra slots of by-value aggregates through check_arg_extra_slot() so every occupied slot follows the common path. Following patches can extend this guarded common-check branch as each remaining BPF-subprogram-specific implementation is removed. Signed-off-by: Amery Hung --- kernel/bpf/verifier.c | 19 ++++++------------- .../selftests/bpf/progs/aggregate_arg_func.c | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 65a1245e4edb..a84143285b3f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -10871,10 +10871,9 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, nslots = btf_arg_slots(t); if (arg_type == ARG_SCALAR) { - if (reg->type != SCALAR_VALUE) { - bpf_log(log, "%s is not a scalar\n", reg_arg_name(env, argno)); - return -EINVAL; - } + ret = check_func_arg(env, arg, slot, 0, &meta, env->insn_idx); + if (ret) + return ret; } else if (arg_type & PTR_UNTRUSTED) { /* * Anything is allowed for untrusted arguments, as these are @@ -10964,15 +10963,9 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, } for (k = 1; k < nslots; k++) { - argno_t extra_argno = argno_from_arg(slot + k + 1); - struct bpf_reg_state *extra_reg; - - extra_reg = get_func_arg_reg(caller, regs, slot + k); - if (extra_reg->type != SCALAR_VALUE) { - bpf_log(log, "%s is not a scalar\n", - reg_arg_name(env, extra_argno)); - return -EINVAL; - } + ret = check_arg_extra_slot(env, caller, slot + k, &meta); + if (ret) + return ret; } } diff --git a/tools/testing/selftests/bpf/progs/aggregate_arg_func.c b/tools/testing/selftests/bpf/progs/aggregate_arg_func.c index d0a4f84a6fbf..2132b926a8f0 100644 --- a/tools/testing/selftests/bpf/progs/aggregate_arg_func.c +++ b/tools/testing/selftests/bpf/progs/aggregate_arg_func.c @@ -43,7 +43,7 @@ __naked int aggregate_arg_pair_asm(void) } SEC("tc") -__failure __msg("R2 is not a scalar") +__failure __msg("R2 type=fp expected=scalar") __naked int aggregate_arg_pair_ptr_fail(void) { asm volatile ( -- 2.52.0