mirror of
https://github.com/torvalds/linux.git
synced 2024-11-12 23:23:03 +00:00
bpf: net: Change do_tcp_setsockopt() to use the sockopt's lock_sock() and capable()
Similar to the earlier patch that avoids sk_setsockopt() from taking sk lock and doing capable test when called by bpf. This patch changes do_tcp_setsockopt() to use the sockopt_{lock,release}_sock() and sockopt_[ns_]capable(). Reviewed-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/r/20220817061730.4176021-1-kafai@fb.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
e42c7beee7
commit
cb388e7ee3
@ -3202,7 +3202,7 @@ EXPORT_SYMBOL(tcp_disconnect);
|
|||||||
|
|
||||||
static inline bool tcp_can_repair_sock(const struct sock *sk)
|
static inline bool tcp_can_repair_sock(const struct sock *sk)
|
||||||
{
|
{
|
||||||
return ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN) &&
|
return sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN) &&
|
||||||
(sk->sk_state != TCP_LISTEN);
|
(sk->sk_state != TCP_LISTEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3502,11 +3502,11 @@ static int do_tcp_setsockopt(struct sock *sk, int level, int optname,
|
|||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
name[val] = 0;
|
name[val] = 0;
|
||||||
|
|
||||||
lock_sock(sk);
|
sockopt_lock_sock(sk);
|
||||||
err = tcp_set_congestion_control(sk, name, true,
|
err = tcp_set_congestion_control(sk, name, true,
|
||||||
ns_capable(sock_net(sk)->user_ns,
|
sockopt_ns_capable(sock_net(sk)->user_ns,
|
||||||
CAP_NET_ADMIN));
|
CAP_NET_ADMIN));
|
||||||
release_sock(sk);
|
sockopt_release_sock(sk);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
case TCP_ULP: {
|
case TCP_ULP: {
|
||||||
@ -3522,9 +3522,9 @@ static int do_tcp_setsockopt(struct sock *sk, int level, int optname,
|
|||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
name[val] = 0;
|
name[val] = 0;
|
||||||
|
|
||||||
lock_sock(sk);
|
sockopt_lock_sock(sk);
|
||||||
err = tcp_set_ulp(sk, name);
|
err = tcp_set_ulp(sk, name);
|
||||||
release_sock(sk);
|
sockopt_release_sock(sk);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
case TCP_FASTOPEN_KEY: {
|
case TCP_FASTOPEN_KEY: {
|
||||||
@ -3557,7 +3557,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level, int optname,
|
|||||||
if (copy_from_sockptr(&val, optval, sizeof(val)))
|
if (copy_from_sockptr(&val, optval, sizeof(val)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
lock_sock(sk);
|
sockopt_lock_sock(sk);
|
||||||
|
|
||||||
switch (optname) {
|
switch (optname) {
|
||||||
case TCP_MAXSEG:
|
case TCP_MAXSEG:
|
||||||
@ -3779,7 +3779,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level, int optname,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
release_sock(sk);
|
sockopt_release_sock(sk);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user