This is a note to let you know that I've just added the patch titled bpf: Add missing btf_put to register_btf_id_dtor_kfuncs to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: bpf-add-missing-btf_put-to-register_btf_id_dtor_kfun.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit e979ec2158d753a572e5ee08b826b39d9896e306 Author: Jiri Olsa <jolsa@xxxxxxxxxx> Date: Fri Jan 20 13:21:48 2023 +0100 bpf: Add missing btf_put to register_btf_id_dtor_kfuncs [ Upstream commit 74bc3a5acc82f020d2e126f56c535d02d1e74e37 ] We take the BTF reference before we register dtors and we need to put it back when it's done. We probably won't se a problem with kernel BTF, but module BTF would stay loaded (because of the extra ref) even when its module is removed. Cc: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> Fixes: 5ce937d613a4 ("bpf: Populate pairs of btf_id and destructor kfunc in btf") Acked-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> Link: https://lore.kernel.org/r/20230120122148.1522359-1-jolsa@xxxxxxxxxx Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index efdbba2a0230..a7c2f0c3fc19 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -7607,9 +7607,9 @@ int register_btf_id_dtor_kfuncs(const struct btf_id_dtor_kfunc *dtors, u32 add_c sort(tab->dtors, tab->cnt, sizeof(tab->dtors[0]), btf_id_cmp_func, NULL); - return 0; end: - btf_free_dtor_kfunc_tab(btf); + if (ret) + btf_free_dtor_kfunc_tab(btf); btf_put(btf); return ret; }