Skip to contentSkip to conversation

kernel/bpf/verifier.c:19778 check_attach_btf_id() error: 'tr' dereferencing possible ERR_PTR()

PATCH New Dan Carpenter 1 participant 1 message Sep 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 4799/4965 kernel/bpf/verifier.c:19778 check_attach_btf_id() error: 'tr' dereferencing possible ERR_PTR()

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   e143016b56ecb0fcda5bb6026b0a25fe55274f56
commit: 2b5dcb31a19a2e0acd869b12c9db9b2d696ef544 [4799/4965] bpf, x64: Fix tailcall infinite loop
config: i386-randconfig-141-20230913 (https://download.01.org/0day-ci/archive/20230913/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230913/[email protected]/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 <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
kernel/bpf/verifier.c:19778 check_attach_btf_id() error: 'tr' dereferencing possible ERR_PTR()

vim +/tr +19778 kernel/bpf/verifier.c

f1b9509c2fb0ef Alexei Starovoitov 2019-10-30 19770 }
f7b12b6fea0098 Toke Høiland-Jørgensen 2020-09-25 19771
22dc4a0f5ed11b Andrii Nakryiko 2020-12-03 19772 key = bpf_trampoline_compute_key(tgt_prog, prog->aux->attach_btf, btf_id);

f7b12b6fea0098 Toke Høiland-Jørgensen 2020-09-25  19773  	tr = bpf_trampoline_get(key, &tgt_info);
f7b12b6fea0098 Toke Høiland-Jørgensen 2020-09-25  19774  	if (!tr)

bpf_trampoline_get() returns error pointers if CONFIG_BPF_JIT is turned off. We should make either return NULL in that case, or change CONFIG_BPF_SYSCALL to depend on or select CONFIG_BPF_JIT. Probably we should do both honestly.

Normally when functions return a mix of error pointers and NULL the error pointer means error and the NULL means the feature is disabled. This code does is the reverse way.

f7b12b6fea0098 Toke Høiland-Jørgensen 2020-09-25 19775 return -ENOMEM;
f7b12b6fea0098 Toke Høiland-Jørgensen 2020-09-25 19776

2b5dcb31a19a2e Leon Hwang             2023-09-12  19777  	if (tgt_prog && tgt_prog->aux->tail_call_reachable)
2b5dcb31a19a2e Leon Hwang             2023-09-12 @19778  		tr->flags = BPF_TRAMP_F_TAIL_CALL_CTX;
2b5dcb31a19a2e Leon Hwang             2023-09-12  19779  
3aac1ead5eb6b7 Toke Høiland-Jørgensen 2020-09-29  19780  	prog->aux->dst_trampoline = tr;
f7b12b6fea0098 Toke Høiland-Jørgensen 2020-09-25  19781  	return 0;

38207291604401 Martin KaFai Lau 2019-10-24 19782 }

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki