Skip to content

Commit e34a07c

Browse files
kuba-mooPaolo Abeni
authored andcommitted
sock: redo the psock vs ULP protection check
Commit 8a59f9d ("sock: Introduce sk->sk_prot->psock_update_sk_prot()") has moved the inet_csk_has_ulp(sk) check from sk_psock_init() to the new tcp_bpf_update_proto() function. I'm guessing that this was done to allow creating psocks for non-inet sockets. Unfortunately the destruction path for psock includes the ULP unwind, so we need to fail the sk_psock_init() itself. Otherwise if ULP is already present we'll notice that later, and call tcp_update_ulp() with the sk_proto of the ULP itself, which will most likely result in the ULP looping its callbacks. Fixes: 8a59f9d ("sock: Introduce sk->sk_prot->psock_update_sk_prot()") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: John Fastabend <[email protected]> Reviewed-by: Jakub Sitnicki <[email protected]> Tested-by: Jakub Sitnicki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 1b205d9 commit e34a07c

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

include/net/inet_sock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ struct inet_sock {
253253
#define IP_CMSG_CHECKSUM BIT(7)
254254
#define IP_CMSG_RECVFRAGSIZE BIT(8)
255255

256+
static inline bool sk_is_inet(struct sock *sk)
257+
{
258+
return sk->sk_family == AF_INET || sk->sk_family == AF_INET6;
259+
}
260+
256261
/**
257262
* sk_to_full_sk - Access to a full socket
258263
* @sk: pointer to a socket

net/core/skmsg.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,11 @@ struct sk_psock *sk_psock_init(struct sock *sk, int node)
699699

700700
write_lock_bh(&sk->sk_callback_lock);
701701

702+
if (sk_is_inet(sk) && inet_csk_has_ulp(sk)) {
703+
psock = ERR_PTR(-EINVAL);
704+
goto out;
705+
}
706+
702707
if (sk->sk_user_data) {
703708
psock = ERR_PTR(-EBUSY);
704709
goto out;

net/ipv4/tcp_bpf.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,6 @@ int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
611611
return 0;
612612
}
613613

614-
if (inet_csk_has_ulp(sk))
615-
return -EINVAL;
616-
617614
if (sk->sk_family == AF_INET6) {
618615
if (tcp_bpf_assert_proto_ops(psock->sk_proto))
619616
return -EINVAL;

net/tls/tls_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ static void tls_update(struct sock *sk, struct proto *p,
921921
{
922922
struct tls_context *ctx;
923923

924+
WARN_ON_ONCE(sk->sk_prot == p);
925+
924926
ctx = tls_get_ctx(sk);
925927
if (likely(ctx)) {
926928
ctx->sk_write_space = write_space;

0 commit comments

Comments
 (0)