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 | #include <linux/kallsyms.h> | 20 | #include <linux/kallsyms.h> |
| 21 | #include <linux/if_vlan.h> | 21 | #include <linux/if_vlan.h> |
| 22 | #include <linux/vmalloc.h> | 22 | #include <linux/vmalloc.h> |
| 23 | #include <linux/sockptr.h> | ||
| 23 | #include <crypto/sha.h> | 24 | #include <crypto/sha.h> |
| 24 | 25 | ||
| 25 | #include <net/sch_generic.h> | 26 | #include <net/sch_generic.h> |
| @@ -1276,7 +1277,7 @@ struct bpf_sockopt_kern { · 1250 unmodified lines | |||
| 1276 | s32 retval; | 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 | struct bpf_sk_lookup_kern { | 1282 | struct bpf_sk_lookup_kern { |
| 1282 | u16 family; | 1283 | u16 family; |
| @@ -77,14 +77,14 @@ · 76 unmodified lines | |||
| 77 | #include <net/transp_v6.h> | 77 | #include <net/transp_v6.h> |
| 78 | #include <linux/btf_ids.h> | 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 | if (in_compat_syscall()) { | 82 | if (in_compat_syscall()) { |
| 83 | struct compat_sock_fprog f32; | 83 | struct compat_sock_fprog f32; |
| 84 | 84 | ||
| 85 | if (len != sizeof(f32)) | 85 | if (len != sizeof(f32)) |
| 86 | return -EINVAL; | 86 | return -EINVAL; |
| 87 | if (copy_from_user(&f32, src, sizeof(f32))) | 87 | if (copy_from_sockptr(&f32, src, sizeof(f32))) |
| 88 | return -EFAULT; | 88 | return -EFAULT; |
| 89 | memset(dst, 0, sizeof(*dst)); | 89 | memset(dst, 0, sizeof(*dst)); |
| 90 | dst->len = f32.len; | 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 | } else { | 92 | } else { |
| 93 | if (len != sizeof(*dst)) | 93 | if (len != sizeof(*dst)) |
| 94 | return -EINVAL; | 94 | return -EINVAL; |
| 95 | if (copy_from_user(dst, src, sizeof(*dst))) | 95 | if (copy_from_sockptr(dst, src, sizeof(*dst))) |
| 96 | return -EFAULT; | 96 | return -EFAULT; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| @@ -1063,7 +1063,8 @@ set_sndbuf: · 1062 unmodified lines | |||
| 1063 | case SO_ATTACH_FILTER: { | 1063 | case SO_ATTACH_FILTER: { |
| 1064 | struct sock_fprog fprog; | 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 | if (!ret) | 1068 | if (!ret) |
| 1068 | ret = sk_attach_filter(&fprog, sk); | 1069 | ret = sk_attach_filter(&fprog, sk); |
| 1069 | break; | 1070 | break; |
| @@ -1084,7 +1085,8 @@ set_sndbuf: · 14 unmodified lines | |||
| 1084 | case SO_ATTACH_REUSEPORT_CBPF: { | 1085 | case SO_ATTACH_REUSEPORT_CBPF: { |
| 1085 | struct sock_fprog fprog; | 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 | if (!ret) | 1090 | if (!ret) |
| 1089 | ret = sk_reuseport_attach_filter(&fprog, sk); | 1091 | ret = sk_reuseport_attach_filter(&fprog, sk); |
| 1090 | break; | 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 | unsigned int len) | 1540 | unsigned int len) |
| 1541 | { | 1541 | { |
| 1542 | struct bpf_prog *new; | 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 | switch (po->fanout->type) { | 1585 | switch (po->fanout->type) { |
| 1586 | case PACKET_FANOUT_CBPF: | 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 | case PACKET_FANOUT_EBPF: | 1588 | case PACKET_FANOUT_EBPF: |
| 1589 | return fanout_set_data_ebpf(po, data, len); | 1589 | return fanout_set_data_ebpf(po, data, len); |
| 1590 | default: | 1590 | default: |