Re: [PATCH net v2 2/3] selftests/net/af_unix: test listen() rejects wrong socket states

From: Christian Brauner

Date: Fri Jul 03 2026 - 09:29:44 EST


> 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, re-`listen()`ing a
> socket already in `TCP_LISTEN` is allowed, and an unbound socket fails
> with `EINVAL`.
>
> Fixes: fd0a109a0f6b ("net, pidfs: prepare for handing out pidfds for reaped sk->sk_peer_pid")
> Signed-off-by: John Ericson <mail@xxxxxxxxxxxxxx>

Reviewed-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>

--
Christian Brauner <brauner@xxxxxxxxxx>