Skip to content

Commit 12365b7

Browse files
q2vengregkh
authored andcommitted
af_unix: Save listener for embryo socket.
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 <[email protected]> Acked-by: Paolo Abeni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Lee Jones <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a6c7ce4 commit 12365b7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

include/net/af_unix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct unix_sock {
8383
struct path path;
8484
struct mutex iolock, bindlock;
8585
struct sock *peer;
86+
struct sock *listener;
8687
struct unix_vertex *vertex;
8788
struct list_head link;
8889
unsigned long inflight;

net/unix/af_unix.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern,
954954
sk->sk_max_ack_backlog = READ_ONCE(net->unx.sysctl_max_dgram_qlen);
955955
sk->sk_destruct = unix_sock_destructor;
956956
u = unix_sk(sk);
957+
u->listener = NULL;
957958
u->inflight = 0;
958959
u->vertex = NULL;
959960
u->path.dentry = NULL;
@@ -1558,6 +1559,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
15581559
newsk->sk_type = sk->sk_type;
15591560
init_peercred(newsk);
15601561
newu = unix_sk(newsk);
1562+
newu->listener = other;
15611563
RCU_INIT_POINTER(newsk->sk_wq, &newu->peer_wq);
15621564
otheru = unix_sk(other);
15631565

@@ -1651,8 +1653,8 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags,
16511653
bool kern)
16521654
{
16531655
struct sock *sk = sock->sk;
1654-
struct sock *tsk;
16551656
struct sk_buff *skb;
1657+
struct sock *tsk;
16561658
int err;
16571659

16581660
err = -EOPNOTSUPP;
@@ -1677,6 +1679,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags,
16771679
}
16781680

16791681
tsk = skb->sk;
1682+
unix_sk(tsk)->listener = NULL;
16801683
skb_free_datagram(sk, skb);
16811684
wake_up_interruptible(&unix_sk(sk)->peer_wait);
16821685

0 commit comments

Comments
 (0)