All of lore.kernel.org
 help / color / mirror / Atom feed
* [ast-bpf:relo_core 2/12] tools/lib/bpf/relo_core.c:1040:7: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]
@ 2021-10-01 19:25 kernel test robot
  0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2021-10-01 19:25 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 25946 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
CC: linux-kernel(a)vger.kernel.org
TO: Alexei Starovoitov <ast@kernel.org>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/ast/bpf.git relo_core
head:   b59680f8f85fc73f14859ee02567897309ba8f65
commit: 28e76eb078b4674fecfda090ee4cbd80340a1d71 [2/12] bpf: Prepare relo_core.c for kernel duty.
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: x86_64-randconfig-c007-20210930 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 28981015526f2192440c18f18e8a20cd11b0779c)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://git.kernel.org/pub/scm/linux/kernel/git/ast/bpf.git/commit/?id=28e76eb078b4674fecfda090ee4cbd80340a1d71
        git remote add ast-bpf https://git.kernel.org/pub/scm/linux/kernel/git/ast/bpf.git
        git fetch --no-tags ast-bpf relo_core
        git checkout 28e76eb078b4674fecfda090ee4cbd80340a1d71
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
            ^
   include/linux/list.h:282:9: note: Left side of '||' is false
           return READ_ONCE(head->next) == head;
                  ^
   include/asm-generic/rwonce.h:49:2: note: expanded from macro 'READ_ONCE'
           compiletime_assert_rwonce_type(x);                              \
           ^
   include/asm-generic/rwonce.h:36:21: note: expanded from macro 'compiletime_assert_rwonce_type'
           compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
                              ^
   include/linux/compiler_types.h:290:3: note: expanded from macro '__native_word'
           (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
            ^
   include/linux/list.h:282:9: note: Left side of '||' is false
           return READ_ONCE(head->next) == head;
                  ^
   include/asm-generic/rwonce.h:49:2: note: expanded from macro 'READ_ONCE'
           compiletime_assert_rwonce_type(x);                              \
           ^
   include/asm-generic/rwonce.h:36:21: note: expanded from macro 'compiletime_assert_rwonce_type'
           compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
                              ^
   include/linux/compiler_types.h:290:3: note: expanded from macro '__native_word'
           (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
            ^
   include/linux/list.h:282:9: note: Left side of '||' is true
           return READ_ONCE(head->next) == head;
                  ^
   include/asm-generic/rwonce.h:49:2: note: expanded from macro 'READ_ONCE'
           compiletime_assert_rwonce_type(x);                              \
           ^
   include/asm-generic/rwonce.h:36:38: note: expanded from macro 'compiletime_assert_rwonce_type'
           compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
                                               ^
   include/linux/list.h:282:9: note: Taking false branch
           return READ_ONCE(head->next) == head;
                  ^
   include/asm-generic/rwonce.h:49:2: note: expanded from macro 'READ_ONCE'
           compiletime_assert_rwonce_type(x);                              \
           ^
   include/asm-generic/rwonce.h:36:2: note: expanded from macro 'compiletime_assert_rwonce_type'
           compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
           ^
   include/linux/compiler_types.h:322:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:310:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:302:3: note: expanded from macro '__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   include/linux/list.h:282:9: note: Loop condition is false.  Exiting loop
           return READ_ONCE(head->next) == head;
                  ^
   include/asm-generic/rwonce.h:49:2: note: expanded from macro 'READ_ONCE'
           compiletime_assert_rwonce_type(x);                              \
           ^
   include/asm-generic/rwonce.h:36:2: note: expanded from macro 'compiletime_assert_rwonce_type'
           compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long),  \
           ^
   include/linux/compiler_types.h:322:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:310:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:300:2: note: expanded from macro '__compiletime_assert'
           do {                                                            \
           ^
   include/linux/list.h:282:9: note: Dereference of null pointer
           return READ_ONCE(head->next) == head;
                  ^
   include/asm-generic/rwonce.h:50:2: note: expanded from macro 'READ_ONCE'
           __READ_ONCE(x);                                                 \
           ^~~~~~~~~~~~~~
   include/asm-generic/rwonce.h:44:24: note: expanded from macro '__READ_ONCE'
   #define __READ_ONCE(x)  (*(const volatile __unqual_scalar_typeof(x) *)&(x))
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/gcov/fs.c:532:3: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
                   strcpy(node->name, name);
                   ^~~~~~
   kernel/gcov/fs.c:532:3: note: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119
                   strcpy(node->name, name);
                   ^~~~~~
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   8 warnings generated.
   Suppressed 8 warnings (8 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   8 warnings generated.
   Suppressed 8 warnings (8 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   8 warnings generated.
   Suppressed 8 warnings (8 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   9 warnings generated.
   Suppressed 9 warnings (9 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   6 warnings generated.
>> tools/lib/bpf/relo_core.c:1040:7: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]
                   if (res->fail_memsz_adjust) {
                       ^
   tools/lib/bpf/relo_core.c:1230:6: note: Assuming 'local_type' is non-null
           if (!local_type)
               ^~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1230:2: note: Taking false branch
           if (!local_type)
           ^
   tools/lib/bpf/relo_core.c:1234:6: note: Assuming 'local_name' is non-null
           if (!local_name)
               ^~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1234:2: note: Taking false branch
           if (!local_name)
           ^
   tools/lib/bpf/relo_core.c:1238:6: note: Calling 'str_is_empty'
           if (str_is_empty(spec_str))
               ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/btf.h:148:9: note: Assuming 's' is non-null
           return !s || !s[0];
                  ^~
   include/linux/btf.h:148:9: note: Left side of '||' is false
   include/linux/btf.h:148:15: note: Assuming the condition is false
           return !s || !s[0];
                        ^~~~~
   include/linux/btf.h:148:2: note: Returning zero, which participates in a condition later
           return !s || !s[0];
           ^~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1238:6: note: Returning from 'str_is_empty'
           if (str_is_empty(spec_str))
               ^~~~~~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1238:2: note: Taking false branch
           if (str_is_empty(spec_str))
           ^
   tools/lib/bpf/relo_core.c:1242:6: note: Assuming 'err' is 0
           if (err) {
               ^~~
   tools/lib/bpf/relo_core.c:1242:2: note: Taking false branch
           if (err) {
           ^
   tools/lib/bpf/relo_core.c:1250:2: note: Loop condition is false.  Exiting loop
           pr_debug("prog '%s': relo #%d: kind <%s> (%d), spec is ", prog_name,
           ^
   tools/lib/bpf/relo_core.c:69:28: note: expanded from macro 'pr_debug'
   #define pr_debug(fmt, ...)      __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__)
                                   ^
   tools/lib/bpf/relo_core.c:59:31: note: expanded from macro '__pr'
   #define __pr(level, fmt, ...)   \
                                   ^
   tools/lib/bpf/relo_core.c:1256:12: note: Field 'kind' is equal to BPF_TYPE_ID_LOCAL
           if (relo->kind == BPF_TYPE_ID_LOCAL) {
                     ^
   tools/lib/bpf/relo_core.c:1256:2: note: Taking true branch
           if (relo->kind == BPF_TYPE_ID_LOCAL) {
           ^
   tools/lib/bpf/relo_core.c:1261:3: note: Control jumps to line 1355
                   goto patch_insn;
                   ^
   tools/lib/bpf/relo_core.c:1355:8: note: Calling 'bpf_core_patch_insn'
           err = bpf_core_patch_insn(prog_name, insn, insn_idx, relo, relo_idx, &targ_res);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:996:11: note: Field 'poison' is false
           if (res->poison) {
                    ^
   tools/lib/bpf/relo_core.c:996:2: note: Taking false branch
           if (res->poison) {
           ^
   tools/lib/bpf/relo_core.c:1010:2: note: Control jumps to 'case 3:'  at line 1029
           switch (class) {
           ^
   tools/lib/bpf/relo_core.c:1030:12: note: Field 'validate' is true
                   if (res->validate && insn->off != orig_val) {
                            ^
   tools/lib/bpf/relo_core.c:1030:7: note: Left side of '&&' is true
                   if (res->validate && insn->off != orig_val) {
                       ^
   tools/lib/bpf/relo_core.c:1030:24: note: Assuming 'orig_val' is equal to field 'off'
                   if (res->validate && insn->off != orig_val) {
                                        ^~~~~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1030:3: note: Taking false branch
                   if (res->validate && insn->off != orig_val) {
                   ^
   tools/lib/bpf/relo_core.c:1035:7: note: Assuming the condition is false
                   if (new_val > SHRT_MAX) {
                       ^~~~~~~~~~~~~~~~~~
   tools/lib/bpf/relo_core.c:1035:3: note: Taking false branch
                   if (new_val > SHRT_MAX) {
                   ^
   tools/lib/bpf/relo_core.c:1040:7: note: Branch condition evaluates to a garbage value
                   if (res->fail_memsz_adjust) {
                       ^~~~~~~~~~~~~~~~~~~~~~
   Suppressed 5 warnings (4 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   3 warnings generated.
   Suppressed 3 warnings (3 in non-user code).

vim +1040 tools/lib/bpf/relo_core.c

b0588390dbcedc Alexei Starovoitov 2021-07-20   969  
b0588390dbcedc Alexei Starovoitov 2021-07-20   970  /*
b0588390dbcedc Alexei Starovoitov 2021-07-20   971   * Patch relocatable BPF instruction.
b0588390dbcedc Alexei Starovoitov 2021-07-20   972   *
b0588390dbcedc Alexei Starovoitov 2021-07-20   973   * Patched value is determined by relocation kind and target specification.
b0588390dbcedc Alexei Starovoitov 2021-07-20   974   * For existence relocations target spec will be NULL if field/type is not found.
b0588390dbcedc Alexei Starovoitov 2021-07-20   975   * Expected insn->imm value is determined using relocation kind and local
b0588390dbcedc Alexei Starovoitov 2021-07-20   976   * spec, and is checked before patching instruction. If actual insn->imm value
b0588390dbcedc Alexei Starovoitov 2021-07-20   977   * is wrong, bail out with error.
b0588390dbcedc Alexei Starovoitov 2021-07-20   978   *
b0588390dbcedc Alexei Starovoitov 2021-07-20   979   * Currently supported classes of BPF instruction are:
b0588390dbcedc Alexei Starovoitov 2021-07-20   980   * 1. rX = <imm> (assignment with immediate operand);
b0588390dbcedc Alexei Starovoitov 2021-07-20   981   * 2. rX += <imm> (arithmetic operations with immediate operand);
b0588390dbcedc Alexei Starovoitov 2021-07-20   982   * 3. rX = <imm64> (load with 64-bit immediate value);
b0588390dbcedc Alexei Starovoitov 2021-07-20   983   * 4. rX = *(T *)(rY + <off>), where T is one of {u8, u16, u32, u64};
b0588390dbcedc Alexei Starovoitov 2021-07-20   984   * 5. *(T *)(rX + <off>) = rY, where T is one of {u8, u16, u32, u64};
b0588390dbcedc Alexei Starovoitov 2021-07-20   985   * 6. *(T *)(rX + <off>) = <imm>, where T is one of {u8, u16, u32, u64}.
b0588390dbcedc Alexei Starovoitov 2021-07-20   986   */
b0588390dbcedc Alexei Starovoitov 2021-07-20   987  static int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
b0588390dbcedc Alexei Starovoitov 2021-07-20   988  			       int insn_idx, const struct bpf_core_relo *relo,
b0588390dbcedc Alexei Starovoitov 2021-07-20   989  			       int relo_idx, const struct bpf_core_relo_res *res)
b0588390dbcedc Alexei Starovoitov 2021-07-20   990  {
b0588390dbcedc Alexei Starovoitov 2021-07-20   991  	__u32 orig_val, new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20   992  	__u8 class;
b0588390dbcedc Alexei Starovoitov 2021-07-20   993  
b0588390dbcedc Alexei Starovoitov 2021-07-20   994  	class = BPF_CLASS(insn->code);
b0588390dbcedc Alexei Starovoitov 2021-07-20   995  
b0588390dbcedc Alexei Starovoitov 2021-07-20   996  	if (res->poison) {
b0588390dbcedc Alexei Starovoitov 2021-07-20   997  poison:
b0588390dbcedc Alexei Starovoitov 2021-07-20   998  		/* poison second part of ldimm64 to avoid confusing error from
b0588390dbcedc Alexei Starovoitov 2021-07-20   999  		 * verifier about "unknown opcode 00"
b0588390dbcedc Alexei Starovoitov 2021-07-20  1000  		 */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1001  		if (is_ldimm64_insn(insn))
b0588390dbcedc Alexei Starovoitov 2021-07-20  1002  			bpf_core_poison_insn(prog_name, relo_idx, insn_idx + 1, insn + 1);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1003  		bpf_core_poison_insn(prog_name, relo_idx, insn_idx, insn);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1004  		return 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1005  	}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1006  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1007  	orig_val = res->orig_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1008  	new_val = res->new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1009  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1010  	switch (class) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1011  	case BPF_ALU:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1012  	case BPF_ALU64:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1013  		if (BPF_SRC(insn->code) != BPF_K)
b0588390dbcedc Alexei Starovoitov 2021-07-20  1014  			return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1015  		if (res->validate && insn->imm != orig_val) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1016  			pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %u, exp %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1017  				prog_name, relo_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1018  				insn_idx, insn->imm, orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1019  			return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1020  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1021  		orig_val = insn->imm;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1022  		insn->imm = new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1023  		pr_debug("prog '%s': relo #%d: patched insn #%d (ALU/ALU64) imm %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1024  			 prog_name, relo_idx, insn_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1025  			 orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1026  		break;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1027  	case BPF_LDX:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1028  	case BPF_ST:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1029  	case BPF_STX:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1030  		if (res->validate && insn->off != orig_val) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1031  			pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %u, exp %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1032  				prog_name, relo_idx, insn_idx, insn->off, orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1033  			return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1034  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1035  		if (new_val > SHRT_MAX) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1036  			pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) value too big: %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1037  				prog_name, relo_idx, insn_idx, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1038  			return -ERANGE;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1039  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20 @1040  		if (res->fail_memsz_adjust) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1041  			pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) accesses field incorrectly. "
b0588390dbcedc Alexei Starovoitov 2021-07-20  1042  				"Make sure you are accessing pointers, unsigned integers, or fields of matching type and size.\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1043  				prog_name, relo_idx, insn_idx);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1044  			goto poison;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1045  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1046  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1047  		orig_val = insn->off;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1048  		insn->off = new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1049  		pr_debug("prog '%s': relo #%d: patched insn #%d (LDX/ST/STX) off %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1050  			 prog_name, relo_idx, insn_idx, orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1051  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1052  		if (res->new_sz != res->orig_sz) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1053  			int insn_bytes_sz, insn_bpf_sz;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1054  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1055  			insn_bytes_sz = insn_bpf_size_to_bytes(insn);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1056  			if (insn_bytes_sz != res->orig_sz) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1057  				pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) unexpected mem size: got %d, exp %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1058  					prog_name, relo_idx, insn_idx, insn_bytes_sz, res->orig_sz);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1059  				return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1060  			}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1061  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1062  			insn_bpf_sz = insn_bytes_to_bpf_size(res->new_sz);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1063  			if (insn_bpf_sz < 0) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1064  				pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) invalid new mem size: %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1065  					prog_name, relo_idx, insn_idx, res->new_sz);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1066  				return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1067  			}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1068  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1069  			insn->code = BPF_MODE(insn->code) | insn_bpf_sz | BPF_CLASS(insn->code);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1070  			pr_debug("prog '%s': relo #%d: patched insn #%d (LDX/ST/STX) mem_sz %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1071  				 prog_name, relo_idx, insn_idx, res->orig_sz, res->new_sz);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1072  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1073  		break;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1074  	case BPF_LD: {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1075  		__u64 imm;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1076  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1077  		if (!is_ldimm64_insn(insn) ||
b0588390dbcedc Alexei Starovoitov 2021-07-20  1078  		    insn[0].src_reg != 0 || insn[0].off != 0 ||
b0588390dbcedc Alexei Starovoitov 2021-07-20  1079  		    insn[1].code != 0 || insn[1].dst_reg != 0 ||
b0588390dbcedc Alexei Starovoitov 2021-07-20  1080  		    insn[1].src_reg != 0 || insn[1].off != 0) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1081  			pr_warn("prog '%s': relo #%d: insn #%d (LDIMM64) has unexpected form\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1082  				prog_name, relo_idx, insn_idx);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1083  			return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1084  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1085  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1086  		imm = insn[0].imm + ((__u64)insn[1].imm << 32);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1087  		if (res->validate && imm != orig_val) {
b0588390dbcedc Alexei Starovoitov 2021-07-20  1088  			pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, exp %u -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1089  				prog_name, relo_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1090  				insn_idx, (unsigned long long)imm,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1091  				orig_val, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1092  			return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1093  		}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1094  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1095  		insn[0].imm = new_val;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1096  		insn[1].imm = 0; /* currently only 32-bit values are supported */
b0588390dbcedc Alexei Starovoitov 2021-07-20  1097  		pr_debug("prog '%s': relo #%d: patched insn #%d (LDIMM64) imm64 %llu -> %u\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1098  			 prog_name, relo_idx, insn_idx,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1099  			 (unsigned long long)imm, new_val);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1100  		break;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1101  	}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1102  	default:
b0588390dbcedc Alexei Starovoitov 2021-07-20  1103  		pr_warn("prog '%s': relo #%d: trying to relocate unrecognized insn #%d, code:0x%x, src:0x%x, dst:0x%x, off:0x%x, imm:0x%x\n",
b0588390dbcedc Alexei Starovoitov 2021-07-20  1104  			prog_name, relo_idx, insn_idx, insn->code,
b0588390dbcedc Alexei Starovoitov 2021-07-20  1105  			insn->src_reg, insn->dst_reg, insn->off, insn->imm);
b0588390dbcedc Alexei Starovoitov 2021-07-20  1106  		return -EINVAL;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1107  	}
b0588390dbcedc Alexei Starovoitov 2021-07-20  1108  
b0588390dbcedc Alexei Starovoitov 2021-07-20  1109  	return 0;
b0588390dbcedc Alexei Starovoitov 2021-07-20  1110  }
b0588390dbcedc Alexei Starovoitov 2021-07-20  1111  

:::::: The code at line 1040 was first introduced by commit
:::::: b0588390dbcedcd74fab6ffb8afe8d52380fd8b6 libbpf: Split CO-RE logic into relo_core.c.

:::::: TO: Alexei Starovoitov <ast@kernel.org>
:::::: CC: Andrii Nakryiko <andrii@kernel.org>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 38483 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-01 19:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 19:25 [ast-bpf:relo_core 2/12] tools/lib/bpf/relo_core.c:1040:7: warning: Branch condition evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch] kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.