Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

Alexei Starovoitov and committed by
Daniel Borkmann
c571bd75 00899e7e

+9 -8
+1 -1
include/linux/btf.h
··· 21 21 22 22 void btf_get(struct btf *btf); 23 23 void btf_put(struct btf *btf); 24 - int btf_new_fd(const union bpf_attr *attr); 24 + int btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr); 25 25 struct btf *btf_get_by_fd(int fd); 26 26 int btf_get_info_by_fd(const struct btf *btf, 27 27 const union bpf_attr *attr,
+4 -4
kernel/bpf/btf.c
··· 4257 4257 return 0; 4258 4258 } 4259 4259 4260 - static struct btf *btf_parse(void __user *btf_data, u32 btf_data_size, 4260 + static struct btf *btf_parse(bpfptr_t btf_data, u32 btf_data_size, 4261 4261 u32 log_level, char __user *log_ubuf, u32 log_size) 4262 4262 { 4263 4263 struct btf_verifier_env *env = NULL; ··· 4306 4306 btf->data = data; 4307 4307 btf->data_size = btf_data_size; 4308 4308 4309 - if (copy_from_user(data, btf_data, btf_data_size)) { 4309 + if (copy_from_bpfptr(data, btf_data, btf_data_size)) { 4310 4310 err = -EFAULT; 4311 4311 goto errout; 4312 4312 } ··· 5780 5780 return anon_inode_getfd("btf", &btf_fops, btf, O_RDONLY | O_CLOEXEC); 5781 5781 } 5782 5782 5783 - int btf_new_fd(const union bpf_attr *attr) 5783 + int btf_new_fd(const union bpf_attr *attr, bpfptr_t uattr) 5784 5784 { 5785 5785 struct btf *btf; 5786 5786 int ret; 5787 5787 5788 - btf = btf_parse(u64_to_user_ptr(attr->btf), 5788 + btf = btf_parse(make_bpfptr(attr->btf, uattr.is_kernel), 5789 5789 attr->btf_size, attr->btf_log_level, 5790 5790 u64_to_user_ptr(attr->btf_log_buf), 5791 5791 attr->btf_log_size);
+4 -3
kernel/bpf/syscall.c
··· 3842 3842 3843 3843 #define BPF_BTF_LOAD_LAST_FIELD btf_log_level 3844 3844 3845 - static int bpf_btf_load(const union bpf_attr *attr) 3845 + static int bpf_btf_load(const union bpf_attr *attr, bpfptr_t uattr) 3846 3846 { 3847 3847 if (CHECK_ATTR(BPF_BTF_LOAD)) 3848 3848 return -EINVAL; ··· 3850 3850 if (!bpf_capable()) 3851 3851 return -EPERM; 3852 3852 3853 - return btf_new_fd(attr); 3853 + return btf_new_fd(attr, uattr); 3854 3854 } 3855 3855 3856 3856 #define BPF_BTF_GET_FD_BY_ID_LAST_FIELD btf_id ··· 4471 4471 err = bpf_raw_tracepoint_open(&attr); 4472 4472 break; 4473 4473 case BPF_BTF_LOAD: 4474 - err = bpf_btf_load(&attr); 4474 + err = bpf_btf_load(&attr, uattr); 4475 4475 break; 4476 4476 case BPF_BTF_GET_FD_BY_ID: 4477 4477 err = bpf_btf_get_fd_by_id(&attr); ··· 4552 4552 case BPF_MAP_UPDATE_ELEM: 4553 4553 case BPF_MAP_FREEZE: 4554 4554 case BPF_PROG_LOAD: 4555 + case BPF_BTF_LOAD: 4555 4556 break; 4556 4557 /* case BPF_PROG_TEST_RUN: 4557 4558 * is not part of this list to prevent recursive test_run