Unify subprog argument checks
Subsystems (4)
v3 cover Unify subprog argument checks
Hi,
Helper and kfunc calls now validate arguments through check_func_args(), while subprog calls still duplicate much of the same validation in btf_check_func_arg_match(). This makes common argument rules and diagnostics easy to change for one call kind without updating the other.
This series builds a temporary helper-style argument prototype from the subprog's cached BTF metadata, then moves each supported argument class to the common checker. The last patch removes the duplicate loop.
The series is organized as follows:
- Patch 1 fixes kfunc BTF parameter lookups after wide arguments.
- Patches 2-3 identify subprog calls in common metadata and generate the temporary argument prototype.
- Patches 4-9 move scalar, untrusted, context, arena, dynptr, and BTF-ID arguments to the common path.
- Patch 10 moves global subprog memory arguments and their packet-change check to the common path.
- Patch 11 removes the legacy loop and checks all subprog arguments through check_func_args().
This follows the helper/kfunc argument-checking consolidation:
https://lore.kernel.org/bpf/[email protected]/
v2 -> v3:
- Remove the redundant dynptr register-type check from process_dynptr_func() after all callers begin using check_func_arg() (Sashiko)
v1 -> v2:
- Extend patch 1 to fix the release and iterator BTF parameter lookups after wide arguments (Alexei)
- Keep subprog call metadata local to argument checking, leaving callers and helper/kfunc handling unchanged (Alexei)
Amery Hung (11):
bpf: Fix kfunc BTF parameter lookups after wide arguments
bpf: Identify subprog calls in argument metadata
bpf: Build argument prototypes for subprog calls
bpf: Check subprog scalar arguments in the common path
bpf: Check global subprog untrusted arguments in the common path
bpf: Check subprog context arguments in the common path
bpf: Check subprog arena arguments in the common path
bpf: Check subprog dynptr arguments in the common path
bpf: Check global subprog BTF-ID arguments in the common path
bpf: Check global subprog memory arguments in the common path
bpf: Check all subprog arguments in the common path
include/linux/bpf_verifier.h | 6 +- kernel/bpf/verifier.c | 283 +++++++----------- .../selftests/bpf/progs/aggregate_arg_func.c | 2 +- .../testing/selftests/bpf/progs/dynptr_fail.c | 11 +- .../selftests/bpf/progs/test_global_func5.c | 2 +- .../bpf/progs/verifier_global_ptr_args.c | 7 +- .../bpf/progs/verifier_global_subprogs.c | 2 +- 7 files changed, 129 insertions(+), 184 deletions(-)
Signature · 1 line
2.52.0
PATCH v3 1/11 bpf: Fix kfunc BTF parameter lookups after wide arguments
Several kfunc argument checks index BTF parameters using the ABI slot number. Parameter and slot indexes diverge after a by-value argument wider than one eightbyte, so a later argument can select the wrong BTF parameter or index past the end of the function prototype.
This affects the BTF lookups in check_func_arg_nullability() and check_func_arg_release(), and the parameter passed to btf_check_iter_arg() by process_iter_arg().
check_func_arg() already tracks the BTF parameter and ABI slot separately. Pass the parameter index to all three consumers while retaining argno for register and stack-slot diagnostics.
--- kernel/bpf/verifier.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
kernel/bpf/verifier.c +10 -10
@@ -8264,12 +8264,12 @@ static bool is_kfunc_arg_iter(struct bpf_call_arg_meta *meta, int arg_idx,return btf_param_match_suffix (meta->btf, arg,"__iter" ); } -static int process_iter_arg (struct bpf_verifier_env *env,struct bpf_reg_state *reg,argno_t argno,int insn_idx, +static int process_iter_arg (struct bpf_verifier_env *env,struct bpf_reg_state *reg, +u32 arg,argno_t argno,int insn_idx,struct bpf_call_arg_meta *meta) {struct bpf_func_state *state =bpf_func (env, reg);const struct btf_type *t; -u32 arg_idx =arg_idx_from_argno (argno);int spi, err, i, nr_slots, btf_id;if (reg->type !=PTR_TO_STACK ) {
@@ -8289,7 +8289,7 @@ static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state ** to any kfunc, if arg has "__iter" suffix, we need to be a bit more * conservative here. */ - btf_id =btf_check_iter_arg (meta->btf, meta->func_proto, arg_idx); + btf_id =btf_check_iter_arg (meta->btf, meta->func_proto, arg);if (btf_id <0 ) {verbose (env,"expected valid iter pointer as %s\n" ,reg_arg_name (env, argno));
@@ -8920,7 +8920,7 @@ __printf(6, 7) static void bpf_diag_call_arg_fmt(struct bpf_verifier_env *env, u }static int check_func_arg_nullability (struct bpf_verifier_env *env, -struct bpf_reg_state *reg,argno_t argno, +struct bpf_reg_state *reg,u32 arg,argno_t argno,enum bpf_arg_type arg_type,struct bpf_call_arg_meta *meta,int insn_idx) {
@@ -8933,7 +8933,7 @@ static int check_func_arg_nullability(struct bpf_verifier_env *env,if (meta->btf) {u32 arg_btf_id; - arg_btf_id =btf_params (meta->func_proto)[arg_idx_from_argno (argno)].type; + arg_btf_id =btf_params (meta->func_proto)[arg].type; expected_type =bpf_diag_fmt (env,"value of type %s" ,bpf_diag_fmt_btf_type (env, meta->btf, arg_btf_id)); }
@@ -8948,7 +8948,7 @@ static int check_func_arg_nullability(struct bpf_verifier_env *env, }static int check_func_arg_release (struct bpf_verifier_env *env,struct bpf_reg_state *reg, -argno_t argno,enum bpf_arg_type arg_type, +u32 arg,argno_t argno,enum bpf_arg_type arg_type,struct bpf_call_arg_meta *meta,int insn_idx) {const char *expected_type ="pointer" ;
@@ -8968,7 +8968,7 @@ static int check_func_arg_release(struct bpf_verifier_env *env, struct bpf_reg_sconst struct btf_type *t;u32 ref_id; - btf_arg = &btf_params (meta->func_proto)[arg_idx_from_argno (argno)]; + btf_arg = &btf_params (meta->func_proto)[arg]; ref_id = btf_arg->type; t =btf_type_skip_modifiers (meta->btf, btf_arg->type,NULL );if (btf_type_is_ptr (t))
@@ -9413,7 +9413,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 preturn 0 ; } - err =check_func_arg_nullability (env, reg, argno, arg_type, meta, insn_idx); + err =check_func_arg_nullability (env, reg, arg, argno, arg_type, meta, insn_idx);if (err)return err;
@@ -9425,7 +9425,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 pif (err)return err; - err =check_func_arg_release (env, reg, argno, arg_type, meta, insn_idx); + err =check_func_arg_release (env, reg, arg, argno, arg_type, meta, insn_idx);if (err)return err;
@@ -9759,7 +9759,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 pverbose (env,"css_task_iter is only allowed in bpf_lsm, bpf_iter and sleepable progs\n" );return -EINVAL ; } - err =process_iter_arg (env, reg, argno, insn_idx, meta); + err =process_iter_arg (env, reg, arg, argno, insn_idx, meta);if (err <0 )return err;break ;
Signature · 1 line
2.52.0
PATCH v3 2/11 bpf: Identify subprog calls in argument metadata
In reply to Amery HungPrepare subprog calls to use the common check_func_args() path. That checker distinguishes call kinds through bpf_call_arg_meta, but btf_check_func_arg_match() leaves both BTF and the function ID zero even though it validates a program-BTF signature.
Represent a subprog call with a non-NULL BTF and a zero function ID. Define helpers as NULL BTF plus nonzero ID, and kfuncs as non-NULL BTF plus nonzero ID. Requiring a nonzero kfunc ID also prevents unavailable special-kfunc IDs from matching subprog metadata. The corresponding subprog predicate is introduced later alongside its first use.
Setting BTF would expose checks that treat every BTF-backed call as a kfunc. Restrict kfunc-only BTF parameter lookup, register admission, release diagnostics, no-cast alias, and projection handling to actual kfuncs.
The BTF is not modified here, but bpf_call_arg_meta::btf and several downstream consumers use non-const pointers. Match those existing types instead of broadening this series with a const-correctness cleanup.
No functional change is intended.
--- kernel/bpf/verifier.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
kernel/bpf/verifier.c +23 -13
@@ -8639,18 +8639,27 @@ static bool arg_type_is_scalar(enum bpf_arg_type type) }/* -* A kfunc is named by a BTF ID, which can take the same numeric value as an -* enum bpf_func_id. Only test meta->func_id against a BPF_FUNC_* once the call -* is known to be to a helper; meta->btf is set only for a kfunc. +* A helper has no BTF and a nonzero function ID. A kfunc has both, while a +* BPF subprogram has BTF and a zero function ID. */ +static bool is_helper (const struct bpf_call_arg_meta *meta) +{ +return !meta->btf && meta->func_id; +} +static bool is_helper_call (const struct bpf_call_arg_meta *meta,enum bpf_func_id func_id) { -return !meta->btf && meta->func_id == func_id; +return is_helper (meta) && meta->func_id == func_id; +} + +static bool is_kfunc (const struct bpf_call_arg_meta *meta) +{ +return meta->btf && meta->func_id; }static bool is_kfunc_call (const struct bpf_call_arg_meta *meta,u32 btf_id) { -return meta->btf && meta->func_id == btf_id; +return is_kfunc (meta) && meta->func_id == btf_id; } static int resolve_map_arg_type(struct bpf_verifier_env *env,
@@ -8963,7 +8972,7 @@ static int check_func_arg_release(struct bpf_verifier_env *env, struct bpf_reg_sverbose (env,"release function %s expects referenced PTR_TO_BTF_ID passed to %s\n" , meta->func_name,reg_arg_name (env, argno)); -if (meta->btf) { +if (is_kfunc (meta)) {const struct btf_param *btf_arg;const struct btf_type *t;u32 ref_id;
@@ -9017,7 +9026,7 @@ static int check_reg_type(struct bpf_verifier_env *env, struct bpf_reg_state *reverifier_bug (env,"unsupported arg type %d" , arg_type);return -EFAULT ; } -if (meta->btf &&base_type (arg_type) ==ARG_PTR_TO_BTF_ID && +if (is_kfunc (meta) &&base_type (arg_type) ==ARG_PTR_TO_BTF_ID && (base_type (type) ==PTR_TO_BTF_ID || reg2btf_ids[base_type (type)])) goto found;
@@ -9040,7 +9049,7 @@ static int check_reg_type(struct bpf_verifier_env *env, struct bpf_reg_state *reif (base_type (arg_type) ==ARG_PTR_TO_MEM ) type &= ~DYNPTR_TYPE_FLAG_MASK ;/* Allow allocated memory for kfunc ARG_PTR_TO_MEM but not helper. */ -if (meta->btf &&base_type (arg_type) ==ARG_PTR_TO_MEM && +if (is_kfunc (meta) &&base_type (arg_type) ==ARG_PTR_TO_MEM &&type_is_ptr_alloc_obj (type)) type =PTR_TO_MEM ;
@@ -9363,7 +9372,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 p struct bpf_call_arg_meta *meta, int insn_idx) { -const struct btf_param *btf_arg = meta->btf ? &btf_params (meta->func_proto)[arg] :NULL ; +const struct btf_param *btf_arg =is_kfunc (meta) ? + &btf_params (meta->func_proto)[arg] :NULL ;const struct bpf_func_proto *fn = meta->fn;struct bpf_func_state *caller =cur_func (env);struct bpf_reg_state *regs =cur_regs (env);
@@ -10789,7 +10799,7 @@ static int setup_func_entry(struct bpf_verifier_env *env, int subprog, int calls }static int btf_check_func_arg_match (struct bpf_verifier_env *env,int subprog, -const struct btf *btf, +struct btf *btf,struct bpf_reg_state *regs) {struct bpf_subprog_info *sub =subprog_info (env, subprog);
@@ -10801,8 +10811,8 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,u32 i;int ret, err; -/* Leave btf and func_id zero: this is neither a helper nor a kfunc. */ memset (&meta,0 ,sizeof (meta)); + meta.btf = btf; meta.func_name =bpf_subprog_name (env, subprog); ret =btf_prepare_func_args (env, subprog);
@@ -13783,7 +13793,7 @@ static int process_arg_ptr_to_btf_id(struct bpf_verifier_env *env, struct bpf_re* resolve types. */ if ((arg_type_is_release (arg_type) && !is_helper_call (meta, BPF_FUNC_sk_release)) || - (meta->btf &&btf_type_ids_nocast_alias (&env->log, reg_btf, reg_btf_id, + (is_kfunc (meta) &&btf_type_ids_nocast_alias (&env->log, reg_btf, reg_btf_id, arg_btf, arg_btf_id))) strict_type_match = true;
@@ -13800,7 +13810,7 @@ static int process_arg_ptr_to_btf_id(struct bpf_verifier_env *env, struct bpf_re* actually use it -- it must cast to the underlying type. So we allow * caller to pass in the underlying type. */ - taking_projection = meta->btf &&btf_is_projection_of (arg_tname, reg_tname); + taking_projection =is_kfunc (meta) &&btf_is_projection_of (arg_tname, reg_tname);if (!taking_projection && !struct_same) { verbose(env, "%s %s expected pointer to %s %s but %s has a pointer to %s %s\n", meta->func_name, reg_arg_name(env, argno),
Signature · 1 line
2.52.0
PATCH v3 3/11 bpf: Build argument prototypes for subprog calls
In reply to Amery HungThe common argument checker consumes a parameter-indexed bpf_func_proto, while BPF subprogram argument metadata is cached by ABI slot in compact bpf_subprog_info entries. Embedding a full prototype in every fixed subprogram entry would waste memory.
Embed a scratch prototype in the verifier environment. Fill it by walking BTF parameters and the cached slots with separate cursors, mirroring the kfunc representation for parameters that occupy multiple slots. Keep the compact cache as the source of truth. The verifier environment is already heap allocated, so this avoids a separate allocation, failure path, and cleanup.
Keep the existing validation loop, but make it consume the generated prototype in preparation for moving BPF subprogram calls to the common argument checker. No functional change.
--- include/linux/bpf_verifier.h | 3 +- kernel/bpf/verifier.c | 103 ++++++++++++++++++++++++----------- 2 files changed, 73 insertions(+), 33 deletions(-)
include/linux/bpf_verifier.h +2 -1
@@ -976,6 +976,7 @@ struct bpf_verifier_env {const struct bpf_line_info *prev_linfo;struct bpf_verifier_log log;struct bpf_diag *diag; +struct bpf_func_proto bpf_subprog_scratch;struct bpf_subprog_info subprog_info[BPF_MAX_SUBPROGS +2 ];/* max + 2 for the fake and exception subprogs */ /* subprog indices sorted in topological order: leaves first, callers last */ int subprog_topo_order[BPF_MAX_SUBPROGS +2 ];
@@ -1645,6 +1646,7 @@ struct bpf_call_arg_meta {struct btf *btf;u32 func_id;const struct bpf_func_proto *fn; +const struct btf_type *func_proto;u8 release_regno;u32 ret_btf_id;u32 subprogno;
@@ -1657,7 +1659,6 @@ struct bpf_call_arg_meta {/* Only set by kfunc */ bool r0_rdonly;u32 kfunc_flags; -const struct btf_type *func_proto;const char *func_name;struct arg_constant_desc arg_constant;
kernel/bpf/verifier.c +71 -32
230 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v3 4/11 bpf: Check subprog scalar arguments in the common path
In reply to Amery HungBPF 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.
--- kernel/bpf/verifier.c | 19 ++++++------------- .../selftests/bpf/progs/aggregate_arg_func.c | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-)
kernel/bpf/verifier.c +6 -13
@@ -10872,10 +10872,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
@@ -10965,15 +10964,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; } }
tools/testing/selftests/bpf/progs/aggregate_arg_func.c +1 -1
@@ -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 (
Signature · 1 line
2.52.0
PATCH v3 5/11 bpf: Check global subprog untrusted arguments in the common path
In reply to Amery HungGlobal subprogram arguments tagged __arg_untrusted deliberately accept any caller value. The callee is verified separately with a read-only untrusted pointer, whose accesses use protected probe-read instructions.
Keep the untrusted type in the canonical bpf_subprog_info used to prepare the callee state. Represent it as ARG_IGNORE only in the temporary bpf_func_proto used for call-site checking, then extend the guarded check_func_arg() path to cover it.
--- kernel/bpf/verifier.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
kernel/bpf/verifier.c +11 -8
@@ -10806,9 +10806,18 @@ static void gen_subprog_arg_proto(const struct bpf_subprog_info *sub, const strumemset (proto,0 ,sizeof (*proto));for (arg =0 ; arg <btf_type_vlen (func_proto); arg++) { +enum bpf_arg_type arg_type = sub->args[slot].arg_type;const struct btf_type *t; - proto->arg_type[arg] = sub->args[slot].arg_type; +if (arg_type &PTR_UNTRUSTED ) { +/* +* An __arg_untrusted argument accepts any caller value. The +* callee treats it as read-only and uses probe-read instructions +* to protect against invalid memory access. +*/ + arg_type =ARG_IGNORE ; + } + proto->arg_type[arg] = arg_type; t =btf_type_skip_modifiers (btf, args[arg].type,NULL ); slot +=btf_arg_slots (t); }
@@ -10871,16 +10880,10 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, t =btf_type_skip_modifiers (btf, args[arg].type,NULL ); nslots =btf_arg_slots (t); -if (arg_type ==ARG_SCALAR ) { +if (arg_type ==ARG_SCALAR || arg_type ==ARG_IGNORE ) { 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 -* read-only and probe read instructions would protect against -* invalid memory access. -*/ }else if (arg_type ==ARG_PTR_TO_CTX ) { ret =check_func_arg_reg_off (env, reg, argno,ARG_PTR_TO_CTX );if (ret <0 )
Signature · 1 line
2.52.0
PATCH v3 6/11 bpf: Check subprog context arguments in the common path
In reply to Amery HungSubprog and helper/kfunc context arguments require PTR_TO_CTX with an acceptable offset. Route subprog context arguments through check_func_arg() and update the verifier-log expectation.
--- kernel/bpf/verifier.c | 15 ++------------- .../selftests/bpf/progs/test_global_func5.c | 2 +- 2 files changed, 3 insertions(+), 14 deletions(-)
kernel/bpf/verifier.c +2 -13
@@ -10880,22 +10880,11 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, t =btf_type_skip_modifiers (btf, args[arg].type,NULL ); nslots =btf_arg_slots (t); -if (arg_type ==ARG_SCALAR || arg_type ==ARG_IGNORE ) { +if (arg_type ==ARG_SCALAR || arg_type ==ARG_IGNORE || + arg_type ==ARG_PTR_TO_CTX ) { ret =check_func_arg (env, arg, slot,0 , &meta, env->insn_idx);if (ret)return ret; - }else if (arg_type ==ARG_PTR_TO_CTX ) { - ret =check_func_arg_reg_off (env, reg, argno,ARG_PTR_TO_CTX ); -if (ret <0 ) -return ret; -/* If function expects ctx type in BTF check that caller -* is passing PTR_TO_CTX. -*/ -if (reg->type !=PTR_TO_CTX ) { -bpf_log (log,"%s expects pointer to ctx\n" , -reg_arg_name (env, argno)); -return -EINVAL ; - } }else if (base_type (arg_type) ==ARG_PTR_TO_MEM ) { ret =check_func_arg_reg_off (env, reg, argno,ARG_PTR_TO_MEM );if (ret <0 )
tools/testing/selftests/bpf/progs/test_global_func5.c +1 -1
@@ -26,7 +26,7 @@ int f3(int val, struct __sk_buff *skb) } SEC("tc") -__failure __msg("expects pointer to ctx") +__failure __msg("R2 type=fp expected=ctx") int global_func5(struct __sk_buff *skb) {return f1 (skb) +f2 (2 , skb) +f3 (3 , skb);
Signature · 1 line
2.52.0
PATCH v3 7/11 bpf: Check subprog arena arguments in the common path
In reply to Amery HungARG_PTR_TO_ARENA accepts both arena pointers and scalars. The existing BPF-subprogram contract includes a constant-zero scalar; it is an arena address value rather than a conventional pointer rejected by nullability checking.
Kfunc prototype generation already records this zero acceptance with PTR_MAYBE_NULL for both arena suffixes; separate JIT metadata determines whether the kernel callee receives the arena base or NULL. Apply the same call-site representation to the temporary BPF-subprogram prototype, then extend the guarded check_func_arg() path to cover arena arguments.
--- kernel/bpf/verifier.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
kernel/bpf/verifier.c +4 -14
@@ -10816,6 +10816,8 @@ static void gen_subprog_arg_proto(const struct bpf_subprog_info *sub, const stru* to protect against invalid memory access. */ arg_type =ARG_IGNORE ; + }else if (base_type (arg_type) ==ARG_PTR_TO_ARENA ) { + arg_type |=PTR_MAYBE_NULL ; } proto->arg_type[arg] = arg_type; t =btf_type_skip_modifiers (btf, args[arg].type,NULL );
@@ -10881,7 +10883,8 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, nslots =btf_arg_slots (t);if (arg_type ==ARG_SCALAR || arg_type ==ARG_IGNORE || - arg_type ==ARG_PTR_TO_CTX ) { + arg_type ==ARG_PTR_TO_CTX || +base_type (arg_type) ==ARG_PTR_TO_ARENA ) { ret =check_func_arg (env, arg, slot,0 , &meta, env->insn_idx);if (ret)return ret;
@@ -10909,19 +10912,6 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, reg_arg_name(env, argno));return -EINVAL ; } - }else if (base_type (arg_type) ==ARG_PTR_TO_ARENA ) { -/* -* Can pass any value and the kernel won't crash, but -* only PTR_TO_ARENA or SCALAR make sense. Everything -* else is a bug in the bpf program. Point it out to -* the user at the verification time instead of -* run-time debug nightmare. -*/ -if (reg->type !=PTR_TO_ARENA && reg->type !=SCALAR_VALUE ) { -bpf_log (log,"%s is not a pointer to arena or scalar.\n" , -reg_arg_name (env, argno)); -return -EINVAL ; - } }else if (arg_type ==ARG_PTR_TO_DYNPTR ) { ret =check_func_arg_reg_off (env, reg, argno,ARG_PTR_TO_DYNPTR );if (ret)
Signature · 1 line
2.52.0
PATCH v3 8/11 bpf: Check subprog dynptr arguments in the common path
In reply to Amery HungSubprog and helper/kfunc dynptr arguments ultimately use the same process_dynptr_func() validation. Route the subprog dynptr branch through check_func_arg() so register type, offset, and dynptr state are checked in the common order.
check_func_arg() validates the register against the PTR_TO_STACK and CONST_PTR_TO_DYNPTR compatibility set before dispatching to process_dynptr_func(). Once the subprog path uses the common checker, process_dynptr_func() has no caller that bypasses this validation. Remove its now-redundant register-type check.
The existing wrong-register-type test passed a NULL local to a callee that did not use the argument. Clang left the context pointer in R1, while GCC materialized zero. The common checker rejected the values at different stages and emitted different diagnostics.
Obtain a PTR_TO_BTF_ID from bpf_get_current_task_btf() and keep its callee argument live. This makes both compilers exercise the intended register-type mismatch.
--- kernel/bpf/verifier.c | 23 +------------------ .../testing/selftests/bpf/progs/dynptr_fail.c | 11 ++++----- 2 files changed, 6 insertions(+), 28 deletions(-)
kernel/bpf/verifier.c +1 -22
@@ -8133,18 +8133,6 @@ static int process_dynptr_func(struct bpf_verifier_env *env, struct bpf_reg_stat {int spi, err =0 ; -if (reg->type !=PTR_TO_STACK && reg->type !=CONST_PTR_TO_DYNPTR ) { -verbose (env, -"%s expected pointer to stack or const struct bpf_dynptr\n" , -reg_arg_name (env, argno)); -bpf_diag_call_arg_fmt ( - env, insn_idx, argno, meta->func_name, -"Pass the address of a stack dynptr object, or use a const dynptr pointer returned by the verifier-supported path." , -"a dynptr argument must be a pointer to a dynptr stack slot or a verifier-provided const struct bpf_dynptr, but %s is %s" , -reg_arg_name (env, argno),bpf_diag_reg_type_plain (env, reg->type)); -return -EINVAL ; - } -/* MEM_UNINIT - Points to memory that is an appropriate candidate for * constructing a mutable bpf_dynptr object. *
@@ -10883,7 +10871,7 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, nslots =btf_arg_slots (t);if (arg_type ==ARG_SCALAR || arg_type ==ARG_IGNORE || - arg_type ==ARG_PTR_TO_CTX || + arg_type ==ARG_PTR_TO_CTX || arg_type ==ARG_PTR_TO_DYNPTR ||base_type (arg_type) ==ARG_PTR_TO_ARENA ) { ret =check_func_arg (env, arg, slot,0 , &meta, env->insn_idx);if (ret)
@@ -10912,15 +10900,6 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, reg_arg_name(env, argno));return -EINVAL ; } - }else if (arg_type ==ARG_PTR_TO_DYNPTR ) { - ret =check_func_arg_reg_off (env, reg, argno,ARG_PTR_TO_DYNPTR ); -if (ret) -return ret; - - ret =process_dynptr_func (env, reg, argno, env->insn_idx, - arg_type, &meta); -if (ret) -return ret; }else if (base_type (arg_type) ==ARG_PTR_TO_BTF_ID ) {int err;
tools/testing/selftests/bpf/progs/dynptr_fail.c +5 -6
@@ -2053,19 +2053,18 @@ __noinline long global_call_bpf_dynptr(const struct bpf_dynptr *dynptr)/* Avoid leaving this global function empty to avoid having the compiler * optimize away the call to this global function. */ +__sink (dynptr);__sink (ret);return ret; } SEC("?raw_tp") -__failure __msg("R1 expected pointer to stack or const struct bpf_dynptr") +__failure __msg("R1 type=trusted_ptr_ expected=fp, dynptr_ptr") int test_dynptr_reg_type(void *ctx) { -struct task_struct *current =NULL ; -/* R1 should be holding a PTR_TO_BTF_ID, so this shouldn't be a -* reg->type that can be passed to a function accepting a -* ARG_PTR_TO_DYNPTR | MEM_RDONLY. process_dynptr_func() should catch -* this. +struct task_struct *current =bpf_get_current_task_btf (); +/* R1 holds a PTR_TO_BTF_ID, which cannot be passed to a function +* accepting ARG_PTR_TO_DYNPTR | MEM_RDONLY. */ global_call_bpf_dynptr ((const struct bpf_dynptr *)current);return 0 ;
Signature · 1 line
2.52.0
PATCH v3 9/11 bpf: Check global subprog BTF-ID arguments in the common path
In reply to Amery HungRoute global ARG_PTR_TO_BTF_ID arguments through check_func_arg(). Use vmlinux BTF for their type match and retain the global-subprogram rules instead of applying kfunc-only trusted-pointer validation or runtime type resolution.
The common nullability check now rejects non-nullable global BTF-ID arguments before register-type matching. Update the corresponding verifier log expectations.
--- kernel/bpf/verifier.c | 31 +++++-------------- .../bpf/progs/verifier_global_ptr_args.c | 4 +-- 2 files changed, 10 insertions(+), 25 deletions(-)
kernel/bpf/verifier.c +8 -23
@@ -9501,7 +9501,7 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 pcase ARG_PTR_TO_BTF_ID_SOCK_COMMON : {const u32 *arg_btf_id = fn->arg_btf_id[arg]; -const struct btf *arg_btf = meta->btf ?: btf_vmlinux; +const struct btf *arg_btf =is_kfunc (meta) ? meta->btf : btf_vmlinux;if (!meta->btf) {const struct bpf_reg_types *compatible;
@@ -9529,8 +9529,8 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 p } } -if (meta->btf && (!is_trusted_reg (env, reg) || -bpf_type_has_unsafe_modifiers (reg->type))) { +if (is_kfunc (meta) && (!is_trusted_reg (env, reg) || +bpf_type_has_unsafe_modifiers (reg->type))) {if (!(arg_type &MEM_RCU )) {const char *actual_type, *arg_name, *expected_type;
@@ -10806,6 +10806,8 @@ static void gen_subprog_arg_proto(const struct bpf_subprog_info *sub, const stru arg_type =ARG_IGNORE ; }else if (base_type (arg_type) ==ARG_PTR_TO_ARENA ) { arg_type |=PTR_MAYBE_NULL ; + }else if (base_type (arg_type) ==ARG_PTR_TO_BTF_ID ) { + proto->arg_btf_id[arg] = &sub->args[slot].btf_id; } proto->arg_type[arg] = arg_type; t =btf_type_skip_modifiers (btf, args[arg].type,NULL );
@@ -10872,7 +10874,8 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,if (arg_type ==ARG_SCALAR || arg_type ==ARG_IGNORE || arg_type ==ARG_PTR_TO_CTX || arg_type ==ARG_PTR_TO_DYNPTR || -base_type (arg_type) ==ARG_PTR_TO_ARENA ) { +base_type (arg_type) ==ARG_PTR_TO_ARENA || +base_type (arg_type) ==ARG_PTR_TO_BTF_ID ) { ret =check_func_arg (env, arg, slot,0 , &meta, env->insn_idx);if (ret)return ret;
@@ -10900,24 +10903,6 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, reg_arg_name(env, argno));return -EINVAL ; } - }else if (base_type (arg_type) ==ARG_PTR_TO_BTF_ID ) { -int err; - -if (bpf_register_is_null (reg) &&type_may_be_null (arg_type)) { - err =mark_arg_precision (env, argno); -if (err) -return err; -continue ; - } - - err =check_reg_type (env, reg, argno, arg_type, &meta); - err = err ?:check_func_arg_reg_off (env, reg, argno, arg_type); -if (!err &&base_type (reg->type) ==PTR_TO_BTF_ID ) - err =process_arg_ptr_to_btf_id (env, reg, argno, arg_type, - btf_vmlinux, sub->args[slot].btf_id, - &meta, env->insn_idx); -if (err) -return err; }else {verifier_bug (env,"unrecognized %s type %d" ,reg_arg_name (env, argno), arg_type);
@@ -13063,7 +13048,7 @@ static int resolve_func_arg_type(struct bpf_verifier_env *env,if (base_type (*arg_type) !=ARG_PTR_TO_BTF_ID )return 0 ; -if (!meta->btf ||arg_type_is_release (*arg_type) || +if (!is_kfunc (meta) ||arg_type_is_release (*arg_type) ||base_type (reg->type) ==PTR_TO_BTF_ID || reg2btf_ids[base_type (reg->type)])return 0 ;
tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c +2 -2
@@ -87,7 +87,7 @@ __weak int subprog_trusted_task_nonnull(struct task_struct *task __arg_trusted) SEC("?kprobe") __failure __log_level(2) -__msg("R1 type=scalar expected=ptr_, trusted_ptr_, rcu_ptr_") +__msg("Possibly NULL pointer passed to trusted R1") __msg("Caller passes invalid args into func#1 ('subprog_trusted_task_nonnull')")int trusted_task_arg_nonnull_fail1 (void *ctx) {
@@ -96,7 +96,7 @@ int trusted_task_arg_nonnull_fail1(void *ctx) SEC("?tp_btf/task_newtask") __failure __log_level(2) -__msg("R1 type=trusted_ptr_or_null_ expected=ptr_, trusted_ptr_, rcu_ptr_") +__msg("Possibly NULL pointer passed to trusted R1") __msg("Caller passes invalid args into func#1 ('subprog_trusted_task_nonnull')")int trusted_task_arg_nonnull_fail2 (void *ctx) {
Signature · 1 line
2.52.0
PATCH v3 10/11 bpf: Check global subprog memory arguments in the common path
In reply to Amery HungRoute fixed-size global ARG_PTR_TO_MEM arguments through check_func_arg(). Preserve their read-write access check, nullable contract, and support for BTF-defined allocated memory.
Recognize subprog calls explicitly in the common checker. Global subprog stack liveness can prove that bytes in an argument are unused by the callee. Retain the existing allowance for those poisoned stack bytes when call metadata is present, and update the nullability log expectation.
The verifier also rejects packet pointers when the callee may change packet data. The concrete packet-backed register state is only available while checking the call site; the independently verified callee sees generic PTR_TO_MEM. Record this property as subprog_may_change_pkt in subprog-only call metadata and retain the packet-pointer rejection in the common fixed-memory path.
--- include/linux/bpf_verifier.h | 3 + kernel/bpf/verifier.c | 58 +++++++++---------- .../bpf/progs/verifier_global_ptr_args.c | 3 +- .../bpf/progs/verifier_global_subprogs.c | 2 +- 4 files changed, 33 insertions(+), 33 deletions(-)
include/linux/bpf_verifier.h +3 -0
@@ -1656,6 +1656,9 @@ struct bpf_call_arg_meta {struct ret_mem_desc ret_mem;struct arg_raw_mem_desc arg_raw_mem; +/* Only set by subprog */ +bool subprog_may_change_pkt; +/* Only set by kfunc */ bool r0_rdonly;u32 kfunc_flags;
kernel/bpf/verifier.c +27 -31
117 lines not on this page · raw message
tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c +2 -1
@@ -389,7 +389,8 @@ __weak int subprog_pkt_ptr_changes_data(struct __sk_buff *skb __arg_ctx, SEC("?tc") __failure __log_level(2) -__msg("R2 is a packet pointer, but func#{{[0-9]+}} may change packet data") +__msg("cannot pass packet pointer R2") +__msg("function may change packet data") __msg("Caller passes invalid args into func#{{[0-9]+}} ('subprog_pkt_ptr_changes_data')")int pkt_ptr_to_global_mem_arg_changes_data (struct __sk_buff *skb) {
tools/testing/selftests/bpf/progs/verifier_global_subprogs.c +1 -1
@@ -195,7 +195,7 @@ int arg_tag_nonnull_ptr_good(void *ctx) SEC("?raw_tp") __failure __log_level(2) -__msg("R1 is expected to be non-NULL") +__msg("Possibly NULL pointer passed to trusted R1")int arg_tag_nonnull_ptr_null_bad (void *ctx) {int y =74 ;
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH bpf-next v3 10/11] bpf: Check global subprog memory arguments in the common path
Routing ARG_PTR_TO_MEM through check_func_arg() adds a check_reg_type() step that wasn't in the old path. The old btf_check_func_arg_match() code called check_func_arg_reg_off(), then…
Quoted 4 lines
include/linux/bpf_verifier.h +0
-0
[ ... ]
Quoted 4 lines
kernel/bpf/verifier.c +0
-0
[ ... ]
Quoted 11 lines
kernel/bpf/verifier.c +2
-2@@ -9036,8 +9042,8 @@ static int check_reg_type(struct bpf_verifier_env *env, struct bpf_reg_state *re type &= ~PTR_MAYBE_NULL ;if (base_type (arg_type) ==ARG_PTR_TO_MEM ) type &= ~DYNPTR_TYPE_FLAG_MASK ; -/* Allow allocated memory for kfunc ARG_PTR_TO_MEM but not helper. */ -if (is_kfunc (meta) &&base_type (arg_type) ==ARG_PTR_TO_MEM && +/* Allow allocated memory for BTF-defined ARG_PTR_TO_MEM but not helpers. */ +if (!is_helper (meta) &&base_type (arg_type) ==ARG_PTR_TO_MEM &&type_is_ptr_alloc_obj (type)) type =PTR_TO_MEM ;
[ ... ]
Quoted 35 lines
kernel/bpf/verifier.c +2
-19@@ -10863,7 +10883,6 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,* verifier sees. */ for (arg =0 , slot =0 ; arg <btf_type_vlen (func_proto); arg++, slot += nslots) { -struct bpf_reg_state *reg =get_func_arg_reg (caller, regs, slot);enum bpf_arg_type arg_type = fn->arg_type[arg];argno_t argno =argno_from_arg (slot +1 );const struct btf_type *t;@@ -10875,34 +10894,11 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog,if (arg_type ==ARG_SCALAR || arg_type ==ARG_IGNORE || arg_type ==ARG_PTR_TO_CTX || arg_type ==ARG_PTR_TO_DYNPTR ||base_type (arg_type) ==ARG_PTR_TO_ARENA || -base_type (arg_type) ==ARG_PTR_TO_BTF_ID ) { +base_type (arg_type) ==ARG_PTR_TO_BTF_ID || +base_type (arg_type) ==ARG_PTR_TO_MEM ) { ret =check_func_arg (env, arg, slot,0 , &meta, env->insn_idx);if (ret)return ret; - }else if (base_type (arg_type) ==ARG_PTR_TO_MEM ) { - ret =check_func_arg_reg_off (env, reg, argno,ARG_PTR_TO_MEM ); -if (ret <0 ) -return ret; -if (check_mem_reg (env, reg, argno, sub->args[slot].mem_size, -BPF_READ |BPF_WRITE ,NULL , -NULL )) -return -EINVAL ; -/* -* PTR_TO_PACKET get passed as PTR_TO_MEM, preventing -* us from adjusting bounds tracking info. -*/ -if ((reg_is_pkt_pointer_any (reg) ||reg_is_dynptr_slice_pkt (reg)) && - sub->changes_pkt_data) { -bpf_log (log,"%s is a packet pointer, but func#%d may change packet data\n" , -reg_arg_name (env, argno), subprog); -return -EINVAL ;
kernel/bpf/verifier.c static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, · line 10904
Quoted 10 lines
kernel/bpf/verifier.c +0
-7- } -if (!(arg_type &PTR_MAYBE_NULL ) && - (type_may_be_null (reg->type) ||bpf_register_is_null (reg))) { -bpf_log (log,"%s is expected to be non-NULL\n" , -reg_arg_name (env, argno)); -return -EINVAL ; - } }else {verifier_bug (env,"unrecognized %s type %d" ,reg_arg_name (env, argno), arg_type);
Routing ARG_PTR_TO_MEM through check_func_arg() adds a check_reg_type() step that wasn't in the old path. The old btf_check_func_arg_match() code called check_func_arg_reg_off(), then check_mem_reg() which eventually reached check_ptr_to_btf_access() for PTR_TO_BTF_ID registers.
Does this break PTR_TO_BTF_ID | MEM_RCU? Looking at check_reg_type() in verifier.c around line 9050, the mem_types array only includes PTR_TO_BTF_ID | PTR_TRUSTED for the PTR_TO_BTF_ID case. MEM_ALLOC objects are handled separately by type_is_ptr_alloc_obj() conversion.
Before this patch, check_func_arg_reg_off() accepted PTR_TO_BTF_ID | MEM_RCU with fixed offset, then check_mem_reg() sent it to check_ptr_to_btf_access(). For program types with env->ops->btf_struct_access, the write check was delegated to that callback since MEM_RCU doesn't satisfy bpf_may_fault_on_deref().
As a concrete example, in sched_ext struct_ops programs:
struct task_struct *p = scx_bpf_cpu_curr(cpu);
// or p = scx_bpf_tid_to_task(pid);
// Both are KF_RCU_PROTECTED | KF_RET_NULL, so after NULL check // R0 becomes PTR_TO_BTF_ID | MEM_RCU per the kfunc return handling.
// Tasks from bpf_for_each(task|scx_dsq, ...) are also MEM_RCU
__weak int f(u64 *v) { ... }
f(&p->scx.dsq_vtime); // or &p->scx.slice
The old code verified this because bpf_scx_btf_struct_access() allows writes to those specific fields. The new path would reject it in check_reg_type() with:
"R1 type=rcu_ptr_task_struct expected=fp, pkt, pkt_meta, map_key,
map_value, mem, ringbuf_mem, buf, trusted_ptr_, ctx"
Programs that loaded before this patch would fail with "Caller passes invalid args into func". The commit message says "Preserve their read-write access check" but this appears to change the acceptance criteria for BTF pointers.
The existing selftest trusted_btf_field_to_writable_mem confirms that BTF field pointers passed to global mem args went through check_ptr_to_btf_access() under the old code path.
Should check_reg_type() continue accepting PTR_TO_BTF_ID | MEM_RCU for subprog ARG_PTR_TO_MEM and leave the access decision to check_mem_reg()/check_ptr_to_btf_access()?
[ ... ]
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/36470745096
PATCH v3 11/11 bpf: Check all subprog arguments in the common path
In reply to Amery HungAll supported BPF-subprogram argument types now pass through check_func_arg() from one guarded branch in the legacy validation loop. Replace that loop and its outgoing-stack validation with check_func_args().
The scratch prototype is indexed by BTF parameter and the call metadata carries the BTF function prototype. The existing BTF argument iteration therefore maps parameters to ABI slots for both kfunc and BPF subprogram calls, including additional slots occupied by by-value aggregates.
The common checker can return non-EFAULT errors other than -EINVAL, as the existing BTF-ID path already did. This is compatible with subprog call handling: only -EFAULT is fatal. Any other error marks BTF unreliable. Static subprogs can then fall back to inline verification, while global subprogs reject the call.
Remove the caller-register plumbing that the dedicated loop required.
--- kernel/bpf/verifier.c | 65 ++++++++----------------------------------- 1 file changed, 11 insertions(+), 54 deletions(-)
kernel/bpf/verifier.c +11 -54
@@ -10835,17 +10835,13 @@ static void gen_subprog_arg_proto(const struct bpf_subprog_info *sub, const stru } } -static int btf_check_func_arg_match (struct bpf_verifier_env *env,int subprog, -struct btf *btf, -struct bpf_reg_state *regs) +static int btf_check_func_arg_match (struct bpf_verifier_env *env,int subprog,struct btf *btf) {struct bpf_subprog_info *sub =subprog_info (env, subprog);struct bpf_func_state *caller =cur_func (env); -const struct btf_param *args, *stack_args;const struct btf_type *func, *func_proto;struct bpf_call_arg_meta meta;struct bpf_func_proto *fn; -u32 arg, slot, nslots;int ret, err;memset (&meta,0 ,sizeof (meta));
@@ -10867,63 +10863,24 @@ static int btf_check_func_arg_match(struct bpf_verifier_env *env, int subprog, func =btf_type_by_id (btf, env->prog->aux->func_info[subprog].type_id); func_proto =btf_type_by_id (btf, func->type); - args =btf_params (func_proto); - stack_args = sub->arg_slot_cnt ==btf_type_vlen (func_proto) ? args :NULL ; - ret =check_outgoing_stack_args (env, caller, sub->arg_slot_cnt, -bpf_subprog_name (env, subprog), btf, stack_args); -if (ret) -return ret; fn = &env->bpf_subprog_scratch;gen_subprog_arg_proto (sub, btf, func_proto, fn); meta.fn = fn; meta.func_proto = func_proto; -/* check that BTF function arguments match actual types that the -* verifier sees. -*/ -for (arg =0 , slot =0 ; arg <btf_type_vlen (func_proto); arg++, slot += nslots) { -enum bpf_arg_type arg_type = fn->arg_type[arg]; -argno_t argno =argno_from_arg (slot +1 ); -const struct btf_type *t; -u32 k; - - t =btf_type_skip_modifiers (btf, args[arg].type,NULL ); - nslots =btf_arg_slots (t); - -if (arg_type ==ARG_SCALAR || arg_type ==ARG_IGNORE || - arg_type ==ARG_PTR_TO_CTX || arg_type ==ARG_PTR_TO_DYNPTR || -base_type (arg_type) ==ARG_PTR_TO_ARENA || -base_type (arg_type) ==ARG_PTR_TO_BTF_ID || -base_type (arg_type) ==ARG_PTR_TO_MEM ) { - ret =check_func_arg (env, arg, slot,0 , &meta, env->insn_idx); -if (ret) -return ret; - }else { -verifier_bug (env,"unrecognized %s type %d" , -reg_arg_name (env, argno), arg_type); -return -EFAULT ; - } - -for (k =1 ; k < nslots; k++) { - ret =check_arg_extra_slot (env, caller, slot + k, &meta); -if (ret) -return ret; - } - } - -return 0 ; +return check_func_args (env, &meta, env->insn_idx); } -/* Compare BTF of a function call with given bpf_reg_state. +/* +* Check that call-site argument states match a subprog's BTF signature. +* * Returns: * EFAULT - there is a verifier bug. Abort verification. -* EINVAL - there is a type mismatch or BTF is not available. +* Other errors - there is a type mismatch or BTF is not available. * 0 - BTF matches with what bpf_reg_state expects. -* Only PTR_TO_CTX and SCALAR_VALUE states are recognized. */ -static int btf_check_subprog_call (struct bpf_verifier_env *env,int subprog, -struct bpf_reg_state *regs) +static int btf_check_subprog_call (struct bpf_verifier_env *env,int subprog) {struct bpf_prog *prog = env->prog;struct btf *btf = prog->aux->btf;
@@ -10940,7 +10897,7 @@ static int btf_check_subprog_call(struct bpf_verifier_env *env, int subprog,if (prog->aux->func_info_aux[subprog].unreliable)return -EINVAL ; - err =btf_check_func_arg_match (env, subprog, btf, regs); + err =btf_check_func_arg_match (env, subprog, btf);/* Compiler optimizations can remove arguments from static functions * or mismatched type can be passed into a global function. * In such cases mark the function as unreliable from BTF point of view.
@@ -10959,7 +10916,7 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *insint err; caller = state->frame[state->curframe]; - err =btf_check_subprog_call (env, subprog, caller->regs); + err =btf_check_subprog_call (env, subprog);if (err == -EFAULT )return err;
@@ -11096,7 +11053,7 @@ static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,return -EFAULT ; caller = state->frame[state->curframe]; - err =btf_check_subprog_call (env, subprog, caller->regs); + err =btf_check_subprog_call (env, subprog);if (err == -EFAULT )return err;if (bpf_subprog_is_global (env, subprog)) {
@@ -11233,7 +11190,7 @@ static int check_func_callx(struct bpf_verifier_env *env, struct bpf_insn *insn,/* PTR_TO_FUNC is a pointer to a static subprog */ subprog = reg->subprogno; - err =btf_check_subprog_call (env, subprog, caller->regs); + err =btf_check_subprog_call (env, subprog);if (err == -EFAULT )return err;
Signature · 1 line
2.52.0
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Mon, 28 Sep 2026 11:53:23 -0700 you wrote:
Hi,
Helper and kfunc calls now validate arguments through
check_func_args(), while subprog calls still duplicate much of the same validation inbtf_check_func_arg_match(). This makes common argument rules and diagnostics easy to change for one call kind without updating the other.[...]
Here is the summary with links:
- [bpf-next,v3,01/11] bpf: Fix kfunc BTF parameter lookups after wide arguments
https://git.kernel.org/bpf/bpf-next/c/d82229330a32 - [bpf-next,v3,02/11] bpf: Identify subprog calls in argument metadata https://git.kernel.org/bpf/bpf-next/c/f7be720383d3 - [bpf-next,v3,03/11] bpf: Build argument prototypes for subprog calls https://git.kernel.org/bpf/bpf-next/c/668a51c4ed4b - [bpf-next,v3,04/11] bpf: Check subprog scalar arguments in the common path https://git.kernel.org/bpf/bpf-next/c/c40f746cc7de - [bpf-next,v3,05/11] bpf: Check global subprog untrusted arguments in the common path https://git.kernel.org/bpf/bpf-next/c/3886a9fc38de - [bpf-next,v3,06/11] bpf: Check subprog context arguments in the common path https://git.kernel.org/bpf/bpf-next/c/03f312c2cbd5 - [bpf-next,v3,07/11] bpf: Check subprog arena arguments in the common path https://git.kernel.org/bpf/bpf-next/c/44cfe492d06f - [bpf-next,v3,08/11] bpf: Check subprog dynptr arguments in the common path https://git.kernel.org/bpf/bpf-next/c/a1456ec685a6 - [bpf-next,v3,09/11] bpf: Check global subprog BTF-ID arguments in the common path https://git.kernel.org/bpf/bpf-next/c/77d9384a69cd - [bpf-next,v3,10/11] bpf: Check global subprog memory arguments in the common path https://git.kernel.org/bpf/bpf-next/c/46e074462108 - [bpf-next,v3,11/11] bpf: Check all subprog arguments in the common path https://git.kernel.org/bpf/bpf-next/c/bf82eb018328
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html