From: kernel test robot <lkp@intel.com>
To: Alexei Starovoitov <ast@kernel.org>
Cc: <llvm@lists.linux.dev>, <oe-kbuild-all@lists.linux.dev>,
Jeff Kirsher <jeff.kirsher@gmail.com>,
Martin KaFai Lau <martin.lau@kernel.org>
Subject: [jkirsher-net-queue:master 4/4] kernel/bpf/verifier.c:20957:1: warning: unused label 'patch_insn_buf'
Date: Wed, 9 Jul 2025 09:18:33 +0800 [thread overview]
Message-ID: <aG3DadX7juesXskm@rli9-mobl> (raw)
[-- Attachment #1: Type: text/plain, Size: 29369 bytes --]
tree: https://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net-queue.git master
head: db494b13c593e578fed58a6e41f4c9df619180d8
commit: db494b13c593e578fed58a6e41f4c9df619180d8 [4/4] bpf: Add support for certain atomics in bpf_arena to x86 JIT
:::::: branch date: 11 hours ago
:::::: commit date: 11 hours ago
config: hexagon-randconfig-002-20250708 (attached as .config)
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project 01c97b4953e87ae455bd4c41e3de3f0f0f29c61c)
reproduce (this is a W=1 build): (attached as reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507090023.F3b8lVbm-lkp@intel.com/
All warnings (new ones prefixed by >>):
kernel/bpf/verifier.c:6415:7: error: call to undeclared function 'bpf_jit_supports_private_stack'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
6415 | if (!bpf_jit_supports_private_stack())
| ^
kernel/bpf/verifier.c:7747:8: error: call to undeclared function 'check_load_mem'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
7747 | err = check_load_mem(env, insn, true, false, false, "atomic_load");
| ^
kernel/bpf/verifier.c:7766:8: error: call to undeclared function 'check_store_reg'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
7766 | err = check_store_reg(env, insn, true);
| ^
kernel/bpf/verifier.c:7780:12: error: conflicting types for 'check_atomic'
7780 | static int check_atomic(struct bpf_verifier_env *env, struct bpf_insn *insn)
| ^
kernel/bpf/verifier.c:7650:12: note: previous definition is here
7650 | static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_insn *insn)
| ^
kernel/bpf/verifier.c:7793:10: error: call to undeclared function 'check_atomic_rmw'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
7793 | return check_atomic_rmw(env, insn);
| ^
kernel/bpf/verifier.c:19477:10: error: call to undeclared function 'check_load_mem'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
19477 | err = check_load_mem(env, insn, false, is_ldsx, true,
| ^
kernel/bpf/verifier.c:19483:33: error: too few arguments to function call, expected 3, have 2
19483 | err = check_atomic(env, insn);
| ~~~~~~~~~~~~ ^
kernel/bpf/verifier.c:7650:12: note: 'check_atomic' declared here
7650 | static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_insn *insn)
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/bpf/verifier.c:19495:10: error: call to undeclared function 'check_store_reg'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
19495 | err = check_store_reg(env, insn, false);
| ^
kernel/bpf/verifier.c:20735:6: warning: unused variable 'epilogue_idx' [-Wunused-variable]
20735 | int epilogue_idx = 0;
| ^~~~~~~~~~~~
>> kernel/bpf/verifier.c:20957:1: warning: unused label 'patch_insn_buf' [-Wunused-label]
20957 | patch_insn_buf:
| ^~~~~~~~~~~~~~~
kernel/bpf/verifier.c:21667:25: error: call to undeclared function 'bpf_arch_uaddress_limit'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
21667 | u64 uaddress_limit = bpf_arch_uaddress_limit();
| ^
kernel/bpf/verifier.c:21765:33: error: call to undeclared function 'bpf_jit_supports_timed_may_goto'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
21765 | if (is_may_goto_insn(insn) && bpf_jit_supports_timed_may_goto()) {
| ^
kernel/bpf/verifier.c:22349:15: error: call to undeclared function 'bpf_jit_supports_timed_may_goto'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
22349 | int delta = bpf_jit_supports_timed_may_goto() ? 2 : 1;
| ^
kernel/bpf/verifier.c:22936:42: error: call to undeclared function 'bpf_jit_supports_private_stack'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
22936 | if (prog->aux->priv_stack_requested && !bpf_jit_supports_private_stack()) {
| ^
2 warnings and 12 errors generated.
--
>> kernel/bpf/core.c:3119:13: warning: no previous prototype for function 'bpf_jit_supports_private_stack' [-Wmissing-prototypes]
3119 | bool __weak bpf_jit_supports_private_stack(void)
| ^
kernel/bpf/core.c:3119:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
3119 | bool __weak bpf_jit_supports_private_stack(void)
| ^
| static
>> kernel/bpf/core.c:3128:13: warning: no previous prototype for function 'bpf_jit_supports_timed_may_goto' [-Wmissing-prototypes]
3128 | bool __weak bpf_jit_supports_timed_may_goto(void)
| ^
kernel/bpf/core.c:3128:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
3128 | bool __weak bpf_jit_supports_timed_may_goto(void)
| ^
| static
2 warnings generated.
vim +/patch_insn_buf +20957 kernel/bpf/verifier.c
a4b1d3c1ddf6cb4 Jiong Wang 2019-05-24 20716
c64b7983288e636 Joe Stringer 2018-10-02 20717 /* convert load instructions that access fields of a context type into a
c64b7983288e636 Joe Stringer 2018-10-02 20718 * sequence of instructions that access fields of the underlying structure:
c64b7983288e636 Joe Stringer 2018-10-02 20719 * struct __sk_buff -> struct sk_buff
c64b7983288e636 Joe Stringer 2018-10-02 20720 * struct bpf_sock_ops -> struct sock
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20721 */
58e2af8b3a6b587 Jakub Kicinski 2016-09-21 20722 static int convert_ctx_accesses(struct bpf_verifier_env *env)
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20723 {
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20724 struct bpf_subprog_info *subprogs = env->subprog_info;
00176a34d9e27ab Jakub Kicinski 2017-10-16 20725 const struct bpf_verifier_ops *ops = env->ops;
d519594ee2445d7 Amery Hung 2025-02-25 20726 int i, cnt, size, ctx_field_size, ret, delta = 0, epilogue_cnt = 0;
3df126f35f88dc7 Jakub Kicinski 2016-09-21 20727 const int insn_cnt = env->prog->len;
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20728 struct bpf_insn *epilogue_buf = env->epilogue_buf;
6f606ffd6dd7583 Martin KaFai Lau 2024-08-29 20729 struct bpf_insn *insn_buf = env->insn_buf;
6f606ffd6dd7583 Martin KaFai Lau 2024-08-29 20730 struct bpf_insn *insn;
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20731 u32 target_size, size_default, off;
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20732 struct bpf_prog *new_prog;
d691f9e8d4405c3 Alexei Starovoitov 2015-06-04 20733 enum bpf_access_type type;
f96da09473b52c0 Daniel Borkmann 2017-07-02 20734 bool is_narrower_load;
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20735 int epilogue_idx = 0;
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20736
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20737 if (ops->gen_epilogue) {
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20738 epilogue_cnt = ops->gen_epilogue(epilogue_buf, env->prog,
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20739 -(subprogs[0].stack_depth + 8));
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20740 if (epilogue_cnt >= INSN_BUF_SIZE) {
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20741 verbose(env, "bpf verifier is misconfigured\n");
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20742 return -EINVAL;
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20743 } else if (epilogue_cnt) {
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20744 /* Save the ARG_PTR_TO_CTX for the epilogue to use */
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20745 cnt = 0;
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20746 subprogs[0].stack_depth += 8;
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20747 insn_buf[cnt++] = BPF_STX_MEM(BPF_DW, BPF_REG_FP, BPF_REG_1,
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20748 -subprogs[0].stack_depth);
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20749 insn_buf[cnt++] = env->prog->insnsi[0];
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20750 new_prog = bpf_patch_insn_data(env, 0, insn_buf, cnt);
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20751 if (!new_prog)
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20752 return -ENOMEM;
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20753 env->prog = new_prog;
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20754 delta += cnt - 1;
d519594ee2445d7 Amery Hung 2025-02-25 20755
d519594ee2445d7 Amery Hung 2025-02-25 20756 ret = add_kfunc_in_insns(env, epilogue_buf, epilogue_cnt - 1);
d519594ee2445d7 Amery Hung 2025-02-25 20757 if (ret < 0)
d519594ee2445d7 Amery Hung 2025-02-25 20758 return ret;
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20759 }
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 20760 }
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20761
b09928b976280d6 Daniel Borkmann 2018-10-24 20762 if (ops->gen_prologue || env->seen_direct_write) {
b09928b976280d6 Daniel Borkmann 2018-10-24 20763 if (!ops->gen_prologue) {
b09928b976280d6 Daniel Borkmann 2018-10-24 20764 verbose(env, "bpf verifier is misconfigured\n");
b09928b976280d6 Daniel Borkmann 2018-10-24 20765 return -EINVAL;
b09928b976280d6 Daniel Borkmann 2018-10-24 20766 }
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20767 cnt = ops->gen_prologue(insn_buf, env->seen_direct_write,
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20768 env->prog);
6f606ffd6dd7583 Martin KaFai Lau 2024-08-29 20769 if (cnt >= INSN_BUF_SIZE) {
61bd5218eef349f Jakub Kicinski 2017-10-09 20770 verbose(env, "bpf verifier is misconfigured\n");
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20771 return -EINVAL;
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20772 } else if (cnt) {
8041902dae5299c Alexei Starovoitov 2017-03-15 20773 new_prog = bpf_patch_insn_data(env, 0, insn_buf, cnt);
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20774 if (!new_prog)
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20775 return -ENOMEM;
8041902dae5299c Alexei Starovoitov 2017-03-15 20776
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20777 env->prog = new_prog;
3df126f35f88dc7 Jakub Kicinski 2016-09-21 20778 delta += cnt - 1;
d519594ee2445d7 Amery Hung 2025-02-25 20779
d519594ee2445d7 Amery Hung 2025-02-25 20780 ret = add_kfunc_in_insns(env, insn_buf, cnt - 1);
d519594ee2445d7 Amery Hung 2025-02-25 20781 if (ret < 0)
d519594ee2445d7 Amery Hung 2025-02-25 20782 return ret;
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20783 }
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20784 }
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20785
d5c47719f244388 Martin KaFai Lau 2024-08-29 20786 if (delta)
d5c47719f244388 Martin KaFai Lau 2024-08-29 20787 WARN_ON(adjust_jmp_off(env->prog, 0, delta));
d5c47719f244388 Martin KaFai Lau 2024-08-29 20788
9d03ebc71a027ca Stanislav Fomichev 2023-01-19 20789 if (bpf_prog_is_offloaded(env->prog->aux))
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20790 return 0;
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20791
3df126f35f88dc7 Jakub Kicinski 2016-09-21 20792 insn = env->prog->insnsi + delta;
36bbef52c7eb646 Daniel Borkmann 2016-09-20 20793
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20794 for (i = 0; i < insn_cnt; i++, insn++) {
c64b7983288e636 Joe Stringer 2018-10-02 20795 bpf_convert_ctx_access_t convert_ctx_access;
1f1e864b65554e3 Yonghong Song 2023-07-27 20796 u8 mode;
c64b7983288e636 Joe Stringer 2018-10-02 20797
62c7989b24dbd34 Daniel Borkmann 2017-01-12 20798 if (insn->code == (BPF_LDX | BPF_MEM | BPF_B) ||
62c7989b24dbd34 Daniel Borkmann 2017-01-12 20799 insn->code == (BPF_LDX | BPF_MEM | BPF_H) ||
62c7989b24dbd34 Daniel Borkmann 2017-01-12 20800 insn->code == (BPF_LDX | BPF_MEM | BPF_W) ||
1f9a1ea821ff253 Yonghong Song 2023-07-27 20801 insn->code == (BPF_LDX | BPF_MEM | BPF_DW) ||
1f9a1ea821ff253 Yonghong Song 2023-07-27 20802 insn->code == (BPF_LDX | BPF_MEMSX | BPF_B) ||
1f9a1ea821ff253 Yonghong Song 2023-07-27 20803 insn->code == (BPF_LDX | BPF_MEMSX | BPF_H) ||
1f9a1ea821ff253 Yonghong Song 2023-07-27 20804 insn->code == (BPF_LDX | BPF_MEMSX | BPF_W)) {
d691f9e8d4405c3 Alexei Starovoitov 2015-06-04 20805 type = BPF_READ;
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20806 } else if (insn->code == (BPF_STX | BPF_MEM | BPF_B) ||
62c7989b24dbd34 Daniel Borkmann 2017-01-12 20807 insn->code == (BPF_STX | BPF_MEM | BPF_H) ||
62c7989b24dbd34 Daniel Borkmann 2017-01-12 20808 insn->code == (BPF_STX | BPF_MEM | BPF_W) ||
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20809 insn->code == (BPF_STX | BPF_MEM | BPF_DW) ||
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20810 insn->code == (BPF_ST | BPF_MEM | BPF_B) ||
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20811 insn->code == (BPF_ST | BPF_MEM | BPF_H) ||
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20812 insn->code == (BPF_ST | BPF_MEM | BPF_W) ||
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20813 insn->code == (BPF_ST | BPF_MEM | BPF_DW)) {
d691f9e8d4405c3 Alexei Starovoitov 2015-06-04 20814 type = BPF_WRITE;
db494b13c593e57 Alexei Starovoitov 2024-04-05 20815 } else if ((insn->code == (BPF_STX | BPF_ATOMIC | BPF_W) ||
d503a04f8bc0c75 Alexei Starovoitov 2024-04-05 20816 insn->code == (BPF_STX | BPF_ATOMIC | BPF_DW)) &&
d503a04f8bc0c75 Alexei Starovoitov 2024-04-05 20817 env->insn_aux_data[i + delta].ptr_type == PTR_TO_ARENA) {
d503a04f8bc0c75 Alexei Starovoitov 2024-04-05 20818 insn->code = BPF_STX | BPF_PROBE_ATOMIC | BPF_SIZE(insn->code);
d503a04f8bc0c75 Alexei Starovoitov 2024-04-05 20819 env->prog->aux->num_exentries++;
d503a04f8bc0c75 Alexei Starovoitov 2024-04-05 20820 continue;
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20821 } else {
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20822 continue;
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20823 }
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20824
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20825 if (type == BPF_WRITE &&
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20826 env->insn_aux_data[i + delta].sanitize_stack_spill) {
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20827 struct bpf_insn patch[] = {
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20828 *insn,
2039f26f3aca5b0 Daniel Borkmann 2021-07-13 20829 BPF_ST_NOSPEC(),
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20830 };
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20831
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20832 cnt = ARRAY_SIZE(patch);
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20833 new_prog = bpf_patch_insn_data(env, i + delta, patch, cnt);
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20834 if (!new_prog)
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20835 return -ENOMEM;
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20836
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20837 delta += cnt - 1;
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20838 env->prog = new_prog;
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20839 insn = new_prog->insnsi + i + delta;
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20840 continue;
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20841 }
af86ca4e3088fe5 Alexei Starovoitov 2018-05-15 20842
6efe152d4061a83 Kumar Kartikeya Dwivedi 2022-04-25 20843 switch ((int)env->insn_aux_data[i + delta].ptr_type) {
c64b7983288e636 Joe Stringer 2018-10-02 20844 case PTR_TO_CTX:
c64b7983288e636 Joe Stringer 2018-10-02 20845 if (!ops->convert_ctx_access)
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20846 continue;
c64b7983288e636 Joe Stringer 2018-10-02 20847 convert_ctx_access = ops->convert_ctx_access;
c64b7983288e636 Joe Stringer 2018-10-02 20848 break;
c64b7983288e636 Joe Stringer 2018-10-02 20849 case PTR_TO_SOCKET:
46f8bc92758c625 Martin KaFai Lau 2019-02-09 20850 case PTR_TO_SOCK_COMMON:
c64b7983288e636 Joe Stringer 2018-10-02 20851 convert_ctx_access = bpf_sock_convert_ctx_access;
c64b7983288e636 Joe Stringer 2018-10-02 20852 break;
655a51e536c09d1 Martin KaFai Lau 2019-02-09 20853 case PTR_TO_TCP_SOCK:
655a51e536c09d1 Martin KaFai Lau 2019-02-09 20854 convert_ctx_access = bpf_tcp_sock_convert_ctx_access;
655a51e536c09d1 Martin KaFai Lau 2019-02-09 20855 break;
fada7fdc83c0bf8 Jonathan Lemon 2019-06-06 20856 case PTR_TO_XDP_SOCK:
fada7fdc83c0bf8 Jonathan Lemon 2019-06-06 20857 convert_ctx_access = bpf_xdp_sock_convert_ctx_access;
fada7fdc83c0bf8 Jonathan Lemon 2019-06-06 20858 break;
2a02759ef5f8a34 Alexei Starovoitov 2019-10-15 20859 case PTR_TO_BTF_ID:
6efe152d4061a83 Kumar Kartikeya Dwivedi 2022-04-25 20860 case PTR_TO_BTF_ID | PTR_UNTRUSTED:
282de143ead96a5 Kumar Kartikeya Dwivedi 2022-11-18 20861 /* PTR_TO_BTF_ID | MEM_ALLOC always has a valid lifetime, unlike
282de143ead96a5 Kumar Kartikeya Dwivedi 2022-11-18 20862 * PTR_TO_BTF_ID, and an active ref_obj_id, but the same cannot
282de143ead96a5 Kumar Kartikeya Dwivedi 2022-11-18 20863 * be said once it is marked PTR_UNTRUSTED, hence we must handle
282de143ead96a5 Kumar Kartikeya Dwivedi 2022-11-18 20864 * any faults for loads into such types. BPF_WRITE is disallowed
282de143ead96a5 Kumar Kartikeya Dwivedi 2022-11-18 20865 * for this case.
282de143ead96a5 Kumar Kartikeya Dwivedi 2022-11-18 20866 */
282de143ead96a5 Kumar Kartikeya Dwivedi 2022-11-18 20867 case PTR_TO_BTF_ID | MEM_ALLOC | PTR_UNTRUSTED:
27ae7997a66174c Martin KaFai Lau 2020-01-08 20868 if (type == BPF_READ) {
1f9a1ea821ff253 Yonghong Song 2023-07-27 20869 if (BPF_MODE(insn->code) == BPF_MEM)
27ae7997a66174c Martin KaFai Lau 2020-01-08 20870 insn->code = BPF_LDX | BPF_PROBE_MEM |
27ae7997a66174c Martin KaFai Lau 2020-01-08 20871 BPF_SIZE((insn)->code);
1f9a1ea821ff253 Yonghong Song 2023-07-27 20872 else
1f9a1ea821ff253 Yonghong Song 2023-07-27 20873 insn->code = BPF_LDX | BPF_PROBE_MEMSX |
1f9a1ea821ff253 Yonghong Song 2023-07-27 20874 BPF_SIZE((insn)->code);
27ae7997a66174c Martin KaFai Lau 2020-01-08 20875 env->prog->aux->num_exentries++;
2a02759ef5f8a34 Alexei Starovoitov 2019-10-15 20876 }
2a02759ef5f8a34 Alexei Starovoitov 2019-10-15 20877 continue;
6082b6c328b5486 Alexei Starovoitov 2024-03-07 20878 case PTR_TO_ARENA:
6082b6c328b5486 Alexei Starovoitov 2024-03-07 20879 if (BPF_MODE(insn->code) == BPF_MEMSX) {
6082b6c328b5486 Alexei Starovoitov 2024-03-07 20880 verbose(env, "sign extending loads from arena are not supported yet\n");
6082b6c328b5486 Alexei Starovoitov 2024-03-07 20881 return -EOPNOTSUPP;
6082b6c328b5486 Alexei Starovoitov 2024-03-07 20882 }
6082b6c328b5486 Alexei Starovoitov 2024-03-07 20883 insn->code = BPF_CLASS(insn->code) | BPF_PROBE_MEM32 | BPF_SIZE(insn->code);
6082b6c328b5486 Alexei Starovoitov 2024-03-07 20884 env->prog->aux->num_exentries++;
6082b6c328b5486 Alexei Starovoitov 2024-03-07 20885 continue;
c64b7983288e636 Joe Stringer 2018-10-02 20886 default:
c64b7983288e636 Joe Stringer 2018-10-02 20887 continue;
c64b7983288e636 Joe Stringer 2018-10-02 20888 }
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20889
31fd85816dbe3a7 Yonghong Song 2017-06-13 20890 ctx_field_size = env->insn_aux_data[i + delta].ctx_field_size;
f96da09473b52c0 Daniel Borkmann 2017-07-02 20891 size = BPF_LDST_BYTES(insn);
1f1e864b65554e3 Yonghong Song 2023-07-27 20892 mode = BPF_MODE(insn->code);
31fd85816dbe3a7 Yonghong Song 2017-06-13 20893
31fd85816dbe3a7 Yonghong Song 2017-06-13 20894 /* If the read access is a narrower load of the field,
31fd85816dbe3a7 Yonghong Song 2017-06-13 20895 * convert to a 4/8-byte load, to minimum program type specific
31fd85816dbe3a7 Yonghong Song 2017-06-13 20896 * convert_ctx_access changes. If conversion is successful,
31fd85816dbe3a7 Yonghong Song 2017-06-13 20897 * we will apply proper mask to the result.
31fd85816dbe3a7 Yonghong Song 2017-06-13 20898 */
f96da09473b52c0 Daniel Borkmann 2017-07-02 20899 is_narrower_load = size < ctx_field_size;
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20900 size_default = bpf_ctx_off_adjust_machine(ctx_field_size);
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20901 off = insn->off;
31fd85816dbe3a7 Yonghong Song 2017-06-13 20902 if (is_narrower_load) {
f96da09473b52c0 Daniel Borkmann 2017-07-02 20903 u8 size_code;
31fd85816dbe3a7 Yonghong Song 2017-06-13 20904
f96da09473b52c0 Daniel Borkmann 2017-07-02 20905 if (type == BPF_WRITE) {
61bd5218eef349f Jakub Kicinski 2017-10-09 20906 verbose(env, "bpf verifier narrow ctx access misconfigured\n");
f96da09473b52c0 Daniel Borkmann 2017-07-02 20907 return -EINVAL;
f96da09473b52c0 Daniel Borkmann 2017-07-02 20908 }
f96da09473b52c0 Daniel Borkmann 2017-07-02 20909
f96da09473b52c0 Daniel Borkmann 2017-07-02 20910 size_code = BPF_H;
31fd85816dbe3a7 Yonghong Song 2017-06-13 20911 if (ctx_field_size == 4)
31fd85816dbe3a7 Yonghong Song 2017-06-13 20912 size_code = BPF_W;
31fd85816dbe3a7 Yonghong Song 2017-06-13 20913 else if (ctx_field_size == 8)
31fd85816dbe3a7 Yonghong Song 2017-06-13 20914 size_code = BPF_DW;
f96da09473b52c0 Daniel Borkmann 2017-07-02 20915
bc23105ca0abdee Daniel Borkmann 2018-06-02 20916 insn->off = off & ~(size_default - 1);
31fd85816dbe3a7 Yonghong Song 2017-06-13 20917 insn->code = BPF_LDX | BPF_MEM | size_code;
31fd85816dbe3a7 Yonghong Song 2017-06-13 20918 }
f96da09473b52c0 Daniel Borkmann 2017-07-02 20919
f96da09473b52c0 Daniel Borkmann 2017-07-02 20920 target_size = 0;
c64b7983288e636 Joe Stringer 2018-10-02 20921 cnt = convert_ctx_access(type, insn, insn_buf, env->prog,
f96da09473b52c0 Daniel Borkmann 2017-07-02 20922 &target_size);
6f606ffd6dd7583 Martin KaFai Lau 2024-08-29 20923 if (cnt == 0 || cnt >= INSN_BUF_SIZE ||
f96da09473b52c0 Daniel Borkmann 2017-07-02 20924 (ctx_field_size && !target_size)) {
61bd5218eef349f Jakub Kicinski 2017-10-09 20925 verbose(env, "bpf verifier is misconfigured\n");
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20926 return -EINVAL;
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20927 }
f96da09473b52c0 Daniel Borkmann 2017-07-02 20928
f96da09473b52c0 Daniel Borkmann 2017-07-02 20929 if (is_narrower_load && size < target_size) {
d895a0f16fadb26 Ilya Leoshkevich 2019-08-16 20930 u8 shift = bpf_ctx_narrow_access_offset(
d895a0f16fadb26 Ilya Leoshkevich 2019-08-16 20931 off, size, size_default) * 8;
6f606ffd6dd7583 Martin KaFai Lau 2024-08-29 20932 if (shift && cnt + 1 >= INSN_BUF_SIZE) {
d7af7e497f0308b Andrey Ignatov 2021-08-20 20933 verbose(env, "bpf verifier narrow ctx load misconfigured\n");
d7af7e497f0308b Andrey Ignatov 2021-08-20 20934 return -EINVAL;
d7af7e497f0308b Andrey Ignatov 2021-08-20 20935 }
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20936 if (ctx_field_size <= 4) {
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20937 if (shift)
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20938 insn_buf[cnt++] = BPF_ALU32_IMM(BPF_RSH,
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20939 insn->dst_reg,
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20940 shift);
31fd85816dbe3a7 Yonghong Song 2017-06-13 20941 insn_buf[cnt++] = BPF_ALU32_IMM(BPF_AND, insn->dst_reg,
31fd85816dbe3a7 Yonghong Song 2017-06-13 20942 (1 << size * 8) - 1);
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20943 } else {
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20944 if (shift)
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20945 insn_buf[cnt++] = BPF_ALU64_IMM(BPF_RSH,
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20946 insn->dst_reg,
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20947 shift);
0613d8ca9ab382c Will Deacon 2023-05-18 20948 insn_buf[cnt++] = BPF_ALU32_IMM(BPF_AND, insn->dst_reg,
e2f7fc0ac6957ca Krzesimir Nowak 2019-05-08 20949 (1ULL << size * 8) - 1);
31fd85816dbe3a7 Yonghong Song 2017-06-13 20950 }
46f53a65d2de3e1 Andrey Ignatov 2018-11-10 20951 }
1f1e864b65554e3 Yonghong Song 2023-07-27 20952 if (mode == BPF_MEMSX)
1f1e864b65554e3 Yonghong Song 2023-07-27 20953 insn_buf[cnt++] = BPF_RAW_INSN(BPF_ALU64 | BPF_MOV | BPF_X,
1f1e864b65554e3 Yonghong Song 2023-07-27 20954 insn->dst_reg, insn->dst_reg,
1f1e864b65554e3 Yonghong Song 2023-07-27 20955 size * 8, 0);
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20956
169c31761c8d7f6 Martin KaFai Lau 2024-08-29 @20957 patch_insn_buf:
8041902dae5299c Alexei Starovoitov 2017-03-15 20958 new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20959 if (!new_prog)
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20960 return -ENOMEM;
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20961
3df126f35f88dc7 Jakub Kicinski 2016-09-21 20962 delta += cnt - 1;
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20963
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20964 /* keep walking new program and skip insns we just inserted */
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20965 env->prog = new_prog;
3df126f35f88dc7 Jakub Kicinski 2016-09-21 20966 insn = new_prog->insnsi + i + delta;
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20967 }
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20968
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20969 return 0;
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20970 }
9bac3d6d548e5cc Alexei Starovoitov 2015-03-13 20971
:::::: The code at line 20957 was first introduced by commit
:::::: 169c31761c8d7f606f3ee628829c27998626c4f0 bpf: Add gen_epilogue to bpf_verifier_ops
:::::: TO: Martin KaFai Lau <martin.lau@kernel.org>
:::::: CC: Alexei Starovoitov <ast@kernel.org>
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 42811 bytes --]
[-- Attachment #3: reproduce --]
[-- Type: text/plain, Size: 923 bytes --]
reproduce (this is a W=1 build):
git clone https://github.com/intel/lkp-tests.git ~/lkp-tests
# clang-21 might not be officially released. Try a lower version if installation fails.
# https://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net-queue.git/commit/?id=db494b13c593e578fed58a6e41f4c9df619180d8
git remote add jkirsher-net-queue https://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net-queue.git
git fetch --no-tags jkirsher-net-queue master
git checkout db494b13c593e578fed58a6e41f4c9df619180d8
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang-21 ~/lkp-tests/kbuild/make.cross W=1 O=build_dir ARCH=hexagon olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang-21 ~/lkp-tests/kbuild/make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash kernel/bpf/
reply other threads:[~2025-07-09 1:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aG3DadX7juesXskm@rli9-mobl \
--to=lkp@intel.com \
--cc=ast@kernel.org \
--cc=jeff.kirsher@gmail.com \
--cc=llvm@lists.linux.dev \
--cc=martin.lau@kernel.org \
--cc=oe-kbuild-all@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox