Skip to content

Commit c49dd56

Browse files
theihorKernel Patches Daemon
authored andcommitted
bpf: Support __magic prog_aux arguments for kfuncs
Teach the verifier that the prog_aux argument of a kfunc can be specified with __magic suffix, in which case the type of the function parameter must be checked. Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 305c823 commit c49dd56

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12136,9 +12136,12 @@ static bool is_kfunc_arg_magic(const struct btf *btf, const struct btf_param *ar
1213612136
return btf_param_match_suffix(btf, arg, "__magic");
1213712137
}
1213812138

12139+
static bool is_kfunc_arg_prog_aux(const struct btf *btf, const struct btf_param *arg);
12140+
1213912141
static bool is_kfunc_arg_prog(const struct btf *btf, const struct btf_param *arg)
1214012142
{
12141-
return btf_param_match_suffix(btf, arg, "__prog");
12143+
return btf_param_match_suffix(btf, arg, "__prog") ||
12144+
(is_kfunc_arg_magic(btf, arg) && is_kfunc_arg_prog_aux(btf, arg));
1214212145
}
1214312146

1214412147
static bool is_kfunc_arg_scalar_with_name(const struct btf *btf,
@@ -12169,6 +12172,7 @@ enum {
1216912172
KF_ARG_WORKQUEUE_ID,
1217012173
KF_ARG_RES_SPIN_LOCK_ID,
1217112174
KF_ARG_TASK_WORK_ID,
12175+
KF_ARG_PROG_AUX_ID
1217212176
};
1217312177

1217412178
BTF_ID_LIST(kf_arg_btf_ids)
@@ -12180,6 +12184,7 @@ BTF_ID(struct, bpf_rb_node)
1218012184
BTF_ID(struct, bpf_wq)
1218112185
BTF_ID(struct, bpf_res_spin_lock)
1218212186
BTF_ID(struct, bpf_task_work)
12187+
BTF_ID(struct, bpf_prog_aux)
1218312188

1218412189
static bool __is_kfunc_ptr_arg_type(const struct btf *btf,
1218512190
const struct btf_param *arg, int type)
@@ -12260,6 +12265,11 @@ static bool is_kfunc_arg_callback(struct bpf_verifier_env *env, const struct btf
1226012265
return true;
1226112266
}
1226212267

12268+
static bool is_kfunc_arg_prog_aux(const struct btf *btf, const struct btf_param *arg)
12269+
{
12270+
return __is_kfunc_ptr_arg_type(btf, arg, KF_ARG_PROG_AUX_ID);
12271+
}
12272+
1226312273
/* Returns true if struct is composed of scalars, 4 levels of nesting allowed */
1226412274
static bool __btf_type_is_scalar_struct(struct bpf_verifier_env *env,
1226512275
const struct btf *btf,

0 commit comments

Comments
 (0)