lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 28 Oct 2022 01:15:43 +0800
From:   kernel test robot <lkp@...el.com>
To:     Wang Yufen <wangyufen@...wei.com>, bpf@...r.kernel.org,
        netdev@...r.kernel.org
Cc:     llvm@...ts.linux.dev, oe-kbuild-all@...ts.linux.dev,
        ast@...nel.org, daniel@...earbox.net, john.fastabend@...il.com,
        andrii@...nel.org, martin.lau@...ux.dev, yhs@...com,
        joe@...d.net.nz
Subject: Re: [PATCH net] bpf: Fix memory leaks in __check_func_call

Hi Wang,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on net/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Wang-Yufen/bpf-Fix-memory-leaks-in-__check_func_call/20221027-180438
patch link:    https://lore.kernel.org/r/1666866213-4394-1-git-send-email-wangyufen%40huawei.com
patch subject: [PATCH net] bpf: Fix memory leaks in __check_func_call
config: i386-randconfig-a013
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
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://github.com/intel-lab-lkp/linux/commit/7e03dd8c129a0dbd7c32fb0931ad52e2c9a52f55
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Wang-Yufen/bpf-Fix-memory-leaks-in-__check_func_call/20221027-180438
        git checkout 7e03dd8c129a0dbd7c32fb0931ad52e2c9a52f55
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash kernel/bpf/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@...el.com>

All warnings (new ones prefixed by >>):

>> kernel/bpf/verifier.c:7003:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
           if (!callee->in_callback_fn) {
               ^~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/verifier.c:7021:9: note: uninitialized use occurs here
           return ret;
                  ^~~
   kernel/bpf/verifier.c:7003:2: note: remove the 'if' if its condition is always true
           if (!callee->in_callback_fn) {
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/verifier.c:6962:9: note: initialize the variable 'ret' to silence this warning
           int ret;
                  ^
                   = 0
   1 warning generated.


vim +7003 kernel/bpf/verifier.c

20571567384428 David Vernet            2022-09-19  6956  
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6957  static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6958  {
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6959  	struct bpf_verifier_state *state = env->cur_state;
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6960  	struct bpf_func_state *caller, *callee;
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6961  	struct bpf_reg_state *r0;
7e03dd8c129a0d Wang Yufen              2022-10-27  6962  	int ret;
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6963  
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6964  	callee = state->frame[state->curframe];
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6965  	r0 = &callee->regs[BPF_REG_0];
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6966  	if (r0->type == PTR_TO_STACK) {
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6967  		/* technically it's ok to return caller's stack pointer
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6968  		 * (or caller's caller's pointer) back to the caller,
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6969  		 * since these pointers are valid. Only current stack
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6970  		 * pointer will be invalid as soon as function exits,
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6971  		 * but let's be conservative
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6972  		 */
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6973  		verbose(env, "cannot return stack pointer to the caller\n");
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6974  		return -EINVAL;
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6975  	}
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6976  
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6977  	state->curframe--;
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6978  	caller = state->frame[state->curframe];
69c087ba6225b5 Yonghong Song           2021-02-26  6979  	if (callee->in_callback_fn) {
69c087ba6225b5 Yonghong Song           2021-02-26  6980  		/* enforce R0 return value range [0, 1]. */
1bfe26fb082724 Dave Marchevsky         2022-09-08  6981  		struct tnum range = callee->callback_ret_range;
69c087ba6225b5 Yonghong Song           2021-02-26  6982  
69c087ba6225b5 Yonghong Song           2021-02-26  6983  		if (r0->type != SCALAR_VALUE) {
69c087ba6225b5 Yonghong Song           2021-02-26  6984  			verbose(env, "R0 not a scalar value\n");
7e03dd8c129a0d Wang Yufen              2022-10-27  6985  			ret = -EACCES;
7e03dd8c129a0d Wang Yufen              2022-10-27  6986  			goto out;
69c087ba6225b5 Yonghong Song           2021-02-26  6987  		}
69c087ba6225b5 Yonghong Song           2021-02-26  6988  		if (!tnum_in(range, r0->var_off)) {
69c087ba6225b5 Yonghong Song           2021-02-26  6989  			verbose_invalid_scalar(env, r0, &range, "callback return", "R0");
7e03dd8c129a0d Wang Yufen              2022-10-27  6990  			ret = -EINVAL;
7e03dd8c129a0d Wang Yufen              2022-10-27  6991  			goto out;
69c087ba6225b5 Yonghong Song           2021-02-26  6992  		}
69c087ba6225b5 Yonghong Song           2021-02-26  6993  	} else {
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6994  		/* return to the caller whatever r0 had in the callee */
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6995  		caller->regs[BPF_REG_0] = *r0;
69c087ba6225b5 Yonghong Song           2021-02-26  6996  	}
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  6997  
9d9d00ac29d0ef Kumar Kartikeya Dwivedi 2022-08-23  6998  	/* callback_fn frame should have released its own additions to parent's
9d9d00ac29d0ef Kumar Kartikeya Dwivedi 2022-08-23  6999  	 * reference state at this point, or check_reference_leak would
9d9d00ac29d0ef Kumar Kartikeya Dwivedi 2022-08-23  7000  	 * complain, hence it must be the same as the caller. There is no need
9d9d00ac29d0ef Kumar Kartikeya Dwivedi 2022-08-23  7001  	 * to copy it back.
9d9d00ac29d0ef Kumar Kartikeya Dwivedi 2022-08-23  7002  	 */
9d9d00ac29d0ef Kumar Kartikeya Dwivedi 2022-08-23 @7003  	if (!callee->in_callback_fn) {
fd978bf7fd3125 Joe Stringer            2018-10-02  7004  		/* Transfer references to the caller */
7e03dd8c129a0d Wang Yufen              2022-10-27  7005  		ret = copy_reference_state(caller, callee);
7e03dd8c129a0d Wang Yufen              2022-10-27  7006  		if (ret)
7e03dd8c129a0d Wang Yufen              2022-10-27  7007  			goto out;
9d9d00ac29d0ef Kumar Kartikeya Dwivedi 2022-08-23  7008  	}
fd978bf7fd3125 Joe Stringer            2018-10-02  7009  
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  7010  	*insn_idx = callee->callsite + 1;
06ee7115b0d174 Alexei Starovoitov      2019-04-01  7011  	if (env->log.level & BPF_LOG_LEVEL) {
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  7012  		verbose(env, "returning from callee:\n");
0f55f9ed21f966 Christy Lee             2021-12-16  7013  		print_verifier_state(env, callee, true);
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  7014  		verbose(env, "to caller at %d:\n", *insn_idx);
0f55f9ed21f966 Christy Lee             2021-12-16  7015  		print_verifier_state(env, caller, true);
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  7016  	}
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  7017  	/* clear everything in the callee */
7e03dd8c129a0d Wang Yufen              2022-10-27  7018  out:
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  7019  	free_func_state(callee);
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  7020  	state->frame[state->curframe + 1] = NULL;
7e03dd8c129a0d Wang Yufen              2022-10-27  7021  	return ret;
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  7022  }
f4d7e40a5b7157 Alexei Starovoitov      2017-12-14  7023  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

View attachment "config" of type "text/plain" (155696 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ