[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <e269870b8db409800045ee0061fc02d21721e0efadd99ca83960b48f8db7b3f3@mail.kernel.org>
Date: Fri, 19 Dec 2025 00:53:13 +0000 (UTC)
From: bot+bpf-ci@...nel.org
To: ihor.solodrai@...ux.dev,ast@...nel.org,daniel@...earbox.net,andrii@...nel.org,martin.lau@...ux.dev,eddyz87@...il.com,song@...nel.org,yonghong.song@...ux.dev,john.fastabend@...il.com,kpsingh@...nel.org,sdf@...ichev.me,haoluo@...gle.com,jolsa@...nel.org,akpm@...ux-foundation.org,nathan@...nel.org,nsc@...nel.org,corbet@....net,tj@...nel.org,void@...ifault.com,arighi@...dia.com,changwoo@...lia.com,shuah@...nel.org,nick.desaulniers+lkml@...il.com,morbo@...gle.com,justinstitt@...gle.com,alan.maguire@...cle.com,dolinux.peng@...il.com
Cc: bpf@...r.kernel.org,dwarves@...r.kernel.org,linux-kernel@...r.kernel.org,linux-kbuild@...r.kernel.org,sched-ext@...ts.linux.dev,ast@...nel.org,andrii@...nel.org,daniel@...earbox.net,martin.lau@...nel.org,eddyz87@...il.com,yonghong.song@...ux.dev,clm@...a.com,ihor.solodrai@...ux.dev
Subject: Re: [PATCH bpf-next v5 8/8] resolve_btfids: Change in-place update with raw binary output
> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> index e721e20a2bbd..7127396c5f50 100644
> --- a/tools/bpf/resolve_btfids/main.c
> +++ b/tools/bpf/resolve_btfids/main.c
[ ... ]
> @@ -587,6 +563,19 @@ static int load_btf(struct object *obj)
> obj->base_btf = base_btf;
> obj->btf = btf;
>
> + if (obj->base_btf && obj->distill_base) {
> + err = btf__distill_base(obj->btf, &base_btf, &btf);
> + if (err) {
> + pr_err("FAILED to distill base BTF: %s\n", strerror(errno));
> + goto out_err;
> + }
> +
> + btf__free(obj->btf);
> + btf__free(obj->base_btf);
> + obj->btf = btf;
> + obj->base_btf = base_btf;
> + }
> +
> return 0;
>
> out_err:
> + btf__free(base_btf);
> + btf__free(btf);
> return err;
> }
Can this lead to a double free if btf__distill_base() fails?
At the point of calling btf__distill_base(), the local variables base_btf
and btf have already been assigned to obj->base_btf and obj->btf. If
btf__distill_base() fails, it does not modify its output parameters, so
base_btf and btf still point to the same memory as obj->base_btf and
obj->btf.
The out_err path then frees base_btf and btf (the original BTF objects).
But obj->base_btf and obj->btf still point to this freed memory. When
load_btf() returns an error to main(), the cleanup at the out: label
calls btf__free(obj.base_btf) and btf__free(obj.btf), which would free
the same memory a second time.
The execution path would be:
main() -> load_btf() -> btf__distill_base() fails
-> out_err frees base_btf and btf
-> return err to main()
-> main() goto out
-> btf__free(obj.base_btf) and btf__free(obj.btf) -> double free
Perhaps the out_err path should set obj->base_btf = NULL and obj->btf =
NULL after freeing, or load_btf() should clear obj->base_btf/obj->btf
before going to out_err?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/20355860150
Powered by blists - more mailing lists