Commit 535e7b4b authored by Mickaël Salaün's avatar Mickaël Salaün Committed by David S. Miller

bpf: Use u64_to_user_ptr()

Replace the custom u64_to_ptr() function with the u64_to_user_ptr()
macro.
Signed-off-by: default avatarMickaël Salaün <mic@digikod.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a7888596
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/license.h> #include <linux/license.h>
#include <linux/filter.h> #include <linux/filter.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/kernel.h>
DEFINE_PER_CPU(int, bpf_prog_active); DEFINE_PER_CPU(int, bpf_prog_active);
...@@ -252,12 +253,6 @@ struct bpf_map *bpf_map_get_with_uref(u32 ufd) ...@@ -252,12 +253,6 @@ struct bpf_map *bpf_map_get_with_uref(u32 ufd)
return map; return map;
} }
/* helper to convert user pointers passed inside __aligned_u64 fields */
static void __user *u64_to_ptr(__u64 val)
{
return (void __user *) (unsigned long) val;
}
int __weak bpf_stackmap_copy(struct bpf_map *map, void *key, void *value) int __weak bpf_stackmap_copy(struct bpf_map *map, void *key, void *value)
{ {
return -ENOTSUPP; return -ENOTSUPP;
...@@ -268,8 +263,8 @@ int __weak bpf_stackmap_copy(struct bpf_map *map, void *key, void *value) ...@@ -268,8 +263,8 @@ int __weak bpf_stackmap_copy(struct bpf_map *map, void *key, void *value)
static int map_lookup_elem(union bpf_attr *attr) static int map_lookup_elem(union bpf_attr *attr)
{ {
void __user *ukey = u64_to_ptr(attr->key); void __user *ukey = u64_to_user_ptr(attr->key);
void __user *uvalue = u64_to_ptr(attr->value); void __user *uvalue = u64_to_user_ptr(attr->value);
int ufd = attr->map_fd; int ufd = attr->map_fd;
struct bpf_map *map; struct bpf_map *map;
void *key, *value, *ptr; void *key, *value, *ptr;
...@@ -342,8 +337,8 @@ static int map_lookup_elem(union bpf_attr *attr) ...@@ -342,8 +337,8 @@ static int map_lookup_elem(union bpf_attr *attr)
static int map_update_elem(union bpf_attr *attr) static int map_update_elem(union bpf_attr *attr)
{ {
void __user *ukey = u64_to_ptr(attr->key); void __user *ukey = u64_to_user_ptr(attr->key);
void __user *uvalue = u64_to_ptr(attr->value); void __user *uvalue = u64_to_user_ptr(attr->value);
int ufd = attr->map_fd; int ufd = attr->map_fd;
struct bpf_map *map; struct bpf_map *map;
void *key, *value; void *key, *value;
...@@ -420,7 +415,7 @@ static int map_update_elem(union bpf_attr *attr) ...@@ -420,7 +415,7 @@ static int map_update_elem(union bpf_attr *attr)
static int map_delete_elem(union bpf_attr *attr) static int map_delete_elem(union bpf_attr *attr)
{ {
void __user *ukey = u64_to_ptr(attr->key); void __user *ukey = u64_to_user_ptr(attr->key);
int ufd = attr->map_fd; int ufd = attr->map_fd;
struct bpf_map *map; struct bpf_map *map;
struct fd f; struct fd f;
...@@ -464,8 +459,8 @@ static int map_delete_elem(union bpf_attr *attr) ...@@ -464,8 +459,8 @@ static int map_delete_elem(union bpf_attr *attr)
static int map_get_next_key(union bpf_attr *attr) static int map_get_next_key(union bpf_attr *attr)
{ {
void __user *ukey = u64_to_ptr(attr->key); void __user *ukey = u64_to_user_ptr(attr->key);
void __user *unext_key = u64_to_ptr(attr->next_key); void __user *unext_key = u64_to_user_ptr(attr->next_key);
int ufd = attr->map_fd; int ufd = attr->map_fd;
struct bpf_map *map; struct bpf_map *map;
void *key, *next_key; void *key, *next_key;
...@@ -741,7 +736,7 @@ static int bpf_prog_load(union bpf_attr *attr) ...@@ -741,7 +736,7 @@ static int bpf_prog_load(union bpf_attr *attr)
return -EINVAL; return -EINVAL;
/* copy eBPF program license from user space */ /* copy eBPF program license from user space */
if (strncpy_from_user(license, u64_to_ptr(attr->license), if (strncpy_from_user(license, u64_to_user_ptr(attr->license),
sizeof(license) - 1) < 0) sizeof(license) - 1) < 0)
return -EFAULT; return -EFAULT;
license[sizeof(license) - 1] = 0; license[sizeof(license) - 1] = 0;
...@@ -771,7 +766,7 @@ static int bpf_prog_load(union bpf_attr *attr) ...@@ -771,7 +766,7 @@ static int bpf_prog_load(union bpf_attr *attr)
prog->len = attr->insn_cnt; prog->len = attr->insn_cnt;
err = -EFAULT; err = -EFAULT;
if (copy_from_user(prog->insns, u64_to_ptr(attr->insns), if (copy_from_user(prog->insns, u64_to_user_ptr(attr->insns),
prog->len * sizeof(struct bpf_insn)) != 0) prog->len * sizeof(struct bpf_insn)) != 0)
goto free_prog; goto free_prog;
...@@ -822,7 +817,7 @@ static int bpf_obj_pin(const union bpf_attr *attr) ...@@ -822,7 +817,7 @@ static int bpf_obj_pin(const union bpf_attr *attr)
if (CHECK_ATTR(BPF_OBJ)) if (CHECK_ATTR(BPF_OBJ))
return -EINVAL; return -EINVAL;
return bpf_obj_pin_user(attr->bpf_fd, u64_to_ptr(attr->pathname)); return bpf_obj_pin_user(attr->bpf_fd, u64_to_user_ptr(attr->pathname));
} }
static int bpf_obj_get(const union bpf_attr *attr) static int bpf_obj_get(const union bpf_attr *attr)
...@@ -830,7 +825,7 @@ static int bpf_obj_get(const union bpf_attr *attr) ...@@ -830,7 +825,7 @@ static int bpf_obj_get(const union bpf_attr *attr)
if (CHECK_ATTR(BPF_OBJ) || attr->bpf_fd != 0) if (CHECK_ATTR(BPF_OBJ) || attr->bpf_fd != 0)
return -EINVAL; return -EINVAL;
return bpf_obj_get_user(u64_to_ptr(attr->pathname)); return bpf_obj_get_user(u64_to_user_ptr(attr->pathname));
} }
SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size) SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment