ksmbd: enable TCP keepalive for accepted connections
authorNamjae Jeon <linkinjeon@kernel.org>
Wed, 19 Aug 2026 01:01:11 +0000 (10:01 +0900)
committerNamjae Jeon <linkinjeon@kernel.org>
Thu, 20 Aug 2026 13:56:10 +0000 (22:56 +0900)
A client that disappears without sending a FIN or RST can leave its
ksmbd connection in ESTABLISHED indefinitely. ksmbd sets a socket
receive timeout, but the connection receive loop retries timeout errors
without a limit, so the connection remains in conn_list and consumes the
per-IP connection quota.

Enable SO_KEEPALIVE on accepted TCP sockets so the TCP stack can detect a
silent peer failure. The keepalive idle time, interval, and probe count
remain controlled by the existing TCP sysctl settings.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/smb/server/transport_tcp.c

index 0ae5f14..921e4e8 100644 (file)
@@ -292,6 +292,12 @@ skip_max_ip_conns_limit:
                ksmbd_debug(CONN, "connect success: accepted new connection\n");
                client_sk->sk->sk_rcvtimeo = KSMBD_TCP_RECV_TIMEOUT;
                client_sk->sk->sk_sndtimeo = KSMBD_TCP_SEND_TIMEOUT;
+               /*
+                * Detect peers that disappear without sending a FIN or RST.
+                * Otherwise the connection handler can retry receive timeouts
+                * indefinitely and keep the connection in conn_list.
+                */
+               sock_set_keepalive(client_sk->sk);
 
                ksmbd_tcp_new_connection(client_sk);
        }