Skip to contentSkip to conversation

tlshd: Clean up logic in tlshd_start_tls_handshake()

PATCH In review Chuck Lever 3 participants 3 messages Sep 24, 2025 Handshake upcall for transport layer security

lore
Share & tools
lore

Chuck Lever

author maintainer
#0 lore raw

PATCH 1/1 tlshd: Clean up logic in tlshd_start_tls_handshake()

From: Chuck Lever <[email protected]>

gnutls_handshake() is supposed to return only a GNUTLS_E value, and the session_status field is supposed to contain only a positive errno.

GNUTLS_E_PREMATURE_TERMINATION is -110. It turns out that on x86, -ETIMEDOUT is also -110. Make sure the correct symbolic constants and auditing functions are utilized.

Fixes b010190cfed2 ("tlshd: Pass ETIMEDOUT from gnutls to kernel")
---
 src/tlshd/handshake.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
src/tlshd/handshake.c +5 -5
index 5a2893994d4d..44932b7a5311 100644
@@ -90,19 +90,19 @@ void tlshd_start_tls_handshake(gnutls_session_t session,
 	} while (ret < 0 && !gnutls_error_is_fatal(ret));
 	tlshd_set_nagle(session, saved);
 	if (ret < 0) {
-		/* Any errors here should default to blocking access: */
+		/* By default, a handshake error is permanent */
 		parms->session_status = EACCES;
 		switch (ret) {
 		case GNUTLS_E_CERTIFICATE_ERROR:
 		case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR:
 			tlshd_log_cert_verification_error(session);
 			break;
-		case -ETIMEDOUT:
-			tlshd_log_gnutls_error(ret);
-			parms->session_status = -ret;
+		case GNUTLS_E_PREMATURE_TERMINATION:
+			tlshd_log_error("Handshake timeout, retrying");
+			parms->session_status = ETIMEDOUT;
 			break;
 		default:
-			tlshd_log_notice("tlshd_start_tls_handshake unhandled error %d, returning EACCES\n", ret);
+			tlshd_log_gnutls_error(ret);
 		}
 		return;
 	}
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Chuck Lever

From: Chuck Lever <[email protected]>

gnutls_handshake() is supposed to return only a GNUTLS_E value, and the session_status field is supposed to contain only a positive errno.

Quoted 6 lines

GNUTLS_E_PREMATURE_TERMINATION is -110. It turns out that on x86, -ETIMEDOUT is also -110. Make sure the correct symbolic constants and auditing functions are utilized.

Fixes b010190cfed2 ("tlshd: Pass ETIMEDOUT from gnutls to kernel")

Its better!

Ben

#2 lore raw
In reply to Chuck Lever
Quoted 21 lines · Chuck Lever

From: Chuck Lever <[email protected]>

gnutls_handshake() is supposed to return only a GNUTLS_E value, and the session_status field is supposed to contain only a positive errno.

GNUTLS_E_PREMATURE_TERMINATION is -110. It turns out that on x86, -ETIMEDOUT is also -110. Make sure the correct symbolic constants and auditing functions are utilized.

Fixes b010190cfed2 ("tlshd: Pass ETIMEDOUT from gnutls to kernel")
---
 src/tlshd/handshake.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
src/tlshd/handshake.c +0 -0
index 5a2893994d4d..44932b7a5311 100644

src/tlshd/handshake.c void tlshd_start_tls_handshake(gnutls_session_t session, · line 93

Quoted 5 lines
src/tlshd/handshake.c +1 -1
@@ -90,19 +90,19 @@ void tlshd_start_tls_handshake(gnutls_session_t session,
 	} while (ret < 0 && !gnutls_error_is_fatal(ret));
 	tlshd_set_nagle(session, saved);
 	if (ret < 0) {
-		/* Any errors here should default to blocking access: */
+		/* By default, a handshake error is permanent */

I had forgotten that session_status is initially EIO, so my new comment makes less sense than what is there now. Will drop the comment change.

Quoted 19 lines
src/tlshd/handshake.c +4 -4
 		parms->session_status = EACCES;
 		switch (ret) {
 		case GNUTLS_E_CERTIFICATE_ERROR:
 		case GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR:
 			tlshd_log_cert_verification_error(session);
 			break;
-		case -ETIMEDOUT:
-			tlshd_log_gnutls_error(ret);
-			parms->session_status = -ret;
+		case GNUTLS_E_PREMATURE_TERMINATION:
+			tlshd_log_error("Handshake timeout, retrying");
+			parms->session_status = ETIMEDOUT;
 			break;
 		default:
-			tlshd_log_notice("tlshd_start_tls_handshake unhandled error %d, returning EACCES\n", ret);
+			tlshd_log_gnutls_error(ret);
 		}
 		return;
 	}
Signature · 1 line
Chuck Lever