mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
net: switch copy_bpf_fprog_from_user to sockptr_t
Pass a sockptr_t to prepare for set_fs-less handling of the kernel pointer from bpf-cgroup. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
ba423fdaa5
commit
b1ea9ff6af
4 changed files with 11 additions and 8 deletions
|
@ -20,6 +20,7 @@
|
||||||
#include <linux/kallsyms.h>
|
#include <linux/kallsyms.h>
|
||||||
#include <linux/if_vlan.h>
|
#include <linux/if_vlan.h>
|
||||||
#include <linux/vmalloc.h>
|
#include <linux/vmalloc.h>
|
||||||
|
#include <linux/sockptr.h>
|
||||||
#include <crypto/sha.h>
|
#include <crypto/sha.h>
|
||||||
|
|
||||||
#include <net/sch_generic.h>
|
#include <net/sch_generic.h>
|
||||||
|
@ -1276,7 +1277,7 @@ struct bpf_sockopt_kern {
|
||||||
s32 retval;
|
s32 retval;
|
||||||
};
|
};
|
||||||
|
|
||||||
int copy_bpf_fprog_from_user(struct sock_fprog *dst, void __user *src, int len);
|
int copy_bpf_fprog_from_user(struct sock_fprog *dst, sockptr_t src, int len);
|
||||||
|
|
||||||
struct bpf_sk_lookup_kern {
|
struct bpf_sk_lookup_kern {
|
||||||
u16 family;
|
u16 family;
|
||||||
|
|
|
@ -77,14 +77,14 @@
|
||||||
#include <net/transp_v6.h>
|
#include <net/transp_v6.h>
|
||||||
#include <linux/btf_ids.h>
|
#include <linux/btf_ids.h>
|
||||||
|
|
||||||
int copy_bpf_fprog_from_user(struct sock_fprog *dst, void __user *src, int len)
|
int copy_bpf_fprog_from_user(struct sock_fprog *dst, sockptr_t src, int len)
|
||||||
{
|
{
|
||||||
if (in_compat_syscall()) {
|
if (in_compat_syscall()) {
|
||||||
struct compat_sock_fprog f32;
|
struct compat_sock_fprog f32;
|
||||||
|
|
||||||
if (len != sizeof(f32))
|
if (len != sizeof(f32))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (copy_from_user(&f32, src, sizeof(f32)))
|
if (copy_from_sockptr(&f32, src, sizeof(f32)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
memset(dst, 0, sizeof(*dst));
|
memset(dst, 0, sizeof(*dst));
|
||||||
dst->len = f32.len;
|
dst->len = f32.len;
|
||||||
|
@ -92,7 +92,7 @@ int copy_bpf_fprog_from_user(struct sock_fprog *dst, void __user *src, int len)
|
||||||
} else {
|
} else {
|
||||||
if (len != sizeof(*dst))
|
if (len != sizeof(*dst))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (copy_from_user(dst, src, sizeof(*dst)))
|
if (copy_from_sockptr(dst, src, sizeof(*dst)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1063,7 +1063,8 @@ set_sndbuf:
|
||||||
case SO_ATTACH_FILTER: {
|
case SO_ATTACH_FILTER: {
|
||||||
struct sock_fprog fprog;
|
struct sock_fprog fprog;
|
||||||
|
|
||||||
ret = copy_bpf_fprog_from_user(&fprog, optval, optlen);
|
ret = copy_bpf_fprog_from_user(&fprog, USER_SOCKPTR(optval),
|
||||||
|
optlen);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = sk_attach_filter(&fprog, sk);
|
ret = sk_attach_filter(&fprog, sk);
|
||||||
break;
|
break;
|
||||||
|
@ -1084,7 +1085,8 @@ set_sndbuf:
|
||||||
case SO_ATTACH_REUSEPORT_CBPF: {
|
case SO_ATTACH_REUSEPORT_CBPF: {
|
||||||
struct sock_fprog fprog;
|
struct sock_fprog fprog;
|
||||||
|
|
||||||
ret = copy_bpf_fprog_from_user(&fprog, optval, optlen);
|
ret = copy_bpf_fprog_from_user(&fprog, USER_SOCKPTR(optval),
|
||||||
|
optlen);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = sk_reuseport_attach_filter(&fprog, sk);
|
ret = sk_reuseport_attach_filter(&fprog, sk);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1536,7 +1536,7 @@ static void __fanout_set_data_bpf(struct packet_fanout *f, struct bpf_prog *new)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fanout_set_data_cbpf(struct packet_sock *po, char __user *data,
|
static int fanout_set_data_cbpf(struct packet_sock *po, sockptr_t data,
|
||||||
unsigned int len)
|
unsigned int len)
|
||||||
{
|
{
|
||||||
struct bpf_prog *new;
|
struct bpf_prog *new;
|
||||||
|
@ -1584,7 +1584,7 @@ static int fanout_set_data(struct packet_sock *po, char __user *data,
|
||||||
{
|
{
|
||||||
switch (po->fanout->type) {
|
switch (po->fanout->type) {
|
||||||
case PACKET_FANOUT_CBPF:
|
case PACKET_FANOUT_CBPF:
|
||||||
return fanout_set_data_cbpf(po, data, len);
|
return fanout_set_data_cbpf(po, USER_SOCKPTR(data), len);
|
||||||
case PACKET_FANOUT_EBPF:
|
case PACKET_FANOUT_EBPF:
|
||||||
return fanout_set_data_ebpf(po, data, len);
|
return fanout_set_data_ebpf(po, data, len);
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Reference in a new issue