@@ -11690,6 +11690,9 @@ enum special_kfunc_type {
11690
11690
KF_bpf_get_kmem_cache,
11691
11691
KF_bpf_local_irq_save,
11692
11692
KF_bpf_local_irq_restore,
11693
+ KF_bpf_iter_num_new,
11694
+ KF_bpf_iter_num_next,
11695
+ KF_bpf_iter_num_destroy,
11693
11696
};
11694
11697
11695
11698
BTF_SET_START(special_kfunc_set)
@@ -11765,6 +11768,9 @@ BTF_ID_UNUSED
11765
11768
BTF_ID(func, bpf_get_kmem_cache)
11766
11769
BTF_ID(func, bpf_local_irq_save)
11767
11770
BTF_ID(func, bpf_local_irq_restore)
11771
+ BTF_ID(func, bpf_iter_num_new)
11772
+ BTF_ID(func, bpf_iter_num_next)
11773
+ BTF_ID(func, bpf_iter_num_destroy)
11768
11774
11769
11775
static bool is_kfunc_ret_null(struct bpf_kfunc_call_arg_meta *meta)
11770
11776
{
@@ -12151,12 +12157,24 @@ static bool is_bpf_rbtree_api_kfunc(u32 btf_id)
12151
12157
btf_id == special_kfunc_list[KF_bpf_rbtree_first];
12152
12158
}
12153
12159
12160
+ static bool is_bpf_iter_num_api_kfunc(u32 btf_id)
12161
+ {
12162
+ return btf_id == special_kfunc_list[KF_bpf_iter_num_new] ||
12163
+ btf_id == special_kfunc_list[KF_bpf_iter_num_next] ||
12164
+ btf_id == special_kfunc_list[KF_bpf_iter_num_destroy];
12165
+ }
12166
+
12154
12167
static bool is_bpf_graph_api_kfunc(u32 btf_id)
12155
12168
{
12156
12169
return is_bpf_list_api_kfunc(btf_id) || is_bpf_rbtree_api_kfunc(btf_id) ||
12157
12170
btf_id == special_kfunc_list[KF_bpf_refcount_acquire_impl];
12158
12171
}
12159
12172
12173
+ static bool kfunc_spin_allowed(u32 btf_id)
12174
+ {
12175
+ return is_bpf_graph_api_kfunc(btf_id) || is_bpf_iter_num_api_kfunc(btf_id);
12176
+ }
12177
+
12160
12178
static bool is_sync_callback_calling_kfunc(u32 btf_id)
12161
12179
{
12162
12180
return btf_id == special_kfunc_list[KF_bpf_rbtree_add_impl];
@@ -19048,7 +19066,7 @@ static int do_check(struct bpf_verifier_env *env)
19048
19066
if (env->cur_state->active_locks) {
19049
19067
if ((insn->src_reg == BPF_REG_0 && insn->imm != BPF_FUNC_spin_unlock) ||
19050
19068
(insn->src_reg == BPF_PSEUDO_KFUNC_CALL &&
19051
- (insn->off != 0 || !is_bpf_graph_api_kfunc (insn->imm)))) {
19069
+ (insn->off != 0 || !kfunc_spin_allowed (insn->imm)))) {
19052
19070
verbose(env, "function calls are not allowed while holding a lock\n");
19053
19071
return -EINVAL;
19054
19072
}
0 commit comments