Skip to content

Commit 43191ad

Browse files
committed
bpf: Clear packet pointers after changing packet data in kfuncs
bpf_xdp_pull_data() may change packet data and therefore packet pointers need to be invalidated. Add bpf_xdp_pull_data() to the special kfunc list instead of introducing a new KF_ flag until there are more kfuncs changing packet data. Signed-off-by: Amery Hung <[email protected]>
1 parent 1e98550 commit 43191ad

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

kernel/bpf/verifier.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12228,6 +12228,7 @@ enum special_kfunc_type {
1222812228
KF_bpf_rbtree_right,
1222912229
KF_bpf_dynptr_from_skb,
1223012230
KF_bpf_dynptr_from_xdp,
12231+
KF_bpf_xdp_pull_data,
1223112232
KF_bpf_dynptr_slice,
1223212233
KF_bpf_dynptr_slice_rdwr,
1223312234
KF_bpf_dynptr_clone,
@@ -12277,9 +12278,11 @@ BTF_ID(func, bpf_rbtree_right)
1227712278
#ifdef CONFIG_NET
1227812279
BTF_ID(func, bpf_dynptr_from_skb)
1227912280
BTF_ID(func, bpf_dynptr_from_xdp)
12281+
BTF_ID(func, bpf_xdp_pull_data)
1228012282
#else
1228112283
BTF_ID_UNUSED
1228212284
BTF_ID_UNUSED
12285+
BTF_ID_UNUSED
1228312286
#endif
1228412287
BTF_ID(func, bpf_dynptr_slice)
1228512288
BTF_ID(func, bpf_dynptr_slice_rdwr)
@@ -12349,6 +12352,11 @@ static bool is_kfunc_bpf_preempt_enable(struct bpf_kfunc_call_arg_meta *meta)
1234912352
return meta->func_id == special_kfunc_list[KF_bpf_preempt_enable];
1235012353
}
1235112354

12355+
static bool is_kfunc_pkt_changing(struct bpf_kfunc_call_arg_meta *meta)
12356+
{
12357+
return meta->func_id == special_kfunc_list[KF_bpf_xdp_pull_data];
12358+
}
12359+
1235212360
static enum kfunc_ptr_arg_type
1235312361
get_kfunc_ptr_arg_type(struct bpf_verifier_env *env,
1235412362
struct bpf_kfunc_call_arg_meta *meta,
@@ -14066,6 +14074,9 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
1406614074
}
1406714075
}
1406814076

14077+
if (is_kfunc_pkt_changing(&meta))
14078+
clear_all_pkt_pointers(env);
14079+
1406914080
nargs = btf_type_vlen(meta.func_proto);
1407014081
args = (const struct btf_param *)(meta.func_proto + 1);
1407114082
for (i = 0; i < nargs; i++) {
@@ -17783,6 +17794,8 @@ static int visit_insn(int t, struct bpf_verifier_env *env)
1778317794
*/
1778417795
if (ret == 0 && is_kfunc_sleepable(&meta))
1778517796
mark_subprog_might_sleep(env, t);
17797+
if (ret == 0 && is_kfunc_pkt_changing(&meta))
17798+
mark_subprog_changes_pkt_data(env, t);
1778617799
}
1778717800
return visit_func_call_insn(t, insns, env, insn->src_reg == BPF_PSEUDO_CALL);
1778817801

0 commit comments

Comments
 (0)