BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mykyta Yatsenko" <mykyta.yatsenko5@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next] libbpf: defer arena map size check to load time
Date: Tue, 08 Sep 2026 17:38:57 +0000	[thread overview]
Message-ID: <20260908173857.DE0621F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260908-libbpf_arena_thing-v1-1-0092c0e0d91b@meta.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] NULL pointer dereference in init_arena_map_data() when processing a SHT_NOBITS .arena section.
--

commit 839c80f912fa6d6c52eb18408dfd0437488f602b
Author: Mykyta Yatsenko <yatsenko@meta.com>

libbpf: defer arena map size check to load time

init_arena_map_data() used the build-host page size while it opened an
object. This could reject skeleton generation when the build host and
target use different page sizes.

> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index c036e8a91ed88..413b8b305194e 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c

[ ... ]

> @@ -3107,8 +3095,7 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict,
>  		obj->arena_map_idx = i;
>  
>  		if (obj->efile.arena_data) {
> -			err = init_arena_map_data(obj, map, ARENA_SEC, obj->efile.arena_data_shndx,
> -						  obj->efile.arena_data->d_buf,
> +			err = init_arena_map_data(obj, map, obj->efile.arena_data->d_buf,
>  						  obj->efile.arena_data->d_size);

[Severity: High]
This isn't a bug introduced by this patch, but can we pass a NULL pointer to
init_arena_map_data() here?

If the ELF section is of type SHT_NOBITS with a non-zero size, elf_getdata()
can return an Elf_Data structure where d_buf is NULL but d_size is non-zero.

In that case, bpf_object__init_user_btf_maps() passes a NULL data pointer
to init_arena_map_data(), which then executes:

tools/lib/bpf/libbpf.c:init_arena_map_data() {
    ...
	memcpy(obj->arena_data, data, data_sz);
    ...
}

leading to a NULL pointer dereference. Could we validate that d_buf is not
NULL before calling memcpy, or handle SHT_NOBITS sections differently?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908-libbpf_arena_thing-v1-1-0092c0e0d91b@meta.com?part=1

  reply	other threads:[~2026-09-08 17:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 17:25 [PATCH bpf-next] libbpf: defer arena map size check to load time Mykyta Yatsenko
2026-09-08 17:38 ` sashiko-bot [this message]
2026-09-08 18:07 ` bot+bpf-ci
2026-09-08 19:37 ` Emil Tsalapatis
2026-09-11 17:27   ` Andrii Nakryiko

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=20260908173857.DE0621F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=sashiko-reviews@lists.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