]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
af_unix: Save listener for embryo socket.
authorKuniyuki Iwashima <kuniyu@amazon.com>
Wed, 21 May 2025 15:27:13 +0000 (16:27 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Jun 2025 12:40:24 +0000 (14:40 +0200)
commit aed6ecef55d70de3762ce41c561b7f547dbaf107 upstream.

This is a prep patch for the following change, where we need to
fetch the listening socket from the successor embryo socket
during GC.

We add a new field to struct unix_sock to save a pointer to a
listening socket.

We set it when connect() creates a new socket, and clear it when
accept() is called.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Link: https://lore.kernel.org/r/20240325202425.60930-8-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/net/af_unix.h
net/unix/af_unix.c

index e6f7bba191529c88484404a4581be864d9563176..624fea65751898a574ed8c85304c459da172a1ba 100644 (file)
@@ -83,6 +83,7 @@ struct unix_sock {
        struct path             path;
        struct mutex            iolock, bindlock;
        struct sock             *peer;
+       struct sock             *listener;
        struct unix_vertex      *vertex;
        struct list_head        link;
        unsigned long           inflight;
index 658a1680a92ec2c10ad1e196e264c67b6490d444..6075ecbe40b270b2fdcbe4f065f412126bce340b 100644 (file)
@@ -954,6 +954,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern,
        sk->sk_max_ack_backlog  = READ_ONCE(net->unx.sysctl_max_dgram_qlen);
        sk->sk_destruct         = unix_sock_destructor;
        u = unix_sk(sk);
+       u->listener = NULL;
        u->inflight = 0;
        u->vertex = NULL;
        u->path.dentry = NULL;
@@ -1558,6 +1559,7 @@ restart:
        newsk->sk_type          = sk->sk_type;
        init_peercred(newsk);
        newu = unix_sk(newsk);
+       newu->listener = other;
        RCU_INIT_POINTER(newsk->sk_wq, &newu->peer_wq);
        otheru = unix_sk(other);
 
@@ -1651,8 +1653,8 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags,
                       bool kern)
 {
        struct sock *sk = sock->sk;
-       struct sock *tsk;
        struct sk_buff *skb;
+       struct sock *tsk;
        int err;
 
        err = -EOPNOTSUPP;
@@ -1677,6 +1679,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags,
        }
 
        tsk = skb->sk;
+       unix_sk(tsk)->listener = NULL;
        skb_free_datagram(sk, skb);
        wake_up_interruptible(&unix_sk(sk)->peer_wait);