[PATCH bpf-next v3 0/5] libbpf: Support gen loader attach

From: Mahe Tardy

Date: Mon Nov 02 2026 - 15:14:20 EST


Hey,

I've been working on this in the context of Shirudo[^1]. The current
limitations we face is that gen_loader cannot attach the program it
loads so we still need a userspace component to be allowed to
BPF_LINK_CREATE and we'd like to gradually remove the allowed operations
done in userspace to solely rely on the signed program.

Note that there's no kernel modification in this series, it adds the
gen_attach options and code generation to libbpf and do the wiring from
bpftool. The kernel side was already allowed thanks to 'b1d18a7574d0
("bpf: Extend sys_bpf commands for bpf_syscall programs.")'.

Also note that I did some analyzis with Sashiko and it's been
complaining because I've followed the approach with the prog fds being
initialized to 0 (and not fixing the two fds to init to -1 sentinel
value), so maybe we should pre-patch this.

Lastly, I don't know much about bpftool so unsure if the way I've added
it is the most appropriate way for the lskel attach option.

v3 updates:
- rebased again because I had a debug commit in between master and my
patches that somehow surprisingly conflicted... sorry for the spam!

v2 updates:
- rebased to includes changes from the 'libbpf: BPF program manual
loading'[^2] patch series that conflicts with that series.

[^1]: https://lpc.events/event/20/contributions/2437/
[^2]: https://lore.kernel.org/bpf/20261029223348.3730738-1-andrey.grodzovsky@xxxxxxxxxxxxxxx/

Mahe Tardy (5):
libbpf: Count entry programs for bpf_gen__init()
libbpf: Track generated loader link FDs
libbpf: Emit BPF_LINK_CREATE calls in generated loaders
bpftool: Add attach option for light skeleton generation
selftests/bpf: Test gen loader attach

.../bpf/bpftool/Documentation/bpftool-gen.rst | 11 +-
tools/bpf/bpftool/bash-completion/bpftool | 2 +-
tools/bpf/bpftool/gen.c | 67 +++--
tools/lib/bpf/bpf_gen_internal.h | 7 +
tools/lib/bpf/gen_loader.c | 41 +++-
tools/lib/bpf/libbpf.c | 55 ++++-
tools/lib/bpf/libbpf.h | 3 +-
tools/lib/bpf/skel_internal.h | 4 +
.../bpf/prog_tests/gen_loader_attach.c | 229 ++++++++++++++++++
.../selftests/bpf/progs/gen_loader_attach.c | 48 ++++
10 files changed, 435 insertions(+), 32 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/gen_loader_attach.c
create mode 100644 tools/testing/selftests/bpf/progs/gen_loader_attach.c

--
2.43.0