Skip to content

Commit b396d4d

Browse files
LPhghKernel Patches Daemon
authored andcommitted
bpf: Allow bpf_dynptr_from_skb() for tp_btf
Making tp_btf able to use bpf_dynptr_from_skb(), which is useful for skb parsing, especially for non-linear paged skb data. This is achieved by adding KF_TRUSTED_ARGS flag to bpf_dynptr_from_skb and registering it for TRACING progs. With KF_TRUSTED_ARGS, args from fentry/fexit are excluded, so that unsafe progs like fexit/__kfree_skb are not allowed. We also need the skb dynptr to be read-only in tp_btf. Because may_access_direct_pkt_data() returns false by default when checking bpf_dynptr_from_skb, there is no need to add BPF_PROG_TYPE_TRACING to it explicitly. Suggested-by: Martin KaFai Lau <[email protected]> Signed-off-by: Philo Lu <[email protected]> Acked-by: Martin KaFai Lau <[email protected]>
1 parent e352864 commit b396d4d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/core/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12056,7 +12056,7 @@ int bpf_dynptr_from_skb_rdonly(struct __sk_buff *skb, u64 flags,
1205612056
}
1205712057

1205812058
BTF_KFUNCS_START(bpf_kfunc_check_set_skb)
12059-
BTF_ID_FLAGS(func, bpf_dynptr_from_skb)
12059+
BTF_ID_FLAGS(func, bpf_dynptr_from_skb, KF_TRUSTED_ARGS)
1206012060
BTF_KFUNCS_END(bpf_kfunc_check_set_skb)
1206112061

1206212062
BTF_KFUNCS_START(bpf_kfunc_check_set_xdp)
@@ -12105,6 +12105,7 @@ static int __init bpf_kfunc_init(void)
1210512105
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_LWT_XMIT, &bpf_kfunc_set_skb);
1210612106
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_LWT_SEG6LOCAL, &bpf_kfunc_set_skb);
1210712107
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_NETFILTER, &bpf_kfunc_set_skb);
12108+
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, &bpf_kfunc_set_skb);
1210812109
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &bpf_kfunc_set_xdp);
1210912110
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
1211012111
&bpf_kfunc_set_sock_addr);

0 commit comments

Comments
 (0)