Skip to content

Commit 931be6b

Browse files
bcodding-rhgregkh
authored andcommitted
SUNRPC: timeout and cancel TLS handshake with -ETIMEDOUT
[ Upstream commit d7bdd84 ] We've noticed a situation where an unstable TCP connection can cause the TLS handshake to timeout waiting for userspace to complete it. When this happens, we don't want to return from xs_tls_handshake_sync() with zero, as this will cause the upper xprt to be set CONNECTED, and subsequent attempts to transmit will be returned with -EPIPE. The sunrpc machine does not recover from this situation and will spin attempting to transmit. The return value of tls_handshake_cancel() can be used to detect a race with completion: * tls_handshake_cancel - cancel a pending handshake * Return values: * %true - Uncompleted handshake request was canceled * %false - Handshake request already completed or not found If true, we do not want the upper xprt to be connected, so return -ETIMEDOUT. If false, its possible the handshake request was lost and that may be the reason for our timeout. Again we do not want the upper xprt to be connected, so return -ETIMEDOUT. Ensure that we alway return an error from xs_tls_handshake_sync() if we call tls_handshake_cancel(). Signed-off-by: Benjamin Coddington <[email protected]> Reviewed-by: Chuck Lever <[email protected]> Fixes: 75eb6af ("SUNRPC: Add a TCP-with-TLS RPC transport class") Signed-off-by: Trond Myklebust <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 3811172 commit 931be6b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

net/sunrpc/xprtsock.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,11 +2596,10 @@ static int xs_tls_handshake_sync(struct rpc_xprt *lower_xprt, struct xprtsec_par
25962596
rc = wait_for_completion_interruptible_timeout(&lower_transport->handshake_done,
25972597
XS_TLS_HANDSHAKE_TO);
25982598
if (rc <= 0) {
2599-
if (!tls_handshake_cancel(sk)) {
2600-
if (rc == 0)
2601-
rc = -ETIMEDOUT;
2602-
goto out_put_xprt;
2603-
}
2599+
tls_handshake_cancel(sk);
2600+
if (rc == 0)
2601+
rc = -ETIMEDOUT;
2602+
goto out_put_xprt;
26042603
}
26052604

26062605
rc = lower_transport->xprt_err;

0 commit comments

Comments
 (0)