From: Martin Belanger Date: Mon, 30 Nov 2026 06:32:00 -0500 Subject: [PATCH] tlshd: allow kernels without TLS_TX_MAX_PAYLOAD_LEN MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-tx-payload-len-fallback-v1-1-b52dcfb18f15@gmail.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yXMQQ6CMBBA0auQWTtJB1OIXsW4mJYBBptCWjQYw t2tunyL/3fIklQyXKsdkrw06xwL6FSBHzkOgtoVQ23qhuhscN1w4XeYucMgEXsOwbF/IF2Ms2Q b620LpV6S9Lr9zrf73/npJvHrdwfH8QGGueK7ewAAAA== X-Change-ID: 20261130-tx-payload-len-fallback-190b51565c57 To: kernel-tls-handshake@lists.linux.dev Cc: Chuck Lever , Wilfred Mallawa , Martin Belanger X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796038321; l=2842; i=martin.nvme.dev@gmail.com; s=20261014; h=from:subject:message-id; bh=igwt2yLXsYdPVeU7tiz3F1aaNMKMQjsF68syMOLAfVw=; b=oRwOwMAcyzONgcHwPotAhltwAeZYHFo00AbWqejYAXEzZx0nfaY7y1qa651lPycbPUDFJEVq3 FJwWUnfWbV1DrFI3vewOK7qLlAvVXzVcJaf9fiAKnkYZf7R4QtqmrsS X-Developer-Key: i=martin.nvme.dev@gmail.com; a=ed25519; pk=4K+XXetGK35w2LzRRddd/bbHawZU222BN+YZRuSpN+k= X-Endpoint-Received: by B4 Relay for martin.nvme.dev@gmail.com/20261014 with auth_id=1176 List-Id: B4 Relay Submissions From: Martin Belanger configure detects TLS_TX_MAX_PAYLOAD_LEN in the installed kernel headers. A kernel older than 6.19 rejects the option with ENOPROTOOPT, and tlshd then fails every handshake. Distributions often ship newer headers than the running kernel. Ignore ENOPROTOOPT when the peer did not negotiate a record size limit below 2^14 bytes. The kernel then sends records of at most 2^14 bytes, which the peer accepts. If the peer asked for smaller records, the error stays fatal. Fixes: c1610edc2f08 ("tlshd: support setting the record size limit") Link: https://github.com/linux-nfs/ktls-utils/issues/63 Signed-off-by: Martin Belanger --- Tested in a VM with nvme-tcp TLS to a loopback nvmet target, tlshd built against 7.x kernel headers: - 6.18.63: without the patch, the handshake fails ("setsockopt (TLS_TX_MAX_PAYLOAD_LEN): Protocol not available"). With the patch, the connect succeeds. - 7.3.4: with the patch, the option is set and the connect succeeds. Not tested: a peer that negotiates a smaller record_size_limit on an old kernel. That case still fails, as intended. --- src/tlshd/ktls.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tlshd/ktls.c b/src/tlshd/ktls.c index 07651bc..2251753 100644 --- a/src/tlshd/ktls.c +++ b/src/tlshd/ktls.c @@ -348,18 +348,30 @@ static bool tlshd_set_chacha20_poly1305_info(gnutls_session_t session, int sock, #endif #if defined(HAVE_GNUTLS_RECORD_GET_MAX_SEND_SIZE) && defined(HAVE_TLS_TX_MAX_PAYLOAD_LEN) +/* RFC 8446, Section 5.1: largest TLSPlaintext.fragment */ +#define TLSHD_MAX_PLAINTEXT 16384 + static int tlshd_set_record_size(gnutls_session_t session) { - uint16_t max_send_size; + size_t limit = gnutls_record_get_max_send_size(session); + uint16_t max_send_size = limit; int ret; - max_send_size = gnutls_record_get_max_send_size(session); /* For TLS 1.3 kernel expects us to account for the ContentType */ if (gnutls_protocol_get_version(session) == GNUTLS_TLS1_3) max_send_size -= 1; ret = setsockopt(gnutls_transport_get_int(session), SOL_TLS, TLS_TX_MAX_PAYLOAD_LEN, &max_send_size, sizeof(max_send_size)); + if (ret < 0 && errno == ENOPROTOOPT && limit >= TLSHD_MAX_PLAINTEXT) { + /* + * The kernel predates TLS_TX_MAX_PAYLOAD_LEN. It sends + * records of up to 2^14 bytes, which the peer accepts + * because it did not ask for a smaller record size limit. + */ + tlshd_log_debug("kernel does not support TLS_TX_MAX_PAYLOAD_LEN"); + return 0; + } if (ret < 0) tlshd_log_perror("setsockopt (TLS_TX_MAX_PAYLOAD_LEN)"); --- base-commit: e957590189ea88663dee97348dd42a5dceb4a6ef change-id: 20261130-tx-payload-len-fallback-190b51565c57 Best regards, -- Martin Belanger