Commit c8c1bbb6 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller

net: switch sock_set_timeout to sockptr_t

Pass a sockptr_t to prepare for set_fs-less handling of the kernel
pointer from bpf-cgroup.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarMatthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c34645ac
......@@ -59,6 +59,7 @@
#include <linux/filter.h>
#include <linux/rculist_nulls.h>
#include <linux/poll.h>
#include <linux/sockptr.h>
#include <linux/atomic.h>
#include <linux/refcount.h>
......@@ -1669,7 +1670,7 @@ void sock_pfree(struct sk_buff *skb);
#endif
int sock_setsockopt(struct socket *sock, int level, int op,
char __user *optval, unsigned int optlen);
sockptr_t optval, unsigned int optlen);
int sock_getsockopt(struct socket *sock, int level, int op,
char __user *optval, int __user *optlen);
......
......@@ -826,7 +826,7 @@ EXPORT_SYMBOL(sock_set_rcvbuf);
*/
int sock_setsockopt(struct socket *sock, int level, int optname,
char __user *optval, unsigned int optlen)
sockptr_t optval, unsigned int optlen)
{
struct sock_txtime sk_txtime;
struct sock *sk = sock->sk;
......@@ -840,12 +840,12 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
*/
if (optname == SO_BINDTODEVICE)
return sock_setbindtodevice(sk, USER_SOCKPTR(optval), optlen);
return sock_setbindtodevice(sk, optval, optlen);
if (optlen < sizeof(int))
return -EINVAL;
if (get_user(val, (int __user *)optval))
if (copy_from_sockptr(&val, optval, sizeof(val)))
return -EFAULT;
valbool = val ? 1 : 0;
......@@ -958,7 +958,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
ret = -EINVAL; /* 1003.1g */
break;
}
if (copy_from_user(&ling, optval, sizeof(ling))) {
if (copy_from_sockptr(&ling, optval, sizeof(ling))) {
ret = -EFAULT;
break;
}
......@@ -1052,21 +1052,20 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
case SO_RCVTIMEO_OLD:
case SO_RCVTIMEO_NEW:
ret = sock_set_timeout(&sk->sk_rcvtimeo, USER_SOCKPTR(optval),
ret = sock_set_timeout(&sk->sk_rcvtimeo, optval,
optlen, optname == SO_RCVTIMEO_OLD);
break;
case SO_SNDTIMEO_OLD:
case SO_SNDTIMEO_NEW:
ret = sock_set_timeout(&sk->sk_sndtimeo, USER_SOCKPTR(optval),
ret = sock_set_timeout(&sk->sk_sndtimeo, optval,
optlen, optname == SO_SNDTIMEO_OLD);
break;
case SO_ATTACH_FILTER: {
struct sock_fprog fprog;
ret = copy_bpf_fprog_from_user(&fprog, USER_SOCKPTR(optval),
optlen);
ret = copy_bpf_fprog_from_user(&fprog, optval, optlen);
if (!ret)
ret = sk_attach_filter(&fprog, sk);
break;
......@@ -1077,7 +1076,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
u32 ufd;
ret = -EFAULT;
if (copy_from_user(&ufd, optval, sizeof(ufd)))
if (copy_from_sockptr(&ufd, optval, sizeof(ufd)))
break;
ret = sk_attach_bpf(ufd, sk);
......@@ -1087,8 +1086,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
case SO_ATTACH_REUSEPORT_CBPF: {
struct sock_fprog fprog;
ret = copy_bpf_fprog_from_user(&fprog, USER_SOCKPTR(optval),
optlen);
ret = copy_bpf_fprog_from_user(&fprog, optval, optlen);
if (!ret)
ret = sk_reuseport_attach_filter(&fprog, sk);
break;
......@@ -1099,7 +1097,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
u32 ufd;
ret = -EFAULT;
if (copy_from_user(&ufd, optval, sizeof(ufd)))
if (copy_from_sockptr(&ufd, optval, sizeof(ufd)))
break;
ret = sk_reuseport_attach_bpf(ufd, sk);
......@@ -1179,7 +1177,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
if (sizeof(ulval) != sizeof(val) &&
optlen >= sizeof(ulval) &&
get_user(ulval, (unsigned long __user *)optval)) {
copy_from_sockptr(&ulval, optval, sizeof(ulval))) {
ret = -EFAULT;
break;
}
......@@ -1222,7 +1220,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
if (optlen != sizeof(struct sock_txtime)) {
ret = -EINVAL;
break;
} else if (copy_from_user(&sk_txtime, optval,
} else if (copy_from_sockptr(&sk_txtime, optval,
sizeof(struct sock_txtime))) {
ret = -EFAULT;
break;
......
......@@ -1648,7 +1648,8 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname,
return -EINVAL;
}
ret = sock_setsockopt(ssock, SOL_SOCKET, optname, optval, optlen);
ret = sock_setsockopt(ssock, SOL_SOCKET, optname,
USER_SOCKPTR(optval), optlen);
if (ret == 0) {
if (optname == SO_REUSEPORT)
sk->sk_reuseport = ssock->sk->sk_reuseport;
......@@ -1659,7 +1660,8 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname,
return ret;
}
return sock_setsockopt(sk->sk_socket, SOL_SOCKET, optname, optval, optlen);
return sock_setsockopt(sk->sk_socket, SOL_SOCKET, optname,
USER_SOCKPTR(optval), optlen);
}
static int mptcp_setsockopt_v6(struct mptcp_sock *msk, int optname,
......
......@@ -2130,7 +2130,8 @@ int __sys_setsockopt(int fd, int level, int optname, char __user *optval,
}
if (level == SOL_SOCKET && !sock_use_custom_sol_socket(sock))
err = sock_setsockopt(sock, level, optname, optval, optlen);
err = sock_setsockopt(sock, level, optname,
USER_SOCKPTR(optval), optlen);
else if (unlikely(!sock->ops->setsockopt))
err = -EOPNOTSUPP;
else
......
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