]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: refactor bpf_helper_changes_pkt_data to use helper number
authorEduard Zingerman <eddyz87@gmail.com>
Tue, 10 Dec 2024 04:10:54 +0000 (20:10 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 10 Dec 2024 18:24:57 +0000 (10:24 -0800)
Use BPF helper number instead of function pointer in
bpf_helper_changes_pkt_data(). This would simplify usage of this
function in verifier.c:check_cfg() (in a follow-up patch),
where only helper number is easily available and there is no real need
to lookup helper proto.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20241210041100.1898468-3-eddyz87@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/filter.h
kernel/bpf/core.c
kernel/bpf/verifier.c
net/core/filter.c

index 3a21947f2fd441b6e91a80eae121d5b37cf3c68b..0477254bc2d30f3b48a6097258889584f49d1475 100644 (file)
@@ -1122,7 +1122,7 @@ bool bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena);
 bool bpf_jit_supports_private_stack(void);
 u64 bpf_arch_uaddress_limit(void);
 void arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bp), void *cookie);
-bool bpf_helper_changes_pkt_data(void *func);
+bool bpf_helper_changes_pkt_data(enum bpf_func_id func_id);
 
 static inline bool bpf_dump_raw_ok(const struct cred *cred)
 {
index a2327c4fdc8bc67d42bb5518f6499430f660676a..6fa8041d48318dbc3bc5c7e02994ee8411c68b91 100644 (file)
@@ -2936,7 +2936,7 @@ void __weak bpf_jit_compile(struct bpf_prog *prog)
 {
 }
 
-bool __weak bpf_helper_changes_pkt_data(void *func)
+bool __weak bpf_helper_changes_pkt_data(enum bpf_func_id func_id)
 {
        return false;
 }
index 277c1892bb9a8777a127bfd7d77cdfd790ab0a70..ad3f6d28e8e4ffb830819bc34835fcfcbd2545c9 100644 (file)
@@ -10728,7 +10728,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
        }
 
        /* With LD_ABS/IND some JITs save/restore skb from r1. */
-       changes_data = bpf_helper_changes_pkt_data(fn->func);
+       changes_data = bpf_helper_changes_pkt_data(func_id);
        if (changes_data && fn->arg1_type != ARG_PTR_TO_CTX) {
                verbose(env, "kernel subsystem misconfigured func %s#%d: r1 != ctx\n",
                        func_id_name(func_id), func_id);
index 6625b3f563a4a3110a76b9c12a46340828e16b6e..efb75eed2e35319670820aabbdf130410eac1a23 100644 (file)
@@ -7899,42 +7899,35 @@ static const struct bpf_func_proto bpf_tcp_raw_check_syncookie_ipv6_proto = {
 
 #endif /* CONFIG_INET */
 
-bool bpf_helper_changes_pkt_data(void *func)
-{
-       if (func == bpf_skb_vlan_push ||
-           func == bpf_skb_vlan_pop ||
-           func == bpf_skb_store_bytes ||
-           func == bpf_skb_change_proto ||
-           func == bpf_skb_change_head ||
-           func == sk_skb_change_head ||
-           func == bpf_skb_change_tail ||
-           func == sk_skb_change_tail ||
-           func == bpf_skb_adjust_room ||
-           func == sk_skb_adjust_room ||
-           func == bpf_skb_pull_data ||
-           func == sk_skb_pull_data ||
-           func == bpf_clone_redirect ||
-           func == bpf_l3_csum_replace ||
-           func == bpf_l4_csum_replace ||
-           func == bpf_xdp_adjust_head ||
-           func == bpf_xdp_adjust_meta ||
-           func == bpf_msg_pull_data ||
-           func == bpf_msg_push_data ||
-           func == bpf_msg_pop_data ||
-           func == bpf_xdp_adjust_tail ||
-#if IS_ENABLED(CONFIG_IPV6_SEG6_BPF)
-           func == bpf_lwt_seg6_store_bytes ||
-           func == bpf_lwt_seg6_adjust_srh ||
-           func == bpf_lwt_seg6_action ||
-#endif
-#ifdef CONFIG_INET
-           func == bpf_sock_ops_store_hdr_opt ||
-#endif
-           func == bpf_lwt_in_push_encap ||
-           func == bpf_lwt_xmit_push_encap)
+bool bpf_helper_changes_pkt_data(enum bpf_func_id func_id)
+{
+       switch (func_id) {
+       case BPF_FUNC_clone_redirect:
+       case BPF_FUNC_l3_csum_replace:
+       case BPF_FUNC_l4_csum_replace:
+       case BPF_FUNC_lwt_push_encap:
+       case BPF_FUNC_lwt_seg6_action:
+       case BPF_FUNC_lwt_seg6_adjust_srh:
+       case BPF_FUNC_lwt_seg6_store_bytes:
+       case BPF_FUNC_msg_pop_data:
+       case BPF_FUNC_msg_pull_data:
+       case BPF_FUNC_msg_push_data:
+       case BPF_FUNC_skb_adjust_room:
+       case BPF_FUNC_skb_change_head:
+       case BPF_FUNC_skb_change_proto:
+       case BPF_FUNC_skb_change_tail:
+       case BPF_FUNC_skb_pull_data:
+       case BPF_FUNC_skb_store_bytes:
+       case BPF_FUNC_skb_vlan_pop:
+       case BPF_FUNC_skb_vlan_push:
+       case BPF_FUNC_store_hdr_opt:
+       case BPF_FUNC_xdp_adjust_head:
+       case BPF_FUNC_xdp_adjust_meta:
+       case BPF_FUNC_xdp_adjust_tail:
                return true;
-
-       return false;
+       default:
+               return false;
+       }
 }
 
 const struct bpf_func_proto bpf_event_output_data_proto __weak;