bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Maguire <alan.maguire@oracle.com>
To: bot+bpf-ci@kernel.org, andrii@kernel.org, ast@kernel.org
Cc: daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com,
	song@kernel.org, yonghong.song@linux.dev,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, qmo@kernel.org,
	ihor.solodrai@linux.dev, dwarves@vger.kernel.org,
	bpf@vger.kernel.org, ttreyer@meta.com, martin.lau@kernel.org,
	clm@meta.com
Subject: Re: [PATCH v6 bpf-next 02/10] libbpf: Support kind layout section handling in BTF
Date: Thu, 11 Dec 2025 08:31:58 +0000	[thread overview]
Message-ID: <21ce7f3a-25c0-4f46-98ba-1d76a43e7935@oracle.com> (raw)
In-Reply-To: <aa32deb9e8e7ee4895f4884d375153f5fcf90b5b319e3f7052f4b14f47bb8504@mail.kernel.org>

On 10/12/2025 20:55, bot+bpf-ci@kernel.org wrote:
>> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
>> index b136572e889a..737adc560818 100644
>> --- a/tools/lib/bpf/btf.c
>> +++ b/tools/lib/bpf/btf.c
> 
> [ ... ]
> 
>> @@ -994,6 +1048,7 @@ void btf__free(struct btf *btf)
>>
>>  static struct btf *btf_new_empty(struct btf *base_btf)
>>  {
>> +	struct btf_header *hdr;
>>  	struct btf *btf;
>>
>>  	btf = calloc(1, sizeof(*btf));
>> @@ -1022,14 +1077,20 @@ static struct btf *btf_new_empty(struct btf *base_btf)
>>  		return ERR_PTR(-ENOMEM);
>>  	}
>>
>> -	btf->hdr = btf->raw_data;
>> -	btf->hdr->hdr_len = sizeof(struct btf_header);
>> -	btf->hdr->magic = BTF_MAGIC;
>> -	btf->hdr->version = BTF_VERSION;
>> +	hdr = btf->raw_data;
>> +	hdr->hdr_len = sizeof(struct btf_header);
>> +	hdr->magic = BTF_MAGIC;
>> +	hdr->version = BTF_VERSION;
>>
>> -	btf->types_data = btf->raw_data + btf->hdr->hdr_len;
>> -	btf->strs_data = btf->raw_data + btf->hdr->hdr_len;
>> -	btf->hdr->str_len = base_btf ? 0 : 1; /* empty string at offset 0 */
>> +	btf->types_data = btf->raw_data + hdr->hdr_len;
>> +	btf->strs_data = btf->raw_data + hdr->hdr_len;
>> +	hdr->str_len = base_btf ? 0 : 1; /* empty string at offset 0 */
>> +	btf->hdr = calloc(1, sizeof(struct btf_header));
>> +	if (!btf->hdr) {
>> +		free(btf);
>> +		return ERR_PTR(-ENOMEM);
>> +	}
>> +	memcpy(btf->hdr, hdr, sizeof(*hdr));
>>
>>  	return btf;
>>  }
> 
> Does this leak btf->raw_data when the btf->hdr allocation fails? The
> btf->raw_data was allocated earlier (at line 1074 in the new code), but
> if we reach the error path here, we only free(btf) without freeing
> btf->raw_data first.
>

Good catch; will fix. Additionally, elsewhere bot raises the issue of validation of
kind_layout_[len|off] in btf_parse_hdr(); we should add additional validation there
to ensure kind_layout_off is 4-byte aligned, points after the str section and does not
overrun the overall size. Will fix these in next round.

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


  reply	other threads:[~2025-12-11  8:32 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10 20:32 [PATCH v6 bpf-next 00/10] Add kind layout to BTF Alan Maguire
2025-12-10 20:32 ` [PATCH v6 bpf-next 01/10] btf: add kind layout encoding to UAPI Alan Maguire
2025-12-10 20:55   ` bot+bpf-ci
2025-12-13  2:52   ` Mykyta Yatsenko
2025-12-10 20:32 ` [PATCH v6 bpf-next 02/10] libbpf: Support kind layout section handling in BTF Alan Maguire
2025-12-10 20:55   ` bot+bpf-ci
2025-12-11  8:31     ` Alan Maguire [this message]
2025-12-13  3:37   ` Mykyta Yatsenko
2025-12-10 20:32 ` [PATCH v6 bpf-next 03/10] libbpf: use kind layout to compute an unknown kind size Alan Maguire
2025-12-10 20:55   ` bot+bpf-ci
2025-12-11  8:33     ` Alan Maguire
2025-12-13  3:51       ` Mykyta Yatsenko
2025-12-10 20:32 ` [PATCH v6 bpf-next 04/10] libbpf: Add kind layout encoding support Alan Maguire
2025-12-10 20:55   ` bot+bpf-ci
2025-12-11  8:36     ` Alan Maguire
2025-12-11 10:23       ` Alan Maguire
2025-12-10 20:32 ` [PATCH v6 bpf-next 05/10] libbpf: BTF validation can use kind layout for unknown kinds Alan Maguire
2025-12-10 20:55   ` bot+bpf-ci
2025-12-10 20:32 ` [PATCH v6 bpf-next 06/10] btf: support kernel parsing of BTF with kind layout Alan Maguire
2025-12-10 20:32 ` [PATCH v6 bpf-next 07/10] selftests/bpf: test kind encoding/decoding Alan Maguire
2025-12-10 20:55   ` bot+bpf-ci
2025-12-10 20:32 ` [PATCH v6 bpf-next 08/10] bpftool: add BTF dump "format meta" to dump header/metadata Alan Maguire
2025-12-10 20:55   ` bot+bpf-ci
2025-12-10 20:32 ` [PATCH v6 bpf-next 09/10] bpftool: Update doc to describe bpftool btf dump .. format metadata Alan Maguire
2025-12-10 20:32 ` [PATCH v6 bpf-next 10/10] kbuild, bpf: Specify "kind_layout" optional feature Alan Maguire

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21ce7f3a-25c0-4f46-98ba-1d76a43e7935@oracle.com \
    --to=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=dwarves@vger.kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=qmo@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=ttreyer@meta.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).