Skip to content

Commit 5a8cd53

Browse files
committed
Merge tag 'bpf-next-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Pull bpf updates from Daniel Borkmann: "Major changes: - Redesign the verifier error reporting: failures now carry source and instruction annotations along with the causal event history that led to them, making program rejections far easier to debug and repair (Kumar Kartikeya Dwivedi) - Add arena argument support to kfuncs and struct_ops through the new __arena and __arena__nullable suffixes (Tejun Heo, Puranjay Mohan, Kumar Kartikeya Dwivedi, Ihor Solodrai) - Signed BPF program loader rework to accommodate both BPF and security community needs where the kernel runs the signature verification at BPF_PROG_LOAD time before the LSM admission hook (Daniel Borkmann) - Add a set of ksock kfuncs which let BPF LSM and syscall programs create, connect and send on UDP sockets in order to emit telemetry data (Mahe Tardy) - Unify helper and kfunc call argument verification and classify kfunc arguments purely from BTF into a generated bpf_func_proto which is computed once at add-call time (Amery Hung) Other features and fixes: - Enable EXECMEM_ROX_CACHE for BPF allocations on x86 (Mike Rapoport) - Add bidirectional VLAN support to bpf_fib_lookup() through the new BPF_FIB_LOOKUP_VLAN and BPF_FIB_LOOKUP_VLAN_INPUT flags (Avinash Duduskar) - Infer zext_dst from static register liveness analysis to fix 32-bit zero-extension semantics, and remove the artificial limitations on pointer types eligible for spilling (Eduard Zingerman) - Inline the numeric open-coded iterator kfuncs so that bpf_for() loops no longer pay a kfunc call on every iteration (Puranjay Mohan) - Add an arena-based bitmap data structure to libarena along with serial and parallel selftests (Emil Tsalapatis) - Teach resolve_btfids to discover kfuncs from the kernel's BTF ID sets and to emit kfunc BTF decl tags, reducing the kernel build's dependency on pahole features (Ihor Solodrai) - Add BPF_F_ADJ_ROOM_DECAP_* flags to bpf_skb_adjust_room() so that tunnel decapsulation can update the GSO and encapsulation state of the skb (Nick Hudson) - Fix the ring buffer pending_pos walk and the available-data accounting on 32-bit position wrap (Israel Téllez García) - Add memory usage accounting for arena maps and fix an mmap_lock deadlock on arena lock failure (Jiayuan Chen) - Add tracing_multi link info support to the kernel UAPI and bpftool, and refactor the stack map code to run with preemption disabled (Jiri Olsa) - Support BPF_F_EGRESS in bpf_redirect_peer() to emit the skb in the egress direction of the target's peer device (Jordan Rife) - Add a KF_SPINLOCK_SAFE kfunc flag so that providers, in particular modules, can declare kfuncs safe to call under bpf_spin_lock instead of relying on the verifier's hard-coded allowlist (Kaitao Cheng) - Introduce global percpu data for BPF programs with libbpf probing and bpftool skeleton support, and stop exposing uninitialized kernel heap memory when copying per-CPU map values (Leon Hwang) - Add s390 JIT support for load-acquire and store-release instructions (Maxim Khmelevskii) - Fix a CFI mismatch in the task work callback and an arm64 KASAN false positive after bpf_throw() (Mykyta Yatsenko) - Reject writes through untrusted BTF pointers and bound the rdonly/rdwr_buf_size kfunc arguments (Nicholas Dudar) - Invalidate RCU pointers only after the final spin unlock and account for preempt and IRQ disabled regions as overlapping RCU protection (Ning Ding) - Support mixing bpf2bpf calls and tail calls on RV64, add signed operations and 32-bit atomics to the RV32 JIT, and add timed may_goto support (Pu Lehui, Kuan-Wei Chiu, Feng Jiang) - Fix a use-after-free on mm_struct in bpf_find_vma() for foreign tasks and an mmap_lock leak in the irq_work path (Sanghyun Park) - Populate mmap-able BPF array map memory lazily which makes mmap() O(1) instead of proportional to the map size (Song Liu) - Introduce a jit_required flag and reject programs with inlined helpers when no JIT is available, where the interpreter would otherwise jump into an invalid address (Tiezhu Yang) - Fix the x86 JIT per-CPU address resolution into an extended register where the REX prefix dropped the high destination register bit (Vineet Gupta) - Reject MEM_ALLOC BTF accesses past object bounds, arena frees below the arena base, and mixed arena and ordinary atomic paths (Yiyang Chen) - Fix the trampoline handling of 128-bit arguments and of return values larger than 8 bytes (Yonghong Song) - Ensure that any fault prone load is rewritten with exception table handling, and fix the arena load-acquire and atomic fetch handling in the x86, arm64, riscv and s390 JITs (Daniel Borkmann) - Many more fixes and cleanups across the verifier, arena, trampolines, sockmap, cgroup, ring buffer, x86/arm64/riscv/s390 JITs, libbpf, bpftool, resolve_btfids and selftests" * tag 'bpf-next-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (373 commits) selftests/bpf: Add tests for a store on a fault prone qdisc pointer selftests/bpf: Add tests for fault prone loads out of RCU pointers selftests/bpf: Add tests for pointer type merge at a shared load selftests/bpf: Remove duplicate copies of the arena spinlock qnodes selftests/bpf: Retry stat generation in cgroup_iter_memcg selftests/bpf: Test pseudo-function policy diagnostics bpf: Distinguish function references in policy diagnostics bpf: Preserve source attribution without source text selftests/bpf: Test kfunc argument diagnostics bpf: Correct kfunc argument diagnostics bpf: Use canonical stack argument names in diagnostics bpf: Preserve R0 lineage across helper calls selftests/bpf: Exercise negative optlen in cgroup getsockopt hook bpf: Reject negative optlen in cgroup getsockopt hook selftests/bpf: tc_tunnel - validate decap GSO and encapsulation state bpf: Clear decap state on skb_adjust_room shrink path bpf: Allow new DECAP flags and add guard rails bpf: Add BPF_F_ADJ_ROOM_DECAP_* flags for tunnel decapsulation bpf: Refactor masks for ADJ_ROOM flags and encap validation bpf: Name the enum for BPF_FUNC_skb_adjust_room flags ...
2 parents a4ff2be + f79066c commit 5a8cd53

272 files changed

Lines changed: 18968 additions & 3417 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/bpf/bpf_devel_QA.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,10 @@ for details.
479479

480480
To maximize the number of tests passing, the .config of the kernel
481481
under test should match the config file fragment in
482-
tools/testing/selftests/bpf as closely as possible.
482+
tools/testing/selftests/bpf as closely as possible. If not possible,
483+
however, you can set ``BPF_STRICT_BUILD=0`` when invoking ``make``
484+
to tolerate individual compilation failures and continue building
485+
the remaining tests rather than treating each failure as fatal.
483486

484487
Finally to ensure support for latest BPF Type Format features -
485488
discussed in Documentation/bpf/btf.rst - pahole version 1.16

Documentation/bpf/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ that goes into great technical depth about the BPF Architecture.
2828
classic_vs_extended.rst
2929
bpf_iterators
3030
bpf_licensing
31+
signing
3132
test_debug
3233
clang-notes
3334
linux-notes

Documentation/bpf/kfuncs.rst

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,71 @@ Or::
250250
...
251251
}
252252

253+
2.3.7 __const_map and __map Annotations
254+
---------------------------------------
255+
256+
These annotations are used for ``struct bpf_map *`` arguments and distinguish a
257+
verifier-known map from an opaque one.
258+
259+
``__const_map`` indicates a map must be known at the verification time, i.e. a
260+
concrete map fd the BPF program references directly.
261+
262+
An example is given below::
263+
264+
__bpf_kfunc int bpf_wq_init(struct bpf_wq *wq, void *p__const_map,
265+
unsigned int flags)
266+
{
267+
...
268+
}
269+
270+
``__map`` indicates an opaque ``struct bpf_map *`` that may be resolved
271+
at run time. The argument may take either a map fd or a ``PTR_TO_BTF_ID``
272+
``struct bpf_map`` pointer.
273+
274+
An example is given below::
275+
276+
__bpf_kfunc void *bpf_arena_alloc_pages(void *p__map, ...)
277+
{
278+
...
279+
}
280+
281+
2.3.8 __arena and __arena__nullable Annotations
282+
-----------------------------------------------
283+
284+
Both annotations indicate that the pointer argument points into the
285+
calling program's arena. The JIT rebases the value at the call site so
286+
the kfunc receives a directly dereferenceable kernel address, subject to
287+
the access rules described in :ref:`BPF_kfunc_arena_access` (at most
288+
``GUARD_SZ / 2``, 32 KiB, past the pointer in a single unchecked access).
289+
290+
With ``__arena`` the rebase is unconditional and the argument is never
291+
NULL: a value whose lower 32 bits are zero arrives as the arena base
292+
address (arena offset 0). The kfunc must not check the argument for NULL.
293+
With ``__arena__nullable`` such a value arrives as NULL instead and the
294+
kfunc must check before dereferencing.
295+
296+
An example is given below::
297+
298+
__bpf_kfunc int bpf_process_item(struct item *item__arena)
299+
{
300+
...
301+
}
302+
303+
Calling such a kfunc requires the program to use an arena map and a JIT with
304+
arena argument support (currently x86-64 and arm64); verification fails
305+
otherwise. The program can pass any value without compromising the kernel. A
306+
value that does not point into the arena is a program bug.
307+
308+
The suffixes have the same meaning on the arguments of struct_ops stub
309+
functions, with the conversion running in the opposite direction. The
310+
kernel caller passes the kernel arena address and the trampoline converts
311+
it while saving the arguments, so the callback receives an arena pointer
312+
it can dereference directly. With ``__arena`` the kernel caller must not
313+
pass NULL. With ``__arena__nullable`` a NULL kernel pointer arrives as NULL.
314+
However, there is no obligation to prove to the verifier that such a pointer is
315+
non-NULL before use, in-line with existing semantics of arena pointers used in
316+
a program (or obtained from any other source).
317+
253318
.. _BPF_kfunc_nodef:
254319

255320
2.4 Using an existing kernel function
@@ -273,22 +338,29 @@ flags on a set of kfuncs as follows::
273338
BTF_KFUNCS_END(bpf_task_set)
274339

275340
This set encodes the BTF ID of each kfunc listed above, and encodes the flags
276-
along with it. Ofcourse, it is also allowed to specify no flags.
341+
along with it. It is also allowed to specify no flags.
277342

278343
kfunc definitions should also always be annotated with the ``__bpf_kfunc``
279-
macro. This prevents issues such as the compiler inlining the kfunc if it's a
280-
static kernel function, or the function being elided in an LTO build as it's
281-
not used in the rest of the kernel. Developers should not manually add
282-
annotations to their kfunc to prevent these issues. If an annotation is
283-
required to prevent such an issue with your kfunc, it is a bug and should be
284-
added to the definition of the macro so that other kfuncs are similarly
285-
protected. An example is given below::
344+
macro. This prevents issues such as the compiler inlining the kfunc, or the
345+
function being elided in an LTO build as it's not used in the rest of the
346+
kernel. Developers should not manually add annotations to their kfunc to prevent
347+
these issues. If an annotation is required to prevent such an issue with your
348+
kfunc, it is a bug and should be added to the definition of the macro so that
349+
other kfuncs are similarly protected. An example is given below::
286350

287351
__bpf_kfunc struct task_struct *bpf_get_task_pid(s32 pid)
288352
{
289353
...
290354
}
291355

356+
Note that kfuncs must not be declared ``static``. A kfunc can be called from a
357+
BPF program ``*.c`` file outside the compilation unit that defines it, so its
358+
externally visible name must remain available for BTF ID lookup. ``static``
359+
linkage allows the compiler to rename the function, which can break this
360+
BTF-based kfunc resolution. Further note that sparse may warn that an otherwise
361+
unreferenced kfunc should be static. Such warnings should be ignored for kfunc
362+
definitions.
363+
292364
2.5.1 KF_ACQUIRE flag
293365
---------------------
294366

@@ -404,7 +476,7 @@ Example declaration:
404476
.. code-block:: c
405477
406478
__bpf_kfunc int bpf_task_work_schedule_signal(struct task_struct *task, struct bpf_task_work *tw,
407-
void *map__map, bpf_task_work_callback_t callback,
479+
void *map__const_map, bpf_task_work_callback_t callback,
408480
struct bpf_prog_aux *aux) { ... }
409481
410482
Example usage in BPF program:
@@ -437,6 +509,13 @@ type. An example is shown below::
437509
}
438510
late_initcall(init_subsystem);
439511

512+
At kernel build time the ``resolve_btfids`` tool finds all kfuncs declared with
513+
``BTF_KFUNCS_START()`` and emits their BTF annotations into the kernel's BTF.
514+
For each kfunc it emits a ``bpf_kfunc`` BTF decl tag, a ``bpf_fastcall`` decl
515+
tag when the kfunc is flagged ``KF_FASTCALL``, and the ``address_space(1)`` type
516+
attribute on the return value and/or arguments that use arena pointers (see
517+
sections 2.3.8 and 2.8).
518+
440519
2.7 Specifying no-cast aliases with ___init
441520
--------------------------------------------
442521

@@ -480,6 +559,8 @@ In order to accommodate such requirements, the verifier will enforce strict
480559
PTR_TO_BTF_ID type matching if two types have the exact same name, with one
481560
being suffixed with ``___init``.
482561

562+
.. _BPF_kfunc_arena_access:
563+
483564
2.8 Accessing arena memory through kfunc arguments
484565
--------------------------------------------------
485566

0 commit comments

Comments
 (0)