Skip to content

Commit 1728df7

Browse files
author
Paolo Abeni
committed
Daniel Borkmann says: ==================== pull-request: bpf-next 2023-12-19 Hi David, hi Jakub, hi Paolo, hi Eric, The following pull-request contains BPF updates for your *net-next* tree. We've added 2 non-merge commits during the last 1 day(s) which contain a total of 40 files changed, 642 insertions(+), 2926 deletions(-). The main changes are: 1) Revert all of BPF token-related patches for now as per list discussion [0], from Andrii Nakryiko. [0] https://lore.kernel.org/bpf/CAHk-=wg7JuFYwGy=GOMbRCtOL+jwSQsdUaBsRWkDVYbxipbM5A@mail.gmail.com 2) Fix a syzbot-reported use-after-free read in nla_find() triggered from bpf_skb_get_nlattr_nest() helper, from Jakub Kicinski. bpf-next-for-netdev * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: Revert BPF token-related functionality bpf: Use nla_ok() instead of checking nla_len directly ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 62ed78f + d17aff8 commit 1728df7

File tree

40 files changed

+642
-2926
lines changed

40 files changed

+642
-2926
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 (bpf_token_capable(prog->aux->token, CAP_PERFMON))
113+
if (perfmon_capable())
114114
return bpf_get_trace_printk_proto();
115115
fallthrough;
116116
default:

include/linux/bpf.h

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ struct module;
5252
struct bpf_func_state;
5353
struct ftrace_ops;
5454
struct cgroup;
55-
struct bpf_token;
56-
struct user_namespace;
57-
struct super_block;
58-
struct inode;
5955

6056
extern struct idr btf_idr;
6157
extern spinlock_t btf_idr_lock;
@@ -1488,7 +1484,6 @@ struct bpf_prog_aux {
14881484
#ifdef CONFIG_SECURITY
14891485
void *security;
14901486
#endif
1491-
struct bpf_token *token;
14921487
struct bpf_prog_offload *offload;
14931488
struct btf *btf;
14941489
struct bpf_func_info *func_info;
@@ -1613,31 +1608,6 @@ struct bpf_link_primer {
16131608
u32 id;
16141609
};
16151610

1616-
struct bpf_mount_opts {
1617-
kuid_t uid;
1618-
kgid_t gid;
1619-
umode_t mode;
1620-
1621-
/* BPF token-related delegation options */
1622-
u64 delegate_cmds;
1623-
u64 delegate_maps;
1624-
u64 delegate_progs;
1625-
u64 delegate_attachs;
1626-
};
1627-
1628-
struct bpf_token {
1629-
struct work_struct work;
1630-
atomic64_t refcnt;
1631-
struct user_namespace *userns;
1632-
u64 allowed_cmds;
1633-
u64 allowed_maps;
1634-
u64 allowed_progs;
1635-
u64 allowed_attachs;
1636-
#ifdef CONFIG_SECURITY
1637-
void *security;
1638-
#endif
1639-
};
1640-
16411611
struct bpf_struct_ops_value;
16421612
struct btf_member;
16431613

@@ -2097,7 +2067,6 @@ static inline void bpf_enable_instrumentation(void)
20972067
migrate_enable();
20982068
}
20992069

2100-
extern const struct super_operations bpf_super_ops;
21012070
extern const struct file_operations bpf_map_fops;
21022071
extern const struct file_operations bpf_prog_fops;
21032072
extern const struct file_operations bpf_iter_fops;
@@ -2232,26 +2201,24 @@ static inline void bpf_map_dec_elem_count(struct bpf_map *map)
22322201

22332202
extern int sysctl_unprivileged_bpf_disabled;
22342203

2235-
bool bpf_token_capable(const struct bpf_token *token, int cap);
2236-
2237-
static inline bool bpf_allow_ptr_leaks(const struct bpf_token *token)
2204+
static inline bool bpf_allow_ptr_leaks(void)
22382205
{
2239-
return bpf_token_capable(token, CAP_PERFMON);
2206+
return perfmon_capable();
22402207
}
22412208

2242-
static inline bool bpf_allow_uninit_stack(const struct bpf_token *token)
2209+
static inline bool bpf_allow_uninit_stack(void)
22432210
{
2244-
return bpf_token_capable(token, CAP_PERFMON);
2211+
return perfmon_capable();
22452212
}
22462213

2247-
static inline bool bpf_bypass_spec_v1(const struct bpf_token *token)
2214+
static inline bool bpf_bypass_spec_v1(void)
22482215
{
2249-
return cpu_mitigations_off() || bpf_token_capable(token, CAP_PERFMON);
2216+
return cpu_mitigations_off() || perfmon_capable();
22502217
}
22512218

2252-
static inline bool bpf_bypass_spec_v4(const struct bpf_token *token)
2219+
static inline bool bpf_bypass_spec_v4(void)
22532220
{
2254-
return cpu_mitigations_off() || bpf_token_capable(token, CAP_PERFMON);
2221+
return cpu_mitigations_off() || perfmon_capable();
22552222
}
22562223

22572224
int bpf_map_new_fd(struct bpf_map *map, int flags);
@@ -2268,21 +2235,8 @@ int bpf_link_new_fd(struct bpf_link *link);
22682235
struct bpf_link *bpf_link_get_from_fd(u32 ufd);
22692236
struct bpf_link *bpf_link_get_curr_or_next(u32 *id);
22702237

2271-
void bpf_token_inc(struct bpf_token *token);
2272-
void bpf_token_put(struct bpf_token *token);
2273-
int bpf_token_create(union bpf_attr *attr);
2274-
struct bpf_token *bpf_token_get_from_fd(u32 ufd);
2275-
2276-
bool bpf_token_allow_cmd(const struct bpf_token *token, enum bpf_cmd cmd);
2277-
bool bpf_token_allow_map_type(const struct bpf_token *token, enum bpf_map_type type);
2278-
bool bpf_token_allow_prog_type(const struct bpf_token *token,
2279-
enum bpf_prog_type prog_type,
2280-
enum bpf_attach_type attach_type);
2281-
22822238
int bpf_obj_pin_user(u32 ufd, int path_fd, const char __user *pathname);
22832239
int bpf_obj_get_user(int path_fd, const char __user *pathname, int flags);
2284-
struct inode *bpf_get_inode(struct super_block *sb, const struct inode *dir,
2285-
umode_t mode);
22862240

22872241
#define BPF_ITER_FUNC_PREFIX "bpf_iter_"
22882242
#define DEFINE_BPF_ITER_FUNC(target, args...) \
@@ -2526,8 +2480,7 @@ const char *btf_find_decl_tag_value(const struct btf *btf, const struct btf_type
25262480
struct bpf_prog *bpf_prog_by_id(u32 id);
25272481
struct bpf_link *bpf_link_by_id(u32 id);
25282482

2529-
const struct bpf_func_proto *bpf_base_func_proto(enum bpf_func_id func_id,
2530-
const struct bpf_prog *prog);
2483+
const struct bpf_func_proto *bpf_base_func_proto(enum bpf_func_id func_id);
25312484
void bpf_task_storage_free(struct task_struct *task);
25322485
void bpf_cgrp_storage_free(struct cgroup *cgroup);
25332486
bool bpf_prog_has_kfunc_call(const struct bpf_prog *prog);
@@ -2646,24 +2599,6 @@ static inline int bpf_obj_get_user(const char __user *pathname, int flags)
26462599
return -EOPNOTSUPP;
26472600
}
26482601

2649-
static inline bool bpf_token_capable(const struct bpf_token *token, int cap)
2650-
{
2651-
return capable(cap) || (cap != CAP_SYS_ADMIN && capable(CAP_SYS_ADMIN));
2652-
}
2653-
2654-
static inline void bpf_token_inc(struct bpf_token *token)
2655-
{
2656-
}
2657-
2658-
static inline void bpf_token_put(struct bpf_token *token)
2659-
{
2660-
}
2661-
2662-
static inline struct bpf_token *bpf_token_get_from_fd(u32 ufd)
2663-
{
2664-
return ERR_PTR(-EOPNOTSUPP);
2665-
}
2666-
26672602
static inline void __dev_flush(void)
26682603
{
26692604
}
@@ -2787,7 +2722,7 @@ static inline int btf_struct_access(struct bpf_verifier_log *log,
27872722
}
27882723

27892724
static inline const struct bpf_func_proto *
2790-
bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
2725+
bpf_base_func_proto(enum bpf_func_id func_id)
27912726
{
27922727
return NULL;
27932728
}

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_token_capable(prog->aux->token, CAP_BPF))
1142+
if (bpf_jit_harden == 1 && bpf_capable())
11431143
return false;
11441144

11451145
return true;

include/linux/lsm_hook_defs.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,17 +398,10 @@ 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_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)
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)
412405
#endif /* CONFIG_BPF_SYSCALL */
413406

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

include/linux/security.h

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

3736
struct linux_binprm;
3837
struct cred;
@@ -2021,22 +2020,15 @@ static inline void securityfs_remove(struct dentry *dentry)
20212020
union bpf_attr;
20222021
struct bpf_map;
20232022
struct bpf_prog;
2024-
struct bpf_token;
2023+
struct bpf_prog_aux;
20252024
#ifdef CONFIG_SECURITY
20262025
extern int security_bpf(int cmd, union bpf_attr *attr, unsigned int size);
20272026
extern int security_bpf_map(struct bpf_map *map, fmode_t fmode);
20282027
extern int security_bpf_prog(struct bpf_prog *prog);
2029-
extern int security_bpf_map_create(struct bpf_map *map, union bpf_attr *attr,
2030-
struct bpf_token *token);
2028+
extern int security_bpf_map_alloc(struct bpf_map *map);
20312029
extern void security_bpf_map_free(struct bpf_map *map);
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);
2030+
extern int security_bpf_prog_alloc(struct bpf_prog_aux *aux);
2031+
extern void security_bpf_prog_free(struct bpf_prog_aux *aux);
20402032
#else
20412033
static inline int security_bpf(int cmd, union bpf_attr *attr,
20422034
unsigned int size)
@@ -2054,42 +2046,21 @@ static inline int security_bpf_prog(struct bpf_prog *prog)
20542046
return 0;
20552047
}
20562048

2057-
static inline int security_bpf_map_create(struct bpf_map *map, union bpf_attr *attr,
2058-
struct bpf_token *token)
2049+
static inline int security_bpf_map_alloc(struct bpf_map *map)
20592050
{
20602051
return 0;
20612052
}
20622053

20632054
static inline void security_bpf_map_free(struct bpf_map *map)
20642055
{ }
20652056

2066-
static inline int security_bpf_prog_load(struct bpf_prog *prog, union bpf_attr *attr,
2067-
struct bpf_token *token)
2057+
static inline int security_bpf_prog_alloc(struct bpf_prog_aux *aux)
20682058
{
20692059
return 0;
20702060
}
20712061

2072-
static inline void security_bpf_prog_free(struct bpf_prog *prog)
2062+
static inline void security_bpf_prog_free(struct bpf_prog_aux *aux)
20732063
{ }
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-
}
20932064
#endif /* CONFIG_SECURITY */
20942065
#endif /* CONFIG_BPF_SYSCALL */
20952066

include/uapi/linux/bpf.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -847,36 +847,6 @@ 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-
*
880850
* NOTES
881851
* eBPF objects (maps and programs) can be shared between processes.
882852
*
@@ -931,8 +901,6 @@ enum bpf_cmd {
931901
BPF_ITER_CREATE,
932902
BPF_LINK_DETACH,
933903
BPF_PROG_BIND_MAP,
934-
BPF_TOKEN_CREATE,
935-
__MAX_BPF_CMD,
936904
};
937905

938906
enum bpf_map_type {
@@ -983,7 +951,6 @@ enum bpf_map_type {
983951
BPF_MAP_TYPE_BLOOM_FILTER,
984952
BPF_MAP_TYPE_USER_RINGBUF,
985953
BPF_MAP_TYPE_CGRP_STORAGE,
986-
__MAX_BPF_MAP_TYPE
987954
};
988955

989956
/* Note that tracing related programs such as
@@ -1028,7 +995,6 @@ enum bpf_prog_type {
1028995
BPF_PROG_TYPE_SK_LOOKUP,
1029996
BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
1030997
BPF_PROG_TYPE_NETFILTER,
1031-
__MAX_BPF_PROG_TYPE
1032998
};
1033999

10341000
enum bpf_attach_type {
@@ -1437,7 +1403,6 @@ union bpf_attr {
14371403
* to using 5 hash functions).
14381404
*/
14391405
__u64 map_extra;
1440-
__u32 map_token_fd;
14411406
};
14421407

14431408
struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
@@ -1507,7 +1472,6 @@ union bpf_attr {
15071472
* truncated), or smaller (if log buffer wasn't filled completely).
15081473
*/
15091474
__u32 log_true_size;
1510-
__u32 prog_token_fd;
15111475
};
15121476

15131477
struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -1620,7 +1584,6 @@ union bpf_attr {
16201584
* truncated), or smaller (if log buffer wasn't filled completely).
16211585
*/
16221586
__u32 btf_log_true_size;
1623-
__u32 btf_token_fd;
16241587
};
16251588

16261589
struct {
@@ -1751,11 +1714,6 @@ union bpf_attr {
17511714
__u32 flags; /* extra flags */
17521715
} prog_bind_map;
17531716

1754-
struct { /* struct used by BPF_TOKEN_CREATE command */
1755-
__u32 flags;
1756-
__u32 bpffs_fd;
1757-
} token_create;
1758-
17591717
} __attribute__((aligned(8)));
17601718

17611719
/* 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 token.o
9+
obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o log.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(NULL);
85+
bool bypass_spec_v1 = bpf_bypass_spec_v1();
8686
u64 array_size, mask64;
8787
struct bpf_array *array;
8888

0 commit comments

Comments
 (0)