From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 11/14] libbpf: Keep global data in arena when the object has .arena.data
Date: Wed, 30 Sep 2026 19:46:55 +0000 [thread overview]
Message-ID: <20260930194655.865701F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260930193127.2181684-12-alexei.starovoitov@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] libbpf: integer overflow in bpf_object__collect_data_ptr() allows heap corruption
- [Medium] libbpf: ARENA map bypasses pinning and reuse if data pointers exist
--
commit d23345bdc249c218c8d1f72cbc12d47c5a72bd22
Author: Alexei Starovoitov <ast@kernel.org>
libbpf: Keep global data in arena when the object has .arena.data
This commit introduces support for placing global data within an arena for
objects containing a .arena.data section. It appends .data, .bss, and .rodata
sections after __arena variables, converting relocations against these
sections into relocations against the arena map.
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
[ ... ]
> @@ -5736,6 +5954,10 @@ bpf_object__create_maps(struct bpf_object *obj)
> continue;
> }
>
> + /* see bpf_object__relocate_data_ptrs() */
> + if (map->def.type == BPF_MAP_TYPE_ARENA && obj->arena_mapped)
> + continue;
> +
[Severity: Medium]
Since bpf_object__relocate_data_ptrs() can create the ARENA map early and
set obj->arena_mapped to true, will this skip bypass the pinning and reuse
logic in bpf_object__reuse_map()?
If an application uses both data pointers and pinned ARENA maps, it appears
the map sharing might break because the early creation unconditionally skips
pin_path and reuse evaluations.
> err = map_set_def_max_entries(map);
> if (err)
> goto err_out;
[ ... ]
> @@ -8067,12 +8348,84 @@ static int bpf_object__collect_map_relos(struct bpf_object *obj,
[ ... ]
> +static int bpf_object__collect_data_ptr(struct bpf_object *obj, const char *relo_sec_name,
> + int relo_idx, size_t sec_idx, const Elf64_Rel *rel,
> + const Elf64_Sym *sym)
> +{
> + Elf_Data *scn_data = obj->efile.secs[sec_idx].data;
> + const char *sym_name = elf_sym_str(obj, sym->st_name) ?: "<?>";
> + struct data_ptr *ptrs;
> +
> + if (ELF64_ST_TYPE(sym->st_info) == STT_SECTION && sym->st_shndx < obj->efile.sec_cnt)
> + sym_name = elf_sec_name(obj, elf_sec_by_idx(obj, sym->st_shndx)) ?: "<?>";
> +
> + if (ELF64_R_TYPE(rel->r_info) != R_BPF_64_ABS64 ||
> + sym->st_shndx >= obj->efile.sec_cnt ||
> + (sym->st_shndx != obj->efile.arena_data_shndx &&
> + !bpf_object__shndx_is_data(obj, sym->st_shndx)) ||
> + rel->r_offset + sizeof(__u64) > scn_data->d_size) {
[Severity: High]
Could this bounds check overflow if rel->r_offset is maliciously large
(e.g., UINT64_MAX - 7)?
Since both operands are unsigned 64-bit integers, the addition might wrap
around to 0, which would incorrectly pass the > scn_data->d_size check.
If this check is bypassed, the overflowed offset is later used in
bpf_object__relocate_data_ptrs():
memcpy(&val, map->mmaped + p->sec_off, sizeof(val));
val += addr;
memcpy(map->mmaped + p->sec_off, &val, sizeof(val));
Can this lead to an out-of-bounds read and write against map->mmaped,
potentially corrupting heap metadata in the process parsing the object?
> + pr_warn("sec '%s': relo #%d: can't resolve pointer to '%s' at offset %zu when data is in arena\n",
> + relo_sec_name, relo_idx, sym_name, (size_t)rel->r_offset);
> + return -LIBBPF_ERRNO__RELOC;
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260930193127.2181684-1-alexei.starovoitov@gmail.com?part=11
next prev parent reply other threads:[~2026-09-30 19:46 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 19:31 [PATCH bpf-next 00/14] bpf: Support programs compiled by rust-bpf Alexei Starovoitov
2026-09-30 19:31 ` [PATCH bpf-next 01/14] bpf: Allow bitwise ops, shifts and mul/div on pointers with CAP_PERFMON Alexei Starovoitov
2026-09-30 19:31 ` [PATCH bpf-next 02/14] selftests/bpf: Add tests for ALU " Alexei Starovoitov
2026-09-30 19:31 ` [PATCH bpf-next 03/14] bpf: Treat load and store through a number as arena access Alexei Starovoitov
2026-09-30 19:31 ` [PATCH bpf-next 04/14] selftests/bpf: Add tests for arena access through numbers Alexei Starovoitov
2026-09-30 19:48 ` sashiko-bot
2026-09-30 20:22 ` bot+bpf-ci
2026-09-30 19:31 ` [PATCH bpf-next 05/14] bpf: Allow names of Rust types and functions in BTF Alexei Starovoitov
2026-09-30 20:22 ` bot+bpf-ci
2026-10-01 17:42 ` Alan Maguire
2026-10-02 12:24 ` Alexei Starovoitov
2026-10-02 13:38 ` Alan Maguire
2026-09-30 19:31 ` [PATCH bpf-next 06/14] selftests/bpf: Add tests for " Alexei Starovoitov
2026-09-30 20:22 ` bot+bpf-ci
2026-09-30 19:31 ` [PATCH bpf-next 07/14] bpf: Allow arguments without names in static " Alexei Starovoitov
2026-10-01 21:14 ` Alan Maguire
2026-09-30 19:31 ` [PATCH bpf-next 08/14] selftests/bpf: Add test for arguments without names in static functions Alexei Starovoitov
2026-10-01 21:22 ` Alan Maguire
2026-09-30 19:31 ` [PATCH bpf-next 09/14] bpf: Allow a variable in DATASEC that is smaller than its type Alexei Starovoitov
2026-09-30 19:47 ` sashiko-bot
2026-09-30 19:31 ` [PATCH bpf-next 10/14] selftests/bpf: Add tests for a variable " Alexei Starovoitov
2026-09-30 19:31 ` [PATCH bpf-next 11/14] libbpf: Keep global data in arena when the object has .arena.data Alexei Starovoitov
2026-09-30 19:46 ` sashiko-bot [this message]
2026-09-30 20:22 ` bot+bpf-ci
2026-09-30 19:31 ` [PATCH bpf-next 12/14] libbpf: Keep format strings of bpf_printk() in .rodata.str Alexei Starovoitov
2026-09-30 20:22 ` bot+bpf-ci
2026-09-30 19:31 ` [PATCH bpf-next 13/14] selftests/bpf: Add test for global data in arena Alexei Starovoitov
2026-09-30 20:22 ` bot+bpf-ci
2026-09-30 19:31 ` [PATCH bpf-next 14/14] selftests/bpf: Add test for global data of a program in Rust Alexei Starovoitov
2026-09-30 19:53 ` sashiko-bot
2026-09-30 20:22 ` bot+bpf-ci
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=20260930194655.865701F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.