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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <202210280529.TNxdtFjQ-lkp@intel.com>
Date:   Fri, 28 Oct 2022 15:17:56 +0300
From:   Dan Carpenter <dan.carpenter@...cle.com>
To:     oe-kbuild@...ts.linux.dev, Wang Yufen <wangyufen@...wei.com>,
        bpf@...r.kernel.org, netdev@...r.kernel.org
Cc:     lkp@...el.com, 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,

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: openrisc-randconfig-m031-20221026
compiler: or1k-linux-gcc (GCC) 12.1.0

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

smatch warnings:
kernel/bpf/verifier.c:7021 prepare_func_exit() error: uninitialized symbol 'ret'.

vim +/ret +7021 kernel/bpf/verifier.c

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  	}

Not initialized on else path.

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  }

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ