Skip to content

Commit c35919d

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf-token-and-bpf-fs-based-delegation'
Andrii Nakryiko says: ==================== BPF token and BPF FS-based delegation This patch set introduces an ability to delegate a subset of BPF subsystem functionality from privileged system-wide daemon (e.g., systemd or any other container manager) through special mount options for userns-bound BPF FS to a *trusted* unprivileged application. Trust is the key here. This functionality is not about allowing unconditional unprivileged BPF usage. Establishing trust, though, is completely up to the discretion of respective privileged application that would create and mount a BPF FS instance with delegation enabled, as different production setups can and do achieve it through a combination of different means (signing, LSM, code reviews, etc), and it's undesirable and infeasible for kernel to enforce any particular way of validating trustworthiness of particular process. The main motivation for this work is a desire to enable containerized BPF applications to be used together with user namespaces. This is currently impossible, as CAP_BPF, required for BPF subsystem usage, cannot be namespaced or sandboxed, as a general rule. E.g., tracing BPF programs, thanks to BPF helpers like bpf_probe_read_kernel() and bpf_probe_read_user() can safely read arbitrary memory, and it's impossible to ensure that they only read memory of processes belonging to any given namespace. This means that it's impossible to have a mechanically verifiable namespace-aware CAP_BPF capability, and as such another mechanism to allow safe usage of BPF functionality is necessary.BPF FS delegation mount options and BPF token derived from such BPF FS instance is such a mechanism. Kernel makes no assumption about what "trusted" constitutes in any particular case, and it's up to specific privileged applications and their surrounding infrastructure to decide that. What kernel provides is a set of APIs to setup and mount special BPF FS instanecs and derive BPF tokens from it. BPF FS and BPF token are both bound to its owning userns and in such a way are constrained inside intended container. Users can then pass BPF token FD to privileged bpf() syscall commands, like BPF map creation and BPF program loading, to perform such operations without having init userns privileged. This version incorporates feedback and suggestions ([3]) received on v3 of this patch set, and instead of allowing to create BPF tokens directly assuming capable(CAP_SYS_ADMIN), we instead enhance BPF FS to accept a few new delegation mount options. If these options are used and BPF FS itself is properly created, set up, and mounted inside the user namespaced container, user application is able to derive a BPF token object from BPF FS instance, and pass that token to bpf() syscall. As explained in patch #3, BPF token itself doesn't grant access to BPF functionality, but instead allows kernel to do namespaced capabilities checks (ns_capable() vs capable()) for CAP_BPF, CAP_PERFMON, CAP_NET_ADMIN, and CAP_SYS_ADMIN, as applicable. So it forms one half of a puzzle and allows container managers and sys admins to have safe and flexible configuration options: determining which containers get delegation of BPF functionality through BPF FS, and then which applications within such containers are allowed to perform bpf() commands, based on namespaces capabilities. Previous attempt at addressing this very same problem ([0]) attempted to utilize authoritative LSM approach, but was conclusively rejected by upstream LSM maintainers. BPF token concept is not changing anything about LSM approach, but can be combined with LSM hooks for very fine-grained security policy. Some ideas about making BPF token more convenient to use with LSM (in particular custom BPF LSM programs) was briefly described in recent LSF/MM/BPF 2023 presentation ([1]). E.g., an ability to specify user-provided data (context), which in combination with BPF LSM would allow implementing a very dynamic and fine-granular custom security policies on top of BPF token. In the interest of minimizing API surface area and discussions this was relegated to follow up patches, as it's not essential to the fundamental concept of delegatable BPF token. It should be noted that BPF token is conceptually quite similar to the idea of /dev/bpf device file, proposed by Song a while ago ([2]). The biggest difference is the idea of using virtual anon_inode file to hold BPF token and allowing multiple independent instances of them, each (potentially) with its own set of restrictions. And also, crucially, BPF token approach is not using any special stateful task-scoped flags. Instead, bpf() syscall accepts token_fd parameters explicitly for each relevant BPF command. This addresses main concerns brought up during the /dev/bpf discussion, and fits better with overall BPF subsystem design. This patch set adds a basic minimum of functionality to make BPF token idea useful and to discuss API and functionality. Currently only low-level libbpf APIs support creating and passing BPF token around, allowing to test kernel functionality, but for the most part is not sufficient for real-world applications, which typically use high-level libbpf APIs based on `struct bpf_object` type. This was done with the intent to limit the size of patch set and concentrate on mostly kernel-side changes. All the necessary plumbing for libbpf will be sent as a separate follow up patch set kernel support makes it upstream. Another part that should happen once kernel-side BPF token is established, is a set of conventions between applications (e.g., systemd), tools (e.g., bpftool), and libraries (e.g., libbpf) on exposing delegatable BPF FS instance(s) at well-defined locations to allow applications take advantage of this in automatic fashion without explicit code changes on BPF application's side. But I'd like to postpone this discussion to after BPF token concept lands. [0] https://lore.kernel.org/bpf/[email protected]/ [1] http://vger.kernel.org/bpfconf2023_material/Trusted_unprivileged_BPF_LSFMM2023.pdf [2] https://lore.kernel.org/bpf/[email protected]/ [3] https://lore.kernel.org/bpf/20230704-hochverdient-lehne-eeb9eeef785e@brauner/ v11->v12: - enforce exact userns match in bpf_token_capable() and bpf_token_allow_cmd() checks, for added strictness (Christian); v10->v11: - fix BPF FS root check to disallow using bind-mounted subdirectory of BPF FS instance (Christian); - further restrict BPF_TOKEN_CREATE command to be executed from inside exactly the same user namespace as the one used to create BPF FS instance (Christian); v9->v10: - slight adjustments in LSM parts (Paul); - setting delegate_xxx options require capable(CAP_SYS_ADMIN) (Christian); - simplify BPF_TOKEN_CREATE UAPI by accepting BPF FS FD directly (Christian); v8->v9: - fix issue in selftests due to sys/mount.h header (Jiri); - fix warning in doc comments in LSM hooks (kernel test robot); v7->v8: - add bpf_token_allow_cmd and bpf_token_capable hooks (Paul); - inline bpf_token_alloc() into bpf_token_create() to prevent accidental divergence with security_bpf_token_create() hook (Paul); v6->v7: - separate patches to refactor bpf_prog_alloc/bpf_map_alloc LSM hooks, as discussed with Paul, and now they also accept struct bpf_token; - added bpf_token_create/bpf_token_free to allow LSMs (SELinux, specifically) to set up security LSM blob (Paul); - last patch also wires bpf_security_struct setup by SELinux, similar to how it's done for BPF map/prog, though I'm not sure if that's enough, so worst case it's easy to drop this patch if more full fledged SELinux implementation will be done separately; - small fixes for issues caught by code reviews (Jiri, Hou); - fix for test_maps test that doesn't use LIBBPF_OPTS() macro (CI); v5->v6: - fix possible use of uninitialized variable in selftests (CI); - don't use anon_inode, instead create one from BPF FS instance (Christian); - don't store bpf_token inside struct bpf_map, instead pass it explicitly to map_check_btf(). We do store bpf_token inside prog->aux, because it's used during verification and even can be checked during attach time for some program types; - LSM hooks are left intact pending the conclusion of discussion with Paul Moore; I'd prefer to do LSM-related changes as a follow up patch set anyways; v4->v5: - add pre-patch unifying CAP_NET_ADMIN handling inside kernel/bpf/syscall.c (Paul Moore); - fix build warnings and errors in selftests and kernel, detected by CI and kernel test robot; v3->v4: - add delegation mount options to BPF FS; - BPF token is derived from the instance of BPF FS and associates itself with BPF FS' owning userns; - BPF token doesn't grant BPF functionality directly, it just turns capable() checks into ns_capable() checks within BPF FS' owning user; - BPF token cannot be pinned; v2->v3: - make BPF_TOKEN_CREATE pin created BPF token in BPF FS, and disallow BPF_OBJ_PIN for BPF token; v1->v2: - fix build failures on Kconfig with CONFIG_BPF_SYSCALL unset; - drop BPF_F_TOKEN_UNKNOWN_* flags and simplify UAPI (Stanislav). ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 3aee2bf + 36fb949 commit c35919d

File tree

29 files changed

+1624
-167
lines changed

29 files changed

+1624
-167
lines changed

drivers/media/rc/bpf-lirc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ lirc_mode2_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
110110
case BPF_FUNC_get_prandom_u32:
111111
return &bpf_get_prandom_u32_proto;
112112
case BPF_FUNC_trace_printk:
113-
if (perfmon_capable())
113+
if (bpf_token_capable(prog->aux->token, CAP_PERFMON))
114114
return bpf_get_trace_printk_proto();
115115
fallthrough;
116116
default:

include/linux/bpf.h

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ struct module;
5151
struct bpf_func_state;
5252
struct ftrace_ops;
5353
struct cgroup;
54+
struct bpf_token;
55+
struct user_namespace;
56+
struct super_block;
57+
struct inode;
5458

5559
extern struct idr btf_idr;
5660
extern spinlock_t btf_idr_lock;
@@ -1457,6 +1461,7 @@ struct bpf_prog_aux {
14571461
#ifdef CONFIG_SECURITY
14581462
void *security;
14591463
#endif
1464+
struct bpf_token *token;
14601465
struct bpf_prog_offload *offload;
14611466
struct btf *btf;
14621467
struct bpf_func_info *func_info;
@@ -1581,6 +1586,29 @@ struct bpf_link_primer {
15811586
u32 id;
15821587
};
15831588

1589+
struct bpf_mount_opts {
1590+
umode_t mode;
1591+
1592+
/* BPF token-related delegation options */
1593+
u64 delegate_cmds;
1594+
u64 delegate_maps;
1595+
u64 delegate_progs;
1596+
u64 delegate_attachs;
1597+
};
1598+
1599+
struct bpf_token {
1600+
struct work_struct work;
1601+
atomic64_t refcnt;
1602+
struct user_namespace *userns;
1603+
u64 allowed_cmds;
1604+
u64 allowed_maps;
1605+
u64 allowed_progs;
1606+
u64 allowed_attachs;
1607+
#ifdef CONFIG_SECURITY
1608+
void *security;
1609+
#endif
1610+
};
1611+
15841612
struct bpf_struct_ops_value;
15851613
struct btf_member;
15861614

@@ -2038,6 +2066,7 @@ static inline void bpf_enable_instrumentation(void)
20382066
migrate_enable();
20392067
}
20402068

2069+
extern const struct super_operations bpf_super_ops;
20412070
extern const struct file_operations bpf_map_fops;
20422071
extern const struct file_operations bpf_prog_fops;
20432072
extern const struct file_operations bpf_iter_fops;
@@ -2172,24 +2201,26 @@ static inline void bpf_map_dec_elem_count(struct bpf_map *map)
21722201

21732202
extern int sysctl_unprivileged_bpf_disabled;
21742203

2175-
static inline bool bpf_allow_ptr_leaks(void)
2204+
bool bpf_token_capable(const struct bpf_token *token, int cap);
2205+
2206+
static inline bool bpf_allow_ptr_leaks(const struct bpf_token *token)
21762207
{
2177-
return perfmon_capable();
2208+
return bpf_token_capable(token, CAP_PERFMON);
21782209
}
21792210

2180-
static inline bool bpf_allow_uninit_stack(void)
2211+
static inline bool bpf_allow_uninit_stack(const struct bpf_token *token)
21812212
{
2182-
return perfmon_capable();
2213+
return bpf_token_capable(token, CAP_PERFMON);
21832214
}
21842215

2185-
static inline bool bpf_bypass_spec_v1(void)
2216+
static inline bool bpf_bypass_spec_v1(const struct bpf_token *token)
21862217
{
2187-
return cpu_mitigations_off() || perfmon_capable();
2218+
return cpu_mitigations_off() || bpf_token_capable(token, CAP_PERFMON);
21882219
}
21892220

2190-
static inline bool bpf_bypass_spec_v4(void)
2221+
static inline bool bpf_bypass_spec_v4(const struct bpf_token *token)
21912222
{
2192-
return cpu_mitigations_off() || perfmon_capable();
2223+
return cpu_mitigations_off() || bpf_token_capable(token, CAP_PERFMON);
21932224
}
21942225

21952226
int bpf_map_new_fd(struct bpf_map *map, int flags);
@@ -2206,8 +2237,21 @@ int bpf_link_new_fd(struct bpf_link *link);
22062237
struct bpf_link *bpf_link_get_from_fd(u32 ufd);
22072238
struct bpf_link *bpf_link_get_curr_or_next(u32 *id);
22082239

2240+
void bpf_token_inc(struct bpf_token *token);
2241+
void bpf_token_put(struct bpf_token *token);
2242+
int bpf_token_create(union bpf_attr *attr);
2243+
struct bpf_token *bpf_token_get_from_fd(u32 ufd);
2244+
2245+
bool bpf_token_allow_cmd(const struct bpf_token *token, enum bpf_cmd cmd);
2246+
bool bpf_token_allow_map_type(const struct bpf_token *token, enum bpf_map_type type);
2247+
bool bpf_token_allow_prog_type(const struct bpf_token *token,
2248+
enum bpf_prog_type prog_type,
2249+
enum bpf_attach_type attach_type);
2250+
22092251
int bpf_obj_pin_user(u32 ufd, int path_fd, const char __user *pathname);
22102252
int bpf_obj_get_user(int path_fd, const char __user *pathname, int flags);
2253+
struct inode *bpf_get_inode(struct super_block *sb, const struct inode *dir,
2254+
umode_t mode);
22112255

22122256
#define BPF_ITER_FUNC_PREFIX "bpf_iter_"
22132257
#define DEFINE_BPF_ITER_FUNC(target, args...) \
@@ -2451,7 +2495,8 @@ const char *btf_find_decl_tag_value(const struct btf *btf, const struct btf_type
24512495
struct bpf_prog *bpf_prog_by_id(u32 id);
24522496
struct bpf_link *bpf_link_by_id(u32 id);
24532497

2454-
const struct bpf_func_proto *bpf_base_func_proto(enum bpf_func_id func_id);
2498+
const struct bpf_func_proto *bpf_base_func_proto(enum bpf_func_id func_id,
2499+
const struct bpf_prog *prog);
24552500
void bpf_task_storage_free(struct task_struct *task);
24562501
void bpf_cgrp_storage_free(struct cgroup *cgroup);
24572502
bool bpf_prog_has_kfunc_call(const struct bpf_prog *prog);
@@ -2570,6 +2615,24 @@ static inline int bpf_obj_get_user(const char __user *pathname, int flags)
25702615
return -EOPNOTSUPP;
25712616
}
25722617

2618+
static inline bool bpf_token_capable(const struct bpf_token *token, int cap)
2619+
{
2620+
return capable(cap) || (cap != CAP_SYS_ADMIN && capable(CAP_SYS_ADMIN));
2621+
}
2622+
2623+
static inline void bpf_token_inc(struct bpf_token *token)
2624+
{
2625+
}
2626+
2627+
static inline void bpf_token_put(struct bpf_token *token)
2628+
{
2629+
}
2630+
2631+
static inline struct bpf_token *bpf_token_get_from_fd(u32 ufd)
2632+
{
2633+
return ERR_PTR(-EOPNOTSUPP);
2634+
}
2635+
25732636
static inline void __dev_flush(void)
25742637
{
25752638
}
@@ -2693,7 +2756,7 @@ static inline int btf_struct_access(struct bpf_verifier_log *log,
26932756
}
26942757

26952758
static inline const struct bpf_func_proto *
2696-
bpf_base_func_proto(enum bpf_func_id func_id)
2759+
bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
26972760
{
26982761
return NULL;
26992762
}

include/linux/filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ static inline bool bpf_jit_blinding_enabled(struct bpf_prog *prog)
11391139
return false;
11401140
if (!bpf_jit_harden)
11411141
return false;
1142-
if (bpf_jit_harden == 1 && bpf_capable())
1142+
if (bpf_jit_harden == 1 && bpf_token_capable(prog->aux->token, CAP_BPF))
11431143
return false;
11441144

11451145
return true;

include/linux/lsm_hook_defs.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,17 @@ LSM_HOOK(void, LSM_RET_VOID, audit_rule_free, void *lsmrule)
398398
LSM_HOOK(int, 0, bpf, int cmd, union bpf_attr *attr, unsigned int size)
399399
LSM_HOOK(int, 0, bpf_map, struct bpf_map *map, fmode_t fmode)
400400
LSM_HOOK(int, 0, bpf_prog, struct bpf_prog *prog)
401-
LSM_HOOK(int, 0, bpf_map_alloc_security, struct bpf_map *map)
402-
LSM_HOOK(void, LSM_RET_VOID, bpf_map_free_security, struct bpf_map *map)
403-
LSM_HOOK(int, 0, bpf_prog_alloc_security, struct bpf_prog_aux *aux)
404-
LSM_HOOK(void, LSM_RET_VOID, bpf_prog_free_security, struct bpf_prog_aux *aux)
401+
LSM_HOOK(int, 0, bpf_map_create, struct bpf_map *map, union bpf_attr *attr,
402+
struct bpf_token *token)
403+
LSM_HOOK(void, LSM_RET_VOID, bpf_map_free, struct bpf_map *map)
404+
LSM_HOOK(int, 0, bpf_prog_load, struct bpf_prog *prog, union bpf_attr *attr,
405+
struct bpf_token *token)
406+
LSM_HOOK(void, LSM_RET_VOID, bpf_prog_free, struct bpf_prog *prog)
407+
LSM_HOOK(int, 0, bpf_token_create, struct bpf_token *token, union bpf_attr *attr,
408+
struct path *path)
409+
LSM_HOOK(void, LSM_RET_VOID, bpf_token_free, struct bpf_token *token)
410+
LSM_HOOK(int, 0, bpf_token_cmd, const struct bpf_token *token, enum bpf_cmd cmd)
411+
LSM_HOOK(int, 0, bpf_token_capable, const struct bpf_token *token, int cap)
405412
#endif /* CONFIG_BPF_SYSCALL */
406413

407414
LSM_HOOK(int, 0, locked_down, enum lockdown_reason what)

include/linux/security.h

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/string.h>
3333
#include <linux/mm.h>
3434
#include <linux/sockptr.h>
35+
#include <linux/bpf.h>
3536

3637
struct linux_binprm;
3738
struct cred;
@@ -2020,15 +2021,22 @@ static inline void securityfs_remove(struct dentry *dentry)
20202021
union bpf_attr;
20212022
struct bpf_map;
20222023
struct bpf_prog;
2023-
struct bpf_prog_aux;
2024+
struct bpf_token;
20242025
#ifdef CONFIG_SECURITY
20252026
extern int security_bpf(int cmd, union bpf_attr *attr, unsigned int size);
20262027
extern int security_bpf_map(struct bpf_map *map, fmode_t fmode);
20272028
extern int security_bpf_prog(struct bpf_prog *prog);
2028-
extern int security_bpf_map_alloc(struct bpf_map *map);
2029+
extern int security_bpf_map_create(struct bpf_map *map, union bpf_attr *attr,
2030+
struct bpf_token *token);
20292031
extern void security_bpf_map_free(struct bpf_map *map);
2030-
extern int security_bpf_prog_alloc(struct bpf_prog_aux *aux);
2031-
extern void security_bpf_prog_free(struct bpf_prog_aux *aux);
2032+
extern int security_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,
2033+
struct bpf_token *token);
2034+
extern void security_bpf_prog_free(struct bpf_prog *prog);
2035+
extern int security_bpf_token_create(struct bpf_token *token, union bpf_attr *attr,
2036+
struct path *path);
2037+
extern void security_bpf_token_free(struct bpf_token *token);
2038+
extern int security_bpf_token_cmd(const struct bpf_token *token, enum bpf_cmd cmd);
2039+
extern int security_bpf_token_capable(const struct bpf_token *token, int cap);
20322040
#else
20332041
static inline int security_bpf(int cmd, union bpf_attr *attr,
20342042
unsigned int size)
@@ -2046,21 +2054,42 @@ static inline int security_bpf_prog(struct bpf_prog *prog)
20462054
return 0;
20472055
}
20482056

2049-
static inline int security_bpf_map_alloc(struct bpf_map *map)
2057+
static inline int security_bpf_map_create(struct bpf_map *map, union bpf_attr *attr,
2058+
struct bpf_token *token)
20502059
{
20512060
return 0;
20522061
}
20532062

20542063
static inline void security_bpf_map_free(struct bpf_map *map)
20552064
{ }
20562065

2057-
static inline int security_bpf_prog_alloc(struct bpf_prog_aux *aux)
2066+
static inline int security_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,
2067+
struct bpf_token *token)
20582068
{
20592069
return 0;
20602070
}
20612071

2062-
static inline void security_bpf_prog_free(struct bpf_prog_aux *aux)
2072+
static inline void security_bpf_prog_free(struct bpf_prog *prog)
20632073
{ }
2074+
2075+
static inline int security_bpf_token_create(struct bpf_token *token, union bpf_attr *attr,
2076+
struct path *path)
2077+
{
2078+
return 0;
2079+
}
2080+
2081+
static inline void security_bpf_token_free(struct bpf_token *token)
2082+
{ }
2083+
2084+
static inline int security_bpf_token_cmd(const struct bpf_token *token, enum bpf_cmd cmd)
2085+
{
2086+
return 0;
2087+
}
2088+
2089+
static inline int security_bpf_token_capable(const struct bpf_token *token, int cap)
2090+
{
2091+
return 0;
2092+
}
20642093
#endif /* CONFIG_SECURITY */
20652094
#endif /* CONFIG_BPF_SYSCALL */
20662095

include/uapi/linux/bpf.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,36 @@ union bpf_iter_link_info {
847847
* Returns zero on success. On error, -1 is returned and *errno*
848848
* is set appropriately.
849849
*
850+
* BPF_TOKEN_CREATE
851+
* Description
852+
* Create BPF token with embedded information about what
853+
* BPF-related functionality it allows:
854+
* - a set of allowed bpf() syscall commands;
855+
* - a set of allowed BPF map types to be created with
856+
* BPF_MAP_CREATE command, if BPF_MAP_CREATE itself is allowed;
857+
* - a set of allowed BPF program types and BPF program attach
858+
* types to be loaded with BPF_PROG_LOAD command, if
859+
* BPF_PROG_LOAD itself is allowed.
860+
*
861+
* BPF token is created (derived) from an instance of BPF FS,
862+
* assuming it has necessary delegation mount options specified.
863+
* This BPF token can be passed as an extra parameter to various
864+
* bpf() syscall commands to grant BPF subsystem functionality to
865+
* unprivileged processes.
866+
*
867+
* When created, BPF token is "associated" with the owning
868+
* user namespace of BPF FS instance (super block) that it was
869+
* derived from, and subsequent BPF operations performed with
870+
* BPF token would be performing capabilities checks (i.e.,
871+
* CAP_BPF, CAP_PERFMON, CAP_NET_ADMIN, CAP_SYS_ADMIN) within
872+
* that user namespace. Without BPF token, such capabilities
873+
* have to be granted in init user namespace, making bpf()
874+
* syscall incompatible with user namespace, for the most part.
875+
*
876+
* Return
877+
* A new file descriptor (a nonnegative integer), or -1 if an
878+
* error occurred (in which case, *errno* is set appropriately).
879+
*
850880
* NOTES
851881
* eBPF objects (maps and programs) can be shared between processes.
852882
*
@@ -901,6 +931,8 @@ enum bpf_cmd {
901931
BPF_ITER_CREATE,
902932
BPF_LINK_DETACH,
903933
BPF_PROG_BIND_MAP,
934+
BPF_TOKEN_CREATE,
935+
__MAX_BPF_CMD,
904936
};
905937

906938
enum bpf_map_type {
@@ -951,6 +983,7 @@ enum bpf_map_type {
951983
BPF_MAP_TYPE_BLOOM_FILTER,
952984
BPF_MAP_TYPE_USER_RINGBUF,
953985
BPF_MAP_TYPE_CGRP_STORAGE,
986+
__MAX_BPF_MAP_TYPE
954987
};
955988

956989
/* Note that tracing related programs such as
@@ -995,6 +1028,7 @@ enum bpf_prog_type {
9951028
BPF_PROG_TYPE_SK_LOOKUP,
9961029
BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
9971030
BPF_PROG_TYPE_NETFILTER,
1031+
__MAX_BPF_PROG_TYPE
9981032
};
9991033

10001034
enum bpf_attach_type {
@@ -1401,6 +1435,7 @@ union bpf_attr {
14011435
* to using 5 hash functions).
14021436
*/
14031437
__u64 map_extra;
1438+
__u32 map_token_fd;
14041439
};
14051440

14061441
struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
@@ -1470,6 +1505,7 @@ union bpf_attr {
14701505
* truncated), or smaller (if log buffer wasn't filled completely).
14711506
*/
14721507
__u32 log_true_size;
1508+
__u32 prog_token_fd;
14731509
};
14741510

14751511
struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -1582,6 +1618,7 @@ union bpf_attr {
15821618
* truncated), or smaller (if log buffer wasn't filled completely).
15831619
*/
15841620
__u32 btf_log_true_size;
1621+
__u32 btf_token_fd;
15851622
};
15861623

15871624
struct {
@@ -1712,6 +1749,11 @@ union bpf_attr {
17121749
__u32 flags; /* extra flags */
17131750
} prog_bind_map;
17141751

1752+
struct { /* struct used by BPF_TOKEN_CREATE command */
1753+
__u32 flags;
1754+
__u32 bpffs_fd;
1755+
} token_create;
1756+
17151757
} __attribute__((aligned(8)));
17161758

17171759
/* The description below is an attempt at providing documentation to eBPF

kernel/bpf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse
66
endif
77
CFLAGS_core.o += $(call cc-disable-warning, override-init) $(cflags-nogcse-yy)
88

9-
obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o log.o
9+
obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o log.o token.o
1010
obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o
1111
obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o bloom_filter.o
1212
obj-$(CONFIG_BPF_SYSCALL) += local_storage.o queue_stack_maps.o ringbuf.o

kernel/bpf/arraymap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)
8282
bool percpu = attr->map_type == BPF_MAP_TYPE_PERCPU_ARRAY;
8383
int numa_node = bpf_map_attr_numa_node(attr);
8484
u32 elem_size, index_mask, max_entries;
85-
bool bypass_spec_v1 = bpf_bypass_spec_v1();
85+
bool bypass_spec_v1 = bpf_bypass_spec_v1(NULL);
8686
u64 array_size, mask64;
8787
struct bpf_array *array;
8888

0 commit comments

Comments
 (0)