]> git.ipfire.org Git - thirdparty/linux.git/commit
bpf: Set sub->arg_cnt earlier in btf_prepare_func_args()
authorYonghong Song <yonghong.song@linux.dev>
Wed, 13 May 2026 04:50:10 +0000 (21:50 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 13 May 2026 16:27:30 +0000 (09:27 -0700)
commit3ab5bd317ee280b198b00ea2114adaad7a458ef8
treeb84ed039e66bf09cd493895c46ce2258152db0d1
parent78bbe61632f11b1091c03259f92b6559489222ae
bpf: Set sub->arg_cnt earlier in btf_prepare_func_args()

Move the "sub->arg_cnt = nargs" assignment to immediately after
nargs is computed from btf_type_vlen(), instead of at the end of
btf_prepare_func_args().

btf_prepare_func_args() can return -EINVAL early in several cases,
e.g. when a static function has some non-int/enum arguments.
Since -EINVAL from btf_prepare_func_args() does not immediately
reject verification, arg_cnt remains zero after the early return.
This causes later stack argument based load/store insns to
incorrectly assume the function has no arguments.

Setting arg_cnt right after nargs ensures it is available regardless
of which path btf_prepare_func_args() takes.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20260513045010.2384635-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/btf.c