Pass a sockptr_t to prepare for set_fs-less handling of the kernel pointer from bpf-cgroup.
Unified · Split
| @@ -20,6 +20,7 @@ · 19 unmodified lines | ||
| 20 | 20 | #include <linux/kallsyms.h> |
| 21 | 21 | #include <linux/if_vlan.h> |
| 22 | 22 | #include <linux/vmalloc.h> |
| 23 | +#include <linux/sockptr.h> | |
| 23 | 24 | #include <crypto/sha.h> |
| 24 | 25 | |
| 25 | 26 | #include <net/sch_generic.h> |
| @@ -1276,7 +1277,7 @@ struct bpf_sockopt_kern { · 1250 unmodified lines | ||
| 1276 | 1277 | s32 retval; |
| 1277 | 1278 | }; |
| 1278 | 1279 | |
| 1279 | −int copy_bpf_fprog_from_user(struct sock_fprog *dst, void __user *src, int len); | |
| 1280 | +int copy_bpf_fprog_from_user(struct sock_fprog *dst, sockptr_t src, int len); | |
| 1280 | 1281 | |
| 1281 | 1282 | struct bpf_sk_lookup_kern { |
| 1282 | 1283 | u16 family; |
| @@ -77,14 +77,14 @@ · 76 unmodified lines | ||
| 77 | 77 | #include <net/transp_v6.h> |
| 78 | 78 | #include <linux/btf_ids.h> |
| 79 | 79 | |
| 80 | −int copy_bpf_fprog_from_user(struct sock_fprog *dst, void __user *src, int len) | |
| 80 | +int copy_bpf_fprog_from_user(struct sock_fprog *dst, sockptr_t src, int len) | |
| 81 | 81 | { |
| 82 | 82 | if (in_compat_syscall()) { |
| 83 | 83 | struct compat_sock_fprog f32; |
| 84 | 84 | |
| 85 | 85 | if (len != sizeof(f32)) |
| 86 | 86 | return -EINVAL; |
| 87 | − if (copy_from_user(&f32, src, sizeof(f32))) | |
| 87 | + if (copy_from_sockptr(&f32, src, sizeof(f32))) | |
| 88 | 88 | return -EFAULT; |
| 89 | 89 | memset(dst, 0, sizeof(*dst)); |
| 90 | 90 | dst->len = f32.len; |
| @@ -92,7 +92,7 @@ int copy_bpf_fprog_from_user(struct sock_fprog *dst, void __user *src, int len) · 1 unmodified line | ||
| 92 | 92 | } else { |
| 93 | 93 | if (len != sizeof(*dst)) |
| 94 | 94 | return -EINVAL; |
| 95 | − if (copy_from_user(dst, src, sizeof(*dst))) | |
| 95 | + if (copy_from_sockptr(dst, src, sizeof(*dst))) | |
| 96 | 96 | return -EFAULT; |
| 97 | 97 | } |
| 98 | 98 | |
| @@ -1063,7 +1063,8 @@ set_sndbuf: · 1062 unmodified lines | ||
| 1063 | 1063 | case SO_ATTACH_FILTER: { |
| 1064 | 1064 | struct sock_fprog fprog; |
| 1065 | 1065 | |
| 1066 | − ret = copy_bpf_fprog_from_user(&fprog, optval, optlen); | |
| 1066 | + ret = copy_bpf_fprog_from_user(&fprog, USER_SOCKPTR(optval), | |
| 1067 | + optlen); | |
| 1067 | 1068 | if (!ret) |
| 1068 | 1069 | ret = sk_attach_filter(&fprog, sk); |
| 1069 | 1070 | break; |
| @@ -1084,7 +1085,8 @@ set_sndbuf: · 14 unmodified lines | ||
| 1084 | 1085 | case SO_ATTACH_REUSEPORT_CBPF: { |
| 1085 | 1086 | struct sock_fprog fprog; |
| 1086 | 1087 | |
| 1087 | − ret = copy_bpf_fprog_from_user(&fprog, optval, optlen); | |
| 1088 | + ret = copy_bpf_fprog_from_user(&fprog, USER_SOCKPTR(optval), | |
| 1089 | + optlen); | |
| 1088 | 1090 | if (!ret) |
| 1089 | 1091 | ret = sk_reuseport_attach_filter(&fprog, sk); |
| 1090 | 1092 | break; |
| @@ -1536,7 +1536,7 @@ static void __fanout_set_data_bpf(struct packet_fanout *f, struct bpf_prog *new) · 1535 unmodified lines | ||
| 1536 | 1536 | } |
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | −static int fanout_set_data_cbpf(struct packet_sock *po, char __user *data, | |
| 1539 | +static int fanout_set_data_cbpf(struct packet_sock *po, sockptr_t data, | |
| 1540 | 1540 | unsigned int len) |
| 1541 | 1541 | { |
| 1542 | 1542 | struct bpf_prog *new; |
| @@ -1584,7 +1584,7 @@ static int fanout_set_data(struct packet_sock *po, char __user *data, · 41 unmodified lines | ||
| 1584 | 1584 | { |
| 1585 | 1585 | switch (po->fanout->type) { |
| 1586 | 1586 | case PACKET_FANOUT_CBPF: |
| 1587 | − return fanout_set_data_cbpf(po, data, len); | |
| 1587 | + return fanout_set_data_cbpf(po, USER_SOCKPTR(data), len); | |
| 1588 | 1588 | case PACKET_FANOUT_EBPF: |
| 1589 | 1589 | return fanout_set_data_ebpf(po, data, len); |
| 1590 | 1590 | default: |