mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-27 06:05:12 +07:00
5b92a28aae
Allow FENTRY/FEXIT BPF programs to attach to other BPF programs of any type including their subprograms. This feature allows snooping on input and output packets in XDP, TC programs including their return values. In order to do that the verifier needs to track types not only of vmlinux, but types of other BPF programs as well. The verifier also needs to translate uapi/linux/bpf.h types used by networking programs into kernel internal BTF types used by FENTRY/FEXIT BPF programs. In some cases LLVM optimizations can remove arguments from BPF subprograms without adjusting BTF info that LLVM backend knows. When BTF info disagrees with actual types that the verifiers sees the BPF trampoline has to fallback to conservative and treat all arguments as u64. The FENTRY/FEXIT program can still attach to such subprograms, but it won't be able to recognize pointer types like 'struct sk_buff *' and it won't be able to pass them to bpf_skb_output() for dumping packets to user space. The FENTRY/FEXIT program would need to use bpf_probe_read_kernel() instead. The BPF_PROG_LOAD command is extended with attach_prog_fd field. When it's set to zero the attach_btf_id is one vmlinux BTF type ids. When attach_prog_fd points to previously loaded BPF program the attach_btf_id is BTF type id of main function or one of its subprograms. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20191114185720.1641606-18-ast@kernel.org
106 lines
3.1 KiB
C
106 lines
3.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/* Copyright (c) 2018 Facebook */
|
|
|
|
#ifndef _LINUX_BTF_H
|
|
#define _LINUX_BTF_H 1
|
|
|
|
#include <linux/types.h>
|
|
#include <uapi/linux/btf.h>
|
|
|
|
struct btf;
|
|
struct btf_member;
|
|
struct btf_type;
|
|
union bpf_attr;
|
|
|
|
extern const struct file_operations btf_fops;
|
|
|
|
void btf_put(struct btf *btf);
|
|
int btf_new_fd(const union bpf_attr *attr);
|
|
struct btf *btf_get_by_fd(int fd);
|
|
int btf_get_info_by_fd(const struct btf *btf,
|
|
const union bpf_attr *attr,
|
|
union bpf_attr __user *uattr);
|
|
/* Figure out the size of a type_id. If type_id is a modifier
|
|
* (e.g. const), it will be resolved to find out the type with size.
|
|
*
|
|
* For example:
|
|
* In describing "const void *", type_id is "const" and "const"
|
|
* refers to "void *". The return type will be "void *".
|
|
*
|
|
* If type_id is a simple "int", then return type will be "int".
|
|
*
|
|
* @btf: struct btf object
|
|
* @type_id: Find out the size of type_id. The type_id of the return
|
|
* type is set to *type_id.
|
|
* @ret_size: It can be NULL. If not NULL, the size of the return
|
|
* type is set to *ret_size.
|
|
* Return: The btf_type (resolved to another type with size info if needed).
|
|
* NULL is returned if type_id itself does not have size info
|
|
* (e.g. void) or it cannot be resolved to another type that
|
|
* has size info.
|
|
* *type_id and *ret_size will not be changed in the
|
|
* NULL return case.
|
|
*/
|
|
const struct btf_type *btf_type_id_size(const struct btf *btf,
|
|
u32 *type_id,
|
|
u32 *ret_size);
|
|
void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj,
|
|
struct seq_file *m);
|
|
int btf_get_fd_by_id(u32 id);
|
|
u32 btf_id(const struct btf *btf);
|
|
bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s,
|
|
const struct btf_member *m,
|
|
u32 expected_offset, u32 expected_size);
|
|
int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t);
|
|
bool btf_type_is_void(const struct btf_type *t);
|
|
|
|
static inline bool btf_type_is_ptr(const struct btf_type *t)
|
|
{
|
|
return BTF_INFO_KIND(t->info) == BTF_KIND_PTR;
|
|
}
|
|
|
|
static inline bool btf_type_is_int(const struct btf_type *t)
|
|
{
|
|
return BTF_INFO_KIND(t->info) == BTF_KIND_INT;
|
|
}
|
|
|
|
static inline bool btf_type_is_enum(const struct btf_type *t)
|
|
{
|
|
return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM;
|
|
}
|
|
|
|
static inline bool btf_type_is_typedef(const struct btf_type *t)
|
|
{
|
|
return BTF_INFO_KIND(t->info) == BTF_KIND_TYPEDEF;
|
|
}
|
|
|
|
static inline bool btf_type_is_func(const struct btf_type *t)
|
|
{
|
|
return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC;
|
|
}
|
|
|
|
static inline bool btf_type_is_func_proto(const struct btf_type *t)
|
|
{
|
|
return BTF_INFO_KIND(t->info) == BTF_KIND_FUNC_PROTO;
|
|
}
|
|
|
|
#ifdef CONFIG_BPF_SYSCALL
|
|
const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id);
|
|
const char *btf_name_by_offset(const struct btf *btf, u32 offset);
|
|
struct btf *btf_parse_vmlinux(void);
|
|
struct btf *bpf_prog_get_target_btf(const struct bpf_prog *prog);
|
|
#else
|
|
static inline const struct btf_type *btf_type_by_id(const struct btf *btf,
|
|
u32 type_id)
|
|
{
|
|
return NULL;
|
|
}
|
|
static inline const char *btf_name_by_offset(const struct btf *btf,
|
|
u32 offset)
|
|
{
|
|
return NULL;
|
|
}
|
|
#endif
|
|
|
|
#endif
|