Skip to content

Commit c49b292

Browse files
committed
Alexei Starovoitov says: ==================== pull-request: bpf-next 2023-12-18 This PR is larger than usual and contains changes in various parts of the kernel. The main changes are: 1) Fix kCFI bugs in BPF, from Peter Zijlstra. End result: all forms of indirect calls from BPF into kernel and from kernel into BPF work with CFI enabled. This allows BPF to work with CONFIG_FINEIBT=y. 2) Introduce BPF token object, from Andrii Nakryiko. It adds an ability to delegate a subset of BPF features from privileged daemon (e.g., systemd) through special mount options for userns-bound BPF FS to a trusted unprivileged application. The design accommodates suggestions from Christian Brauner and Paul Moore. Example: $ sudo mkdir -p /sys/fs/bpf/token $ sudo mount -t bpf bpffs /sys/fs/bpf/token \ -o delegate_cmds=prog_load:MAP_CREATE \ -o delegate_progs=kprobe \ -o delegate_attachs=xdp 3) Various verifier improvements and fixes, from Andrii Nakryiko, Andrei Matei. - Complete precision tracking support for register spills - Fix verification of possibly-zero-sized stack accesses - Fix access to uninit stack slots - Track aligned STACK_ZERO cases as imprecise spilled registers. It improves the verifier "instructions processed" metric from single digit to 50-60% for some programs. - Fix verifier retval logic 4) Support for VLAN tag in XDP hints, from Larysa Zaremba. 5) Allocate BPF trampoline via bpf_prog_pack mechanism, from Song Liu. End result: better memory utilization and lower I$ miss for calls to BPF via BPF trampoline. 6) Fix race between BPF prog accessing inner map and parallel delete, from Hou Tao. 7) Add bpf_xdp_get_xfrm_state() kfunc, from Daniel Xu. It allows BPF interact with IPSEC infra. The intent is to support software RSS (via XDP) for the upcoming ipsec pcpu work. Experiments on AWS demonstrate single tunnel pcpu ipsec reaching line rate on 100G ENA nics. 8) Expand bpf_cgrp_storage to support cgroup1 non-attach, from Yafang Shao. 9) BPF file verification via fsverity, from Song Liu. It allows BPF progs get fsverity digest. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (164 commits) bpf: Ensure precise is reset to false in __mark_reg_const_zero() selftests/bpf: Add more uprobe multi fail tests bpf: Fail uprobe multi link with negative offset selftests/bpf: Test the release of map btf s390/bpf: Fix indirect trampoline generation selftests/bpf: Temporarily disable dummy_struct_ops test on s390 x86/cfi,bpf: Fix bpf_exception_cb() signature bpf: Fix dtor CFI cfi: Add CFI_NOSEAL() x86/cfi,bpf: Fix bpf_struct_ops CFI x86/cfi,bpf: Fix bpf_callback_t CFI x86/cfi,bpf: Fix BPF JIT call cfi: Flip headers selftests/bpf: Add test for abnormal cnt during multi-kprobe attachment selftests/bpf: Don't use libbpf_get_error() in kprobe_multi_test selftests/bpf: Add test for abnormal cnt during multi-uprobe attachment bpf: Limit the number of kprobes when attaching program to multiple kprobes bpf: Limit the number of uprobes when attaching program to multiple uprobes bpf: xdp: Register generic_kfunc_set with XDP programs selftests/bpf: utilize string values for delegate_xxx mount options ... ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 0ee28c9 + 8e432e6 commit c49b292

File tree

177 files changed

+8407
-1798
lines changed

Some content is hidden

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

177 files changed

+8407
-1798
lines changed

Documentation/bpf/cpumasks.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ can be used to query the contents of cpumasks.
352352

353353
.. kernel-doc:: kernel/bpf/cpumask.c
354354
:identifiers: bpf_cpumask_first bpf_cpumask_first_zero bpf_cpumask_first_and
355-
bpf_cpumask_test_cpu
355+
bpf_cpumask_test_cpu bpf_cpumask_weight
356356

357357
.. kernel-doc:: kernel/bpf/cpumask.c
358358
:identifiers: bpf_cpumask_equal bpf_cpumask_intersects bpf_cpumask_subset

Documentation/bpf/fs_kfuncs.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
.. _fs_kfuncs-header-label:
4+
5+
=====================
6+
BPF filesystem kfuncs
7+
=====================
8+
9+
BPF LSM programs need to access filesystem data from LSM hooks. The following
10+
BPF kfuncs can be used to get these data.
11+
12+
* ``bpf_get_file_xattr()``
13+
14+
* ``bpf_get_fsverity_digest()``
15+
16+
To avoid recursions, these kfuncs follow the following rules:
17+
18+
1. These kfuncs are only permitted from BPF LSM function.
19+
2. These kfuncs should not call into other LSM hooks, i.e. security_*(). For
20+
example, ``bpf_get_file_xattr()`` does not use ``vfs_getxattr()``, because
21+
the latter calls LSM hook ``security_inode_getxattr``.

Documentation/bpf/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ that goes into great technical depth about the BPF Architecture.
2121
helpers
2222
kfuncs
2323
cpumasks
24+
fs_kfuncs
2425
programs
2526
maps
2627
bpf_prog_run

Documentation/netlink/specs/netdev.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ definitions:
5454
name: hash
5555
doc:
5656
Device is capable of exposing receive packet hash via bpf_xdp_metadata_rx_hash().
57+
-
58+
name: vlan-tag
59+
doc:
60+
Device is capable of exposing receive packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag().
5761
-
5862
type: flags
5963
name: xsk-flags

Documentation/networking/xdp-rx-metadata.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ Currently, the following kfuncs are supported. In the future, as more
2020
metadata is supported, this set will grow:
2121

2222
.. kernel-doc:: net/core/xdp.c
23-
:identifiers: bpf_xdp_metadata_rx_timestamp bpf_xdp_metadata_rx_hash
23+
:identifiers: bpf_xdp_metadata_rx_timestamp
24+
25+
.. kernel-doc:: net/core/xdp.c
26+
:identifiers: bpf_xdp_metadata_rx_hash
27+
28+
.. kernel-doc:: net/core/xdp.c
29+
:identifiers: bpf_xdp_metadata_rx_vlan_tag
2430

2531
An XDP program can use these kfuncs to read the metadata into stack
2632
variables for its own consumption. Or, to pass the metadata on to other

Documentation/networking/xsk-tx-metadata.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
13
==================
24
AF_XDP TX Metadata
35
==================

arch/arm64/net/bpf_jit_comp.c

+37-18
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ static void restore_args(struct jit_ctx *ctx, int args_off, int nregs)
18281828
*
18291829
*/
18301830
static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
1831-
struct bpf_tramp_links *tlinks, void *orig_call,
1831+
struct bpf_tramp_links *tlinks, void *func_addr,
18321832
int nregs, u32 flags)
18331833
{
18341834
int i;
@@ -1926,7 +1926,7 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
19261926

19271927
if (flags & BPF_TRAMP_F_IP_ARG) {
19281928
/* save ip address of the traced function */
1929-
emit_addr_mov_i64(A64_R(10), (const u64)orig_call, ctx);
1929+
emit_addr_mov_i64(A64_R(10), (const u64)func_addr, ctx);
19301930
emit(A64_STR64I(A64_R(10), A64_SP, ip_off), ctx);
19311931
}
19321932

@@ -2026,18 +2026,10 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
20262026
return ctx->idx;
20272027
}
20282028

2029-
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image,
2030-
void *image_end, const struct btf_func_model *m,
2031-
u32 flags, struct bpf_tramp_links *tlinks,
2032-
void *orig_call)
2029+
static int btf_func_model_nregs(const struct btf_func_model *m)
20332030
{
2034-
int i, ret;
20352031
int nregs = m->nr_args;
2036-
int max_insns = ((long)image_end - (long)image) / AARCH64_INSN_SIZE;
2037-
struct jit_ctx ctx = {
2038-
.image = NULL,
2039-
.idx = 0,
2040-
};
2032+
int i;
20412033

20422034
/* extra registers needed for struct argument */
20432035
for (i = 0; i < MAX_BPF_FUNC_ARGS; i++) {
@@ -2046,22 +2038,49 @@ int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image,
20462038
nregs += (m->arg_size[i] + 7) / 8 - 1;
20472039
}
20482040

2041+
return nregs;
2042+
}
2043+
2044+
int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
2045+
struct bpf_tramp_links *tlinks, void *func_addr)
2046+
{
2047+
struct jit_ctx ctx = {
2048+
.image = NULL,
2049+
.idx = 0,
2050+
};
2051+
struct bpf_tramp_image im;
2052+
int nregs, ret;
2053+
2054+
nregs = btf_func_model_nregs(m);
20492055
/* the first 8 registers are used for arguments */
20502056
if (nregs > 8)
20512057
return -ENOTSUPP;
20522058

2053-
ret = prepare_trampoline(&ctx, im, tlinks, orig_call, nregs, flags);
2059+
ret = prepare_trampoline(&ctx, &im, tlinks, func_addr, nregs, flags);
20542060
if (ret < 0)
20552061
return ret;
20562062

2057-
if (ret > max_insns)
2058-
return -EFBIG;
2063+
return ret < 0 ? ret : ret * AARCH64_INSN_SIZE;
2064+
}
20592065

2060-
ctx.image = image;
2061-
ctx.idx = 0;
2066+
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image,
2067+
void *image_end, const struct btf_func_model *m,
2068+
u32 flags, struct bpf_tramp_links *tlinks,
2069+
void *func_addr)
2070+
{
2071+
int ret, nregs;
2072+
struct jit_ctx ctx = {
2073+
.image = image,
2074+
.idx = 0,
2075+
};
2076+
2077+
nregs = btf_func_model_nregs(m);
2078+
/* the first 8 registers are used for arguments */
2079+
if (nregs > 8)
2080+
return -ENOTSUPP;
20622081

20632082
jit_fill_hole(image, (unsigned int)(image_end - image));
2064-
ret = prepare_trampoline(&ctx, im, tlinks, orig_call, nregs, flags);
2083+
ret = prepare_trampoline(&ctx, im, tlinks, func_addr, nregs, flags);
20652084

20662085
if (ret > 0 && validate_code(&ctx) < 0)
20672086
ret = -EINVAL;

arch/riscv/include/asm/cfi.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
*
88
* Copyright (C) 2023 Google LLC
99
*/
10+
#include <linux/bug.h>
1011

11-
#include <linux/cfi.h>
12+
struct pt_regs;
1213

1314
#ifdef CONFIG_CFI_CLANG
1415
enum bug_trap_type handle_cfi_failure(struct pt_regs *regs);

arch/riscv/kernel/cfi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Copyright (C) 2023 Google LLC
66
*/
7-
#include <asm/cfi.h>
7+
#include <linux/cfi.h>
88
#include <asm/insn.h>
99

1010
/*

arch/riscv/net/bpf_jit_comp64.c

+15-10
Original file line numberDiff line numberDiff line change
@@ -1029,23 +1029,28 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
10291029
return ret;
10301030
}
10311031

1032-
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image,
1033-
void *image_end, const struct btf_func_model *m,
1034-
u32 flags, struct bpf_tramp_links *tlinks,
1035-
void *func_addr)
1032+
int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
1033+
struct bpf_tramp_links *tlinks, void *func_addr)
10361034
{
1037-
int ret;
1035+
struct bpf_tramp_image im;
10381036
struct rv_jit_context ctx;
1037+
int ret;
10391038

10401039
ctx.ninsns = 0;
10411040
ctx.insns = NULL;
10421041
ctx.ro_insns = NULL;
1043-
ret = __arch_prepare_bpf_trampoline(im, m, tlinks, func_addr, flags, &ctx);
1044-
if (ret < 0)
1045-
return ret;
1042+
ret = __arch_prepare_bpf_trampoline(&im, m, tlinks, func_addr, flags, &ctx);
10461043

1047-
if (ninsns_rvoff(ret) > (long)image_end - (long)image)
1048-
return -EFBIG;
1044+
return ret < 0 ? ret : ninsns_rvoff(ctx.ninsns);
1045+
}
1046+
1047+
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image,
1048+
void *image_end, const struct btf_func_model *m,
1049+
u32 flags, struct bpf_tramp_links *tlinks,
1050+
void *func_addr)
1051+
{
1052+
int ret;
1053+
struct rv_jit_context ctx;
10491054

10501055
ctx.ninsns = 0;
10511056
/*

arch/s390/net/bpf_jit_comp.c

+36-23
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,8 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
23622362
return -ENOTSUPP;
23632363

23642364
/* Return to %r14, since func_addr and %r0 are not available. */
2365-
if (!func_addr && !(flags & BPF_TRAMP_F_ORIG_STACK))
2365+
if ((!func_addr && !(flags & BPF_TRAMP_F_ORIG_STACK)) ||
2366+
(flags & BPF_TRAMP_F_INDIRECT))
23662367
flags |= BPF_TRAMP_F_SKIP_FRAME;
23672368

23682369
/*
@@ -2637,37 +2638,49 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
26372638
return 0;
26382639
}
26392640

2641+
int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,
2642+
struct bpf_tramp_links *tlinks, void *orig_call)
2643+
{
2644+
struct bpf_tramp_image im;
2645+
struct bpf_tramp_jit tjit;
2646+
int ret;
2647+
2648+
memset(&tjit, 0, sizeof(tjit));
2649+
2650+
ret = __arch_prepare_bpf_trampoline(&im, &tjit, m, flags,
2651+
tlinks, orig_call);
2652+
2653+
return ret < 0 ? ret : tjit.common.prg;
2654+
}
2655+
26402656
int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *image,
26412657
void *image_end, const struct btf_func_model *m,
26422658
u32 flags, struct bpf_tramp_links *tlinks,
26432659
void *func_addr)
26442660
{
26452661
struct bpf_tramp_jit tjit;
26462662
int ret;
2647-
int i;
26482663

2649-
for (i = 0; i < 2; i++) {
2650-
if (i == 0) {
2651-
/* Compute offsets, check whether the code fits. */
2652-
memset(&tjit, 0, sizeof(tjit));
2653-
} else {
2654-
/* Generate the code. */
2655-
tjit.common.prg = 0;
2656-
tjit.common.prg_buf = image;
2657-
}
2658-
ret = __arch_prepare_bpf_trampoline(im, &tjit, m, flags,
2659-
tlinks, func_addr);
2660-
if (ret < 0)
2661-
return ret;
2662-
if (tjit.common.prg > (char *)image_end - (char *)image)
2663-
/*
2664-
* Use the same error code as for exceeding
2665-
* BPF_MAX_TRAMP_LINKS.
2666-
*/
2667-
return -E2BIG;
2668-
}
2664+
/* Compute offsets, check whether the code fits. */
2665+
memset(&tjit, 0, sizeof(tjit));
2666+
ret = __arch_prepare_bpf_trampoline(im, &tjit, m, flags,
2667+
tlinks, func_addr);
2668+
2669+
if (ret < 0)
2670+
return ret;
2671+
if (tjit.common.prg > (char *)image_end - (char *)image)
2672+
/*
2673+
* Use the same error code as for exceeding
2674+
* BPF_MAX_TRAMP_LINKS.
2675+
*/
2676+
return -E2BIG;
2677+
2678+
tjit.common.prg = 0;
2679+
tjit.common.prg_buf = image;
2680+
ret = __arch_prepare_bpf_trampoline(im, &tjit, m, flags,
2681+
tlinks, func_addr);
26692682

2670-
return tjit.common.prg;
2683+
return ret < 0 ? ret : tjit.common.prg;
26712684
}
26722685

26732686
bool bpf_jit_supports_subprog_tailcalls(void)

0 commit comments

Comments
 (0)