net/xfrm: switch xfrm_user_policy 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:
Christoph Hellwig 2020-07-23 08:08:51 +02:00 committed by David S. Miller
parent c8c1bbb6eb
commit c6d1b26a8f
4 changed files with 12 additions and 8 deletions

View File

@ -15,6 +15,7 @@
#include <linux/audit.h>
#include <linux/slab.h>
#include <linux/refcount.h>
#include <linux/sockptr.h>
#include <net/sock.h>
#include <net/dst.h>
@ -1609,10 +1610,11 @@ int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb,
void xfrm6_local_rxpmtu(struct sk_buff *skb, u32 mtu);
int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb);
int xfrm6_udp_encap_rcv(struct sock *sk, struct sk_buff *skb);
int xfrm_user_policy(struct sock *sk, int optname,
u8 __user *optval, int optlen);
int xfrm_user_policy(struct sock *sk, int optname, sockptr_t optval,
int optlen);
#else
static inline int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
static inline int xfrm_user_policy(struct sock *sk, int optname,
sockptr_t optval, int optlen)
{
return -ENOPROTOOPT;
}

View File

@ -1322,7 +1322,8 @@ static int do_ip_setsockopt(struct sock *sk, int level,
err = -EPERM;
if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
break;
err = xfrm_user_policy(sk, optname, optval, optlen);
err = xfrm_user_policy(sk, optname, USER_SOCKPTR(optval),
optlen);
break;
case IP_TRANSPARENT:

View File

@ -935,7 +935,8 @@ done:
retv = -EPERM;
if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
break;
retv = xfrm_user_policy(sk, optname, optval, optlen);
retv = xfrm_user_policy(sk, optname, USER_SOCKPTR(optval),
optlen);
break;
case IPV6_ADDR_PREFERENCES:

View File

@ -2264,7 +2264,7 @@ static bool km_is_alive(const struct km_event *c)
return is_alive;
}
int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen)
int xfrm_user_policy(struct sock *sk, int optname, sockptr_t optval, int optlen)
{
int err;
u8 *data;
@ -2274,7 +2274,7 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
if (in_compat_syscall())
return -EOPNOTSUPP;
if (!optval && !optlen) {
if (sockptr_is_null(optval) && !optlen) {
xfrm_sk_policy_insert(sk, XFRM_POLICY_IN, NULL);
xfrm_sk_policy_insert(sk, XFRM_POLICY_OUT, NULL);
__sk_dst_reset(sk);
@ -2284,7 +2284,7 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
if (optlen <= 0 || optlen > PAGE_SIZE)
return -EMSGSIZE;
data = memdup_user(optval, optlen);
data = memdup_sockptr(optval, optlen);
if (IS_ERR(data))
return PTR_ERR(data);