Thread (7 messages) 7 messages, 4 authors, 3d ago

Re: [PATCH net v3 1/2] af_unix: fix listen() succeeding on sockets in the wrong state

From: John Ericson <hidden>
Date: 2026-07-23 20:58:48
Also in: lkml

On Thu, Jul 23, 2026, at 12:12 PM, Jakub Kicinski wrote:
On Sat, 18 Jul 2026 14:29:01 -0400 John Ericson wrote:
quoted
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.
As the bug proves this

err = x
if (cond)
goto bla;

is a fragile pattern. People do this to avoid the extra braces AFAIU
but it's not worth it. Can you move the error setting before the jumps
please?

if (cond) {
err = x;
goto bla;
}
-- 
pw-bot: cr
Ahahaha. I had the exact same thought!

The original revision of this [1] indeed had the error handling reworked
like that, but Kuniyuki Iwashima asked me to submit the simple 1-line
patch to "net" first, and only submit the cleanup to "net-next" later,
so that is what I was doing.

Is that OK with you, too, I hope?

John

[1]: https://lore.kernel.org/all/20260702202018.2280336-1-John.Ericson@Obsidian.Systems/ (local)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help