mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
bpf: Make btf_load command to be bpfptr_t compatible.
Similar to prog_load make btf_load command to be availble to bpf_prog_type_syscall program. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20210514003623.28033-7-alexei.starovoitov@gmail.com
This commit is contained in:
parent
00899e7e8d
commit
c571bd752e
3 changed files with 9 additions and 8 deletions
|
@ -21,7 +21,7 @@ extern const struct file_operations btf_fops;
|
||||||
|
|
||||||
void btf_get(struct btf *btf);
|
void btf_get(struct btf *btf);
|
||||||
void btf_put(struct btf *btf);
|
void btf_put(struct btf *btf);
|
||||||
int btf_new_fd(const union bpf_attr *attr);
|
int btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr);
|
||||||
struct btf *btf_get_by_fd(int fd);
|
struct btf *btf_get_by_fd(int fd);
|
||||||
int btf_get_info_by_fd(const struct btf *btf,
|
int btf_get_info_by_fd(const struct btf *btf,
|
||||||
const union bpf_attr *attr,
|
const union bpf_attr *attr,
|
||||||
|
|
|
@ -4257,7 +4257,7 @@ static int btf_parse_hdr(struct btf_verifier_env *env)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct btf *btf_parse(void __user *btf_data, u32 btf_data_size,
|
static struct btf *btf_parse(bpfptr_t btf_data, u32 btf_data_size,
|
||||||
u32 log_level, char __user *log_ubuf, u32 log_size)
|
u32 log_level, char __user *log_ubuf, u32 log_size)
|
||||||
{
|
{
|
||||||
struct btf_verifier_env *env = NULL;
|
struct btf_verifier_env *env = NULL;
|
||||||
|
@ -4306,7 +4306,7 @@ static struct btf *btf_parse(void __user *btf_data, u32 btf_data_size,
|
||||||
btf->data = data;
|
btf->data = data;
|
||||||
btf->data_size = btf_data_size;
|
btf->data_size = btf_data_size;
|
||||||
|
|
||||||
if (copy_from_user(data, btf_data, btf_data_size)) {
|
if (copy_from_bpfptr(data, btf_data, btf_data_size)) {
|
||||||
err = -EFAULT;
|
err = -EFAULT;
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
@ -5780,12 +5780,12 @@ static int __btf_new_fd(struct btf *btf)
|
||||||
return anon_inode_getfd("btf", &btf_fops, btf, O_RDONLY | O_CLOEXEC);
|
return anon_inode_getfd("btf", &btf_fops, btf, O_RDONLY | O_CLOEXEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
int btf_new_fd(const union bpf_attr *attr)
|
int btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr)
|
||||||
{
|
{
|
||||||
struct btf *btf;
|
struct btf *btf;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
btf = btf_parse(u64_to_user_ptr(attr->btf),
|
btf = btf_parse(make_bpfptr(attr->btf, uattr.is_kernel),
|
||||||
attr->btf_size, attr->btf_log_level,
|
attr->btf_size, attr->btf_log_level,
|
||||||
u64_to_user_ptr(attr->btf_log_buf),
|
u64_to_user_ptr(attr->btf_log_buf),
|
||||||
attr->btf_log_size);
|
attr->btf_log_size);
|
||||||
|
|
|
@ -3842,7 +3842,7 @@ static int bpf_obj_get_info_by_fd(const union bpf_attr *attr,
|
||||||
|
|
||||||
#define BPF_BTF_LOAD_LAST_FIELD btf_log_level
|
#define BPF_BTF_LOAD_LAST_FIELD btf_log_level
|
||||||
|
|
||||||
static int bpf_btf_load(const union bpf_attr *attr)
|
static int bpf_btf_load(const union bpf_attr *attr, bpfptr_t uattr)
|
||||||
{
|
{
|
||||||
if (CHECK_ATTR(BPF_BTF_LOAD))
|
if (CHECK_ATTR(BPF_BTF_LOAD))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -3850,7 +3850,7 @@ static int bpf_btf_load(const union bpf_attr *attr)
|
||||||
if (!bpf_capable())
|
if (!bpf_capable())
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
return btf_new_fd(attr);
|
return btf_new_fd(attr, uattr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BPF_BTF_GET_FD_BY_ID_LAST_FIELD btf_id
|
#define BPF_BTF_GET_FD_BY_ID_LAST_FIELD btf_id
|
||||||
|
@ -4471,7 +4471,7 @@ static int __sys_bpf(int cmd, bpfptr_t uattr, unsigned int size)
|
||||||
err = bpf_raw_tracepoint_open(&attr);
|
err = bpf_raw_tracepoint_open(&attr);
|
||||||
break;
|
break;
|
||||||
case BPF_BTF_LOAD:
|
case BPF_BTF_LOAD:
|
||||||
err = bpf_btf_load(&attr);
|
err = bpf_btf_load(&attr, uattr);
|
||||||
break;
|
break;
|
||||||
case BPF_BTF_GET_FD_BY_ID:
|
case BPF_BTF_GET_FD_BY_ID:
|
||||||
err = bpf_btf_get_fd_by_id(&attr);
|
err = bpf_btf_get_fd_by_id(&attr);
|
||||||
|
@ -4552,6 +4552,7 @@ BPF_CALL_3(bpf_sys_bpf, int, cmd, void *, attr, u32, attr_size)
|
||||||
case BPF_MAP_UPDATE_ELEM:
|
case BPF_MAP_UPDATE_ELEM:
|
||||||
case BPF_MAP_FREEZE:
|
case BPF_MAP_FREEZE:
|
||||||
case BPF_PROG_LOAD:
|
case BPF_PROG_LOAD:
|
||||||
|
case BPF_BTF_LOAD:
|
||||||
break;
|
break;
|
||||||
/* case BPF_PROG_TEST_RUN:
|
/* case BPF_PROG_TEST_RUN:
|
||||||
* is not part of this list to prevent recursive test_run
|
* is not part of this list to prevent recursive test_run
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue