BPF List
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Roman Gushchin" <roman.gushchin@linux.dev>
Cc: <sashiko-reviews@lists.linux.dev>, <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v3 06/14] libbpf: Relocate pointers that are stored in arena
Date: Wed, 04 Nov 2026 02:37:07 +0000	[thread overview]
Message-ID: <DMM2SGQ43OOJ.1QYUMNEVN2LIQ@gmail.com> (raw)
In-Reply-To: <EB1C0109-74FC-4DFC-A25D-DB11BD62EC97@linux.dev>

On Wed Nov 4, 2026 at 2:32 AM UTC, Roman Gushchin wrote:
>> On Nov 3, 2026, at 6:02 PM, Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
>> 
>> On Tue, Nov 03, 2026 at 05:44 PM sashiko-bot@kernel.org <sashiko-bot@kernel.org> wrote:
>>>> +    ptrs = libbpf_reallocarray(NULL, nrels, sizeof(*ptrs));
>>>> +    if (!ptrs)
>>>> +        return -ENOMEM;
>>>> +    obj->arena_ptrs = ptrs;
>> 
>> [...]
>> 
>>> 1. If multiple SEC_RELO sections target arena_data_shndx, the second call
>>> overwrites obj->arena_ptrs (leaking the prior allocation) and allocates only
>>> nrels entries, while obj->arena_ptr_cnt holds the sum across both calls. When
>>> bpf_object__create_maps() -> relocate_arena_ptrs() later runs:
>> 
>> Not a bug. Only a hand-made ELF has two SHT_REL sections for one section.
>> clang emits one for .addr_space.1, and the static linker merges them by
>> name in linker_append_elf_relos().
>> 
>>> 2. If an empty .rel.addr_space.1 section has sh_size == 0 (nrels == 0),
>>> libbpf_reallocarray(NULL, 0, sizeof(*ptrs)) calls realloc(NULL, 0), which may
>>> return NULL and cause bpf_object__collect_arena_relos() to return -ENOMEM.
>> 
>> No. Nothing emits an empty SHT_REL section.
>> glibc returns a pointer for realloc(NULL, 0). Where it's NULL the open of
>> such a file fails, and that's fine.
>> 
>> I'm replying to a bot hoping that Roman will teach it to learn from maintainers
>> and stop reporting such bugs in libbpf where input is trusted.
>
> Thanks, well appreciated!
> It’s going into that direction, now at least it should not raise it again in next versions.

Thank you!

  reply	other threads:[~2026-11-04  2:37 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04  1:23 [PATCH bpf-next v3 00/14] bpf: A stack in arena Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 01/14] libbpf: Make arena 4 Gbyte when max_entries is not set Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 02/14] selftests/bpf: Test the default size of arena Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 03/14] bpf: Treat addr_space_cast of a pointer that is not in arena as a move Alexei Starovoitov
2026-11-04  2:12   ` bot+bpf-ci
2026-11-04  2:32     ` Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 04/14] selftests/bpf: Test addr_space_cast of pointers that are not in arena Alexei Starovoitov
2026-11-04  1:40   ` sashiko-bot
2026-11-04  1:23 ` [PATCH bpf-next v3 05/14] libbpf: Support .bss.addr_space.1 section Alexei Starovoitov
2026-11-04  1:59   ` bot+bpf-ci
2026-11-04  1:23 ` [PATCH bpf-next v3 06/14] libbpf: Relocate pointers that are stored in arena Alexei Starovoitov
2026-11-04  1:44   ` sashiko-bot
2026-11-04  2:02     ` Alexei Starovoitov
2026-11-04  2:32       ` Roman Gushchin
2026-11-04  2:37         ` Alexei Starovoitov [this message]
2026-11-04  1:59   ` bot+bpf-ci
2026-11-04  2:30     ` Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 07/14] selftests/bpf: Test pointers in arena and .bss.addr_space.1 Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 08/14] bpf: Introduce bpf register BPF_REG_ARENA_SP Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 09/14] bpf: Add stacks for programs to arena Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 10/14] bpf, x86: Add BPF_ATOMIC_LOCAL Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 11/14] bpf: Support BPF_REG_ARENA_SP in the verifier Alexei Starovoitov
2026-11-04  2:12   ` bot+bpf-ci
2026-11-04  1:23 ` [PATCH bpf-next v3 12/14] bpf, x86: Support BPF_REG_ARENA_SP Alexei Starovoitov
2026-11-04  1:23 ` [PATCH bpf-next v3 13/14] bpf, arm64: " Alexei Starovoitov
2026-11-04  1:24 ` [PATCH bpf-next v3 14/14] selftests/bpf: Add tests for BPF_REG_ARENA_SP Alexei Starovoitov
2026-11-04  2:12   ` bot+bpf-ci
2026-11-04  2:29     ` Alexei Starovoitov
2026-11-04  3:31 ` [PATCH bpf-next v3 00/14] bpf: A stack in arena Alexei Starovoitov
2026-11-04  7:35   ` Kumar Kartikeya Dwivedi
2026-11-04 18:02     ` Alexei Starovoitov
2026-11-04 20:10 ` patchwork-bot+netdevbpf

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=DMM2SGQ43OOJ.1QYUMNEVN2LIQ@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=roman.gushchin@linux.dev \
    --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