linux/tools/testing/selftests/net/af_unix
John Ericson 7f57c650d0 selftests/net/af_unix: test listen() rejects wrong socket states
Add a regression test for the unix_listen() state check. The key case is
listen() on a bound socket that has already been connected: it is no
longer in TCP_CLOSE or TCP_LISTEN, so it must fail with EINVAL. A
prepare_peercred() call slipped in ahead of that check once left err at 0
and made listen() silently succeed there instead; this guards against a
repeat.

The neighbouring outcomes are covered too so they cannot regress the same
way: a bound socket in TCP_CLOSE listens fine, calling listen() again on a
socket already in TCP_LISTEN is allowed, and an unbound socket fails with
EINVAL.

Each case runs for both listenable socket types (SOCK_STREAM and
SOCK_SEQPACKET) and both pathname and abstract addresses.

Fixes: fd0a109a0f ("net, pidfs: prepare for handing out pidfds for reaped sk->sk_peer_pid")
Signed-off-by: John Ericson <mail@johnericson.me>
Link: https://patch.msgid.link/20260718182903.2295560-2-John.Ericson@Obsidian.Systems
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2026-07-24 15:10:05 -07:00
..
.gitignore selftests/net/af_unix: test listen() rejects wrong socket states 2026-07-24 15:10:05 -07:00
config selftests: af_unix: add USER_NS config 2026-07-21 15:01:29 -07:00
diag_uid.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
Makefile selftests/net/af_unix: test listen() rejects wrong socket states 2026-07-24 15:10:05 -07:00
msg_oob.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
scm_inq.c af_unix: Add test for SCM_INQ on partial read 2026-06-03 18:52:25 -07:00
scm_pidfd.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
scm_rights.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
so_peek_off.c selftests: af_unix: validate SO_PEEK_OFF advancement and reset 2026-03-11 18:20:17 -07:00
unix_connect.c selftests: complete kselftest include centralization 2025-11-27 14:24:31 -08:00
unix_connreset.c selftests: af_unix: remove unused stdlib.h include 2025-11-27 12:42:51 +01:00
unix_listen.c selftests/net/af_unix: test listen() rejects wrong socket states 2026-07-24 15:10:05 -07:00