]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net/smc: fix missing sk_err when TCP handshake fails
authorD. Wythe <alibuda@linux.alibaba.com>
Wed, 6 May 2026 01:41:05 +0000 (09:41 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 7 May 2026 15:36:34 +0000 (08:36 -0700)
In smc_connect_work(), when the underlying TCP handshake fails, the error
code (rc) must be propagated to sk_err to ensure userspace can correctly
retrieve the error status via SO_ERROR. Currently, the code only handles
a restricted set of error codes (e.g., EPIPE, ECONNREFUSED). If other
errors occurs, such as EHOSTUNREACH, sk_err remains unset (zero).

This affects applications that rely on SO_ERROR to determine connect
outcome. For example, higher versions of Go's netpoller treats
SO_ERROR == 0 combined with a failed getpeername() as a spurious wakeup
and re-enters epoll_wait(). Under ET mode, no further edge will be
generated since the socket is already in a terminal state, causing the
connect to hang indefinitely or until a user-specified timeout, if one
is set.

Fixes: 50717a37db03 ("net/smc: nonblocking connect rework")
Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
Link: https://patch.msgid.link/20260506014105.27093-1-alibuda@linux.alibaba.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/smc/af_smc.c

index 1a565095376aaba0904c19467bc6cd9da4f9d867..185dbed7de5d6ceab88c9d92b61ed4d21d7767ff 100644 (file)
@@ -1628,12 +1628,8 @@ static void smc_connect_work(struct work_struct *work)
        lock_sock(&smc->sk);
        if (rc != 0 || smc->sk.sk_err) {
                smc->sk.sk_state = SMC_CLOSED;
-               if (rc == -EPIPE || rc == -EAGAIN)
-                       smc->sk.sk_err = EPIPE;
-               else if (rc == -ECONNREFUSED)
-                       smc->sk.sk_err = ECONNREFUSED;
-               else if (signal_pending(current))
-                       smc->sk.sk_err = -sock_intr_errno(timeo);
+               if (!smc->sk.sk_err)
+                       smc->sk.sk_err = (rc == -EAGAIN) ? EPIPE : -rc;
                sock_put(&smc->sk); /* passive closing */
                goto out;
        }