Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 1/3] af_unix: fix listen() succeeding on sockets in the wrong state
@ 2026-07-03  8:14 John Ericson
  2026-07-03  8:14 ` [PATCH net v2 2/3] selftests/net/af_unix: test listen() rejects wrong socket states John Ericson
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: John Ericson @ 2026-07-03  8:14 UTC (permalink / raw)
  To: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Kuniyuki Iwashima
  Cc: John Ericson, Simon Horman, Christian Brauner, David Rheinsberg,
	Cong Wang, John Ericson, Sergei Zimmerman, netdev, linux-kernel

From: John Ericson <mail@johnericson.me>

Commit fd0a109a0f6b ("net, pidfs: prepare for handing out pidfds for
reaped sk->sk_peer_pid") inserted a `prepare_peercred()` call between
`err = -EINVAL` and the socket-state check in `unix_listen()`. Since
`prepare_peercred()` leaves `err` at 0 on success, `listen()` on an
AF_UNIX socket that is not in `TCP_CLOSE` or `TCP_LISTEN` state (e.g.
one that is already connected) now silently returns success without
doing anything, instead of failing with `EINVAL` as it did before.

Fixes: fd0a109a0f6b ("net, pidfs: prepare for handing out pidfds for reaped sk->sk_peer_pid")
Assisted-by: Claude:claude-fable-5
Signed-off-by: John Ericson <mail@johnericson.me>
---
 net/unix/af_unix.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index f7a9d55eee8a..10ed9421e43a 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -823,6 +823,7 @@ static int unix_listen(struct socket *sock, int backlog)
 	if (err)
 		goto out;
 	unix_state_lock(sk);
+	err = -EINVAL;
 	if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN)
 		goto out_unlock;
 	if (backlog > sk->sk_max_ack_backlog)
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-07-04  1:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-03  8:14 [PATCH net v2 1/3] af_unix: fix listen() succeeding on sockets in the wrong state John Ericson
2026-07-03  8:14 ` [PATCH net v2 2/3] selftests/net/af_unix: test listen() rejects wrong socket states John Ericson
2026-07-03 13:17   ` Christian Brauner
2026-07-04  1:54   ` Kuniyuki Iwashima
2026-07-03  8:14 ` [PATCH net-next v2 3/3] af_unix: Clean up error handling in unix_listen() John Ericson
2026-07-03 13:17   ` Christian Brauner
2026-07-04  1:46   ` Kuniyuki Iwashima
2026-07-03 13:17 ` [PATCH net v2 1/3] af_unix: fix listen() succeeding on sockets in the wrong state Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox