From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 11/21] libbpf: Size the tables of the loader program from the object
Date: Mon, 16 Nov 2026 06:20:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-216265@kernel.org> (raw)
In-Reply-To: <20261116055638.4171529-12-alexei.starovoitov@gmail.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 2 related pre-existing issues it does not
introduce:
- [Medium] libbpf: skeleton prog_fd corruption in
bpf_object__gen_loader() [1]
- [Medium] libbpf: unhandled copy error in bpf_gen__map_update_elem()
[2]
--
commit 90aed32e47532de6cf9729d6808a9ae7a545ec5c
Author: Alexei Starovoitov <ast@kernel.org>
libbpf: Size the tables of the loader program from the object
This commit sizes the loader program's fd_array and prog_fds tables from
the BPF object's counts instead of fixed maximum constants, moves prog_fds
from the loader stack into the data blob, and handles >16-bit offsets via
BPF_JMP32_A and a temporary context register.
> diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c
> index 555d4757a898c..27b4bc9e55acd 100644
> --- a/tools/lib/bpf/gen_loader.c
> +++ b/tools/lib/bpf/gen_loader.c
[ ... ]
> @@ -401,12 +386,12 @@ int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps)
> for (i = 0; i < gen->nr_func_ptr_maps; i++)
> emit_sys_close_blob(gen, blob_fd_array_off(gen, gen->nr_obj_maps + i));
> for (i = 0; i < gen->nr_progs; i++)
> - move_stack2ctx(gen,
> - sizeof(struct bpf_loader_ctx) +
> - sizeof(struct bpf_map_desc) * gen->nr_maps +
> - sizeof(struct bpf_prog_desc) * i +
> - offsetof(struct bpf_prog_desc, prog_fd), 4,
> - stack_off(prog_fd[i]));
> + move_blob2ctx(gen,
> + sizeof(struct bpf_loader_ctx) +
> + sizeof(struct bpf_map_desc) * gen->nr_maps +
> + sizeof(struct bpf_prog_desc) * i +
> + offsetof(struct bpf_prog_desc, prog_fd), 4,
> + blob_prog_fd_off(gen, i));
[Severity: Medium]
This problem wasn't introduced by this patch, but can a non-autoloaded
program (such as one marked with SEC("?...")) shift the prog_fd slots in
the loader context [1]?
bpf_object__load_progs() skips programs with !prog->autoload without
calling bpf_gen__prog_load(), so gen->nr_progs only counts loaded programs
while the generated light skeleton includes descriptors for all main
programs. Because bpf_gen__finish() only rejects nr_progs < gen->nr_progs
and then copies gen->nr_progs file descriptors sequentially starting at
index 0, any skipped program shifts subsequent prog_fd values into the
wrong skeleton slots.
[ ... ]
> @@ -1159,10 +1135,11 @@ void bpf_gen__prog_load(struct bpf_gen *gen,
> static void emit_copy_initial_value(struct bpf_gen *gen, int map_idx, int value,
> __u32 value_size, int nr_more_insns)
> {
> - emit(gen, BPF_LDX_MEM(BPF_DW, BPF_REG_3, BPF_REG_6,
> - sizeof(struct bpf_loader_ctx) +
> - sizeof(struct bpf_map_desc) * map_idx +
> - offsetof(struct bpf_map_desc, initial_value)));
> + int off = sizeof(struct bpf_loader_ctx) + sizeof(struct bpf_map_desc) * map_idx +
> + offsetof(struct bpf_map_desc, initial_value);
> + int ctx = emit_ctx_reg(gen, BPF_REG_3, &off);
> +
> + emit(gen, BPF_LDX_MEM(BPF_DW, BPF_REG_3, ctx, off));
> emit(gen, BPF_JMP_IMM(BPF_JEQ, BPF_REG_3, 0, 8 + nr_more_insns));
> emit2(gen, BPF_LD_IMM64_RAW_FULL(BPF_REG_1, BPF_PSEUDO_MAP_IDX_VALUE,
> 0, 0, 0, value));
[Severity: Medium]
This problem wasn't introduced by this patch, but should
emit_copy_initial_value() check the return value of BPF_FUNC_copy_from_user
and BPF_FUNC_probe_read_kernel [2]?
tools/lib/bpf/gen_loader.c:emit_copy_initial_value() {
...
emit(gen, BPF_EMIT_CALL(BPF_FUNC_copy_from_user));
emit(gen, BPF_JMP_IMM(BPF_JA, 0, 0, 1));
emit(gen, BPF_EMIT_CALL(BPF_FUNC_probe_read_kernel));
}
If copying initial_value fails at runtime, the error in BPF_REG_0 is
ignored and the loader proceeds to update or populate the map with stale
or uninitialized data from the value blob.
[1] https://sashiko.dev/#/bug/linux-2d41a5d8-8f8a-4d8a-830c-c6296f3d3c04
[2] https://sashiko.dev/#/bug/linux-fccc70c7-8ac5-4839-9aed-2cbf7835e292
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116055638.4171529-1-alexei.starovoitov@gmail.com?part=11
next prev parent reply other threads:[~2026-11-16 6:20 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 5:56 [PATCH bpf-next 00/21] bpf: Remove the limits on maps, kfuncs, subprogs and special fields Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 01/21] bpf: Stop a load only when the loader is killed or has to freeze Alexei Starovoitov
2026-11-16 6:39 ` bot+bpf-ci
2026-11-16 6:49 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 02/21] bpf: Fail the load when there is no memory Alexei Starovoitov
2026-11-16 6:29 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 03/21] bpf: Give a syscall program the largest context when it does tail calls Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 04/21] bpf: Do not inline bpf_loop() when its callback is dead code Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 05/21] bpf: Dump programs that have more than 524288 insns Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 06/21] bpf: Resolve BTF structs and arrays first Alexei Starovoitov
2026-11-16 6:13 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 07/21] bpf: Remove the limits on maps, BTFs and fd_array of a program Alexei Starovoitov
2026-11-16 6:39 ` bot+bpf-ci
2026-11-16 5:56 ` [PATCH bpf-next 08/21] bpf: Do not scan all maps for each insn and each subprog Alexei Starovoitov
2026-11-16 6:16 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 09/21] bpf: Remove the limits on kfuncs of a program Alexei Starovoitov
2026-11-16 6:39 ` bot+bpf-ci
2026-11-16 5:56 ` [PATCH bpf-next 10/21] bpf: Remove the limits on tables of functions Alexei Starovoitov
2026-11-16 6:14 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 11/21] libbpf: Size the tables of the loader program from the object Alexei Starovoitov
2026-11-16 6:20 ` sashiko-bot [this message]
2026-11-16 5:56 ` [PATCH bpf-next 12/21] bpf: Relax jumps that patches push out of range Alexei Starovoitov
2026-11-16 6:52 ` bot+bpf-ci
2026-11-16 5:56 ` [PATCH bpf-next 13/21] bpf: Keep the call graph in lists of edges Alexei Starovoitov
2026-11-16 6:39 ` sashiko-bot
2026-11-16 5:56 ` [PATCH bpf-next 14/21] bpf: Find the effects of callees on the call graph Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 15/21] bpf: Link the decl tags of a type Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 16/21] bpf: Remove BPF_MAX_SUBPROGS Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 17/21] bpf: Walk each type once when looking for special fields Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 18/21] bpf: Raise the limit on the length of BTF names Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 19/21] bpf: Find dominators in O(n log n) Alexei Starovoitov
2026-11-16 5:56 ` [PATCH bpf-next 20/21] selftests/bpf: Test programs above the old limits Alexei Starovoitov
2026-11-16 6:33 ` sashiko-bot
2026-11-16 6:39 ` bot+bpf-ci
2026-11-16 5:56 ` [PATCH bpf-next 21/21] selftests/bpf: Test limits of the load with raw programs Alexei Starovoitov
2026-11-16 6:39 ` sashiko-bot
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=sashiko-outbox-216265@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox