mirror of
https://github.com/torvalds/linux.git
synced 2025-11-03 18:20:25 +02:00
bpf: consider CONST_PTR_TO_MAP as trusted pointer to struct bpf_map
Add the BTF id of struct bpf_map to the reg2btf_ids array. This makes the values of the CONST_PTR_TO_MAP type to be considered as trusted by kfuncs. This, in turn, allows users to execute trusted kfuncs which accept `struct bpf_map *` arguments from non-tracing programs. While exporting the btf_bpf_map_id variable, save some bytes by defining it as BTF_ID_LIST_GLOBAL_SINGLE (which is u32[1]) and not as BTF_ID_LIST (which is u32[64]). Signed-off-by: Anton Protopopov <aspsk@isovalent.com> Link: https://lore.kernel.org/r/20230719092952.41202-3-aspsk@isovalent.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
831deb2976
commit
5ba190c29c
3 changed files with 3 additions and 2 deletions
|
|
@ -267,5 +267,6 @@ MAX_BTF_TRACING_TYPE,
|
||||||
extern u32 btf_tracing_ids[];
|
extern u32 btf_tracing_ids[];
|
||||||
extern u32 bpf_cgroup_btf_id[];
|
extern u32 bpf_cgroup_btf_id[];
|
||||||
extern u32 bpf_local_storage_map_btf_id[];
|
extern u32 bpf_local_storage_map_btf_id[];
|
||||||
|
extern u32 btf_bpf_map_id[];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,7 @@ static const struct seq_operations bpf_map_seq_ops = {
|
||||||
.show = bpf_map_seq_show,
|
.show = bpf_map_seq_show,
|
||||||
};
|
};
|
||||||
|
|
||||||
BTF_ID_LIST(btf_bpf_map_id)
|
BTF_ID_LIST_GLOBAL_SINGLE(btf_bpf_map_id, struct, bpf_map)
|
||||||
BTF_ID(struct, bpf_map)
|
|
||||||
|
|
||||||
static const struct bpf_iter_seq_info bpf_map_seq_info = {
|
static const struct bpf_iter_seq_info bpf_map_seq_info = {
|
||||||
.seq_ops = &bpf_map_seq_ops,
|
.seq_ops = &bpf_map_seq_ops,
|
||||||
|
|
|
||||||
|
|
@ -5419,6 +5419,7 @@ static u32 *reg2btf_ids[__BPF_REG_TYPE_MAX] = {
|
||||||
[PTR_TO_SOCK_COMMON] = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON],
|
[PTR_TO_SOCK_COMMON] = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON],
|
||||||
[PTR_TO_TCP_SOCK] = &btf_sock_ids[BTF_SOCK_TYPE_TCP],
|
[PTR_TO_TCP_SOCK] = &btf_sock_ids[BTF_SOCK_TYPE_TCP],
|
||||||
#endif
|
#endif
|
||||||
|
[CONST_PTR_TO_MAP] = btf_bpf_map_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool is_trusted_reg(const struct bpf_reg_state *reg)
|
static bool is_trusted_reg(const struct bpf_reg_state *reg)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue