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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <d023c8bb-1053-46ca-9236-f7e1e6bee52f@linux.dev>
Date: Thu, 18 Dec 2025 17:37:13 -0800
From: Ihor Solodrai <ihor.solodrai@...ux.dev>
To: bot+bpf-ci@...nel.org, 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, martin.lau@...nel.org, clm@...a.com
Subject: Re: [PATCH bpf-next v5 8/8] resolve_btfids: Change in-place update
 with raw binary output

On 12/18/25 4:53 PM, bot+bpf-ci@...nel.org wrote:
>> 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?

I confirmed this is indeed a double free, although in a corner case.

I agree, we should set obj->btf and obj->btf_base to NULL at out_err.

Sending a v6 in a bit.

> 
> 
> ---
> 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

Powered by Openwall GNU/*/Linux Powered by OpenVZ