bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [POC][RFC][PATCH] bpf: in-kernel bpf relocations on raw elf files
@ 2025-01-09 21:43 Blaise Boscaccy
  2025-01-09 21:43 ` [PATCH 01/14] bpf: Port prerequiste BTF handling functions from userspace Blaise Boscaccy
                   ` (15 more replies)
  0 siblings, 16 replies; 30+ messages in thread
From: Blaise Boscaccy @ 2025-01-09 21:43 UTC (permalink / raw)
  To: bpf; +Cc: nkapron, teknoraver, roberto.sassu, gregkh, paul, code, flaniel


This is a proof-of-concept, based off of bpf-next-6.13. The
implementation will need additional work. The goal of this prototype was
to be able load raw elf object files directly into the kernel and have
the kernel perform all the necessary instruction rewriting and
relocation calculations. Having a file descriptor tied to a bpf program
allowed us to have tighter integration with the existing LSM
infrastructure. Additionally, it opens the door for signature and provenance
checking, along with loading programs without a functioning userspace.

The main goal of this RFC is to get some feedback on the overall
approach and feasibility of this design.

A new subcommand BPF_LOAD_FD is introduced. This subcommand takes a file
descriptor to an elf object file, along with an array of map fds, and a
sysfs entry to associate programs and metadata with. The kernel then
performs all the relocation calculations and instruction rewriting
inside the kernel. Later BPF_PROG_LOAD can reference this sysfs entry
and load/attach previously loaded programs by name. Userspace is
responsible for generating and populating maps.

CO-RE relocation support already existed in the kernel. Support for
everything else, maps, externs, etc., was added. In the same vein as
29db4bea1d10 ("bpf: Prepare relo_core.c for kernel duty.")
this prototype directly uses code from libbpf.

One of the challenges encountered was having different elf and btf
abstractions utilized in the kernel vs libpf. Missing btf functionality
was ported over to the kernel while trying to minimize the number of
changes required to the libpf code. As a result, there is some code
duplication and obvious refactoring opportunities. Additionally, being
able to directly share code between userspace and kernelspace in a
similar fashion to relo_core.c would be a TODO.

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2025-02-01 22:24 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-09 21:43 [POC][RFC][PATCH] bpf: in-kernel bpf relocations on raw elf files Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 01/14] bpf: Port prerequiste BTF handling functions from userspace Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 02/14] bpf: Add data structures for managing in-kernel eBPF relocations Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 03/14] bpf: Port .btf.ext parsing functions from userspace Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 04/14] bpf: Port elf and btf utility helper " Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 05/14] fs/kernel_read_file: Add an eBPF specifier to kernel_read_file Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 06/14] bpf: Add BPF_LOAD_FD subcommand Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 07/14] bpf: Implement BPF_LOAD_FD subcommand handler Blaise Boscaccy
2025-01-10  6:05   ` Greg KH
2025-01-10 22:41     ` Blaise Boscaccy
2025-01-11  0:41   ` kernel test robot
2025-01-09 21:43 ` [PATCH 08/14] bpf: Add elf parsing support to the BPF_LOAD_FD subcommand Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 09/14] bpf: Collect extern relocations Blaise Boscaccy
2025-01-11  1:35   ` kernel test robot
2025-01-09 21:43 ` [PATCH 10/14] bpf: Implement BTF fixup functionality Blaise Boscaccy
2025-01-11  3:19   ` kernel test robot
2025-01-09 21:43 ` [PATCH 11/14] bpf: Implement relocation collection Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 12/14] bpf: Resolve external relocations Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 13/14] bpf: Apply in-kernel bpf instruction relocations Blaise Boscaccy
2025-01-09 21:43 ` [PATCH 14/14] bpf: Augment BPF_PROG_LOAD to use in-kernel relocations Blaise Boscaccy
2025-01-10 18:40 ` [POC][RFC][PATCH] bpf: in-kernel bpf relocations on raw elf files Alexei Starovoitov
2025-01-10 23:27   ` Blaise Boscaccy
2025-01-13 17:54     ` Alexei Starovoitov
2025-01-14 18:24       ` Blaise Boscaccy
2025-01-24  5:08         ` bpf signing. " Alexei Starovoitov
2025-01-24  7:05           ` John Fastabend
2025-01-28 22:32             ` Blaise Boscaccy
2025-01-30  1:13 ` Cong Wang
2025-01-30 19:22   ` Blaise Boscaccy
2025-02-01 22:24     ` Cong Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).