Skip to content

Commit 0ac6636

Browse files
committed
tlshd: support setting the record size limit
RFC 8449 [1] Section 4 defines the record_size_limit TLS extension, which allows peers to negotiate a maximum plaintext record size during the TLS handshake. The value must be between 64 bytes and 16,384 bytes (2^14). If a TLS endpoint receives a record larger than its advertised limit, it must send a fatal record_overflow alert. This patch fetches maximum support send size as specified by the record size limit extension or as defined in GnuTLS, this value is then passed to the kernel through setsockopt() using the new TLS_TX_MAX_PAYLOAD_LEN option, such that the kernel can ensure outgoing records do not exceed the size specified. The respective kernel changes are currently applied to net-next [2]. [1] https://www.rfc-editor.org/rfc/rfc8449#section-4 [2] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=82cb5be6ad64198a3a028aeb49dcc7f6224d558a Signed-off-by: Wilfred Mallawa <[email protected]>
1 parent c85d09d commit 0ac6636

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ AC_CHECK_LIB([gnutls], [gnutls_get_system_config_file],
8585
AC_CHECK_LIB([gnutls], [gnutls_psk_allocate_client_credentials2],
8686
[AC_DEFINE([HAVE_GNUTLS_PSK_ALLOCATE_CREDENTIALS2], [1],
8787
[Define to 1 if you have the gnutls_psk_allocate_client_credentials2 function.])])
88+
AC_CHECK_LIB([gnutls], [gnutls_record_get_max_send_size],
89+
[AC_DEFINE([HAVE_GNUTLS_MAX_SEND_SIZE], [1],
90+
[Define to 1 if you have the gnutls_record_get_max_send_size function.])])
8891

8992
AC_MSG_CHECKING(for ML-DSA support in gnutls)
9093
AC_COMPILE_IFELSE(

src/tlshd/handshake.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,23 @@
4343
#include <gnutls/abstract.h>
4444

4545
#include <glib.h>
46+
#include <linux/tls.h>
4647

4748
#include "tlshd.h"
4849
#include "netlink.h"
4950

51+
#ifdef HAVE_GNUTLS_MAX_SEND_SIZE
52+
static void tlshd_set_record_size(gnutls_session_t session, uint16_t val)
53+
{
54+
int ret;
55+
56+
ret = setsockopt(gnutls_transport_get_int(session), SOL_TLS,
57+
TLS_TX_MAX_PAYLOAD_LEN, &val, sizeof(val));
58+
if (ret < 0)
59+
tlshd_log_perror("setsockopt (TLS_RX_RECORD_SIZE_LIM)");
60+
}
61+
#endif
62+
5063
/**
5164
* @brief Toggle the use of the Nagle algorithm
5265
* @param[in] session TLS session to modify
@@ -93,6 +106,9 @@ static void tlshd_save_nagle(gnutls_session_t session, int *saved)
93106
void tlshd_start_tls_handshake(gnutls_session_t session,
94107
struct tlshd_handshake_parms *parms)
95108
{
109+
#ifdef HAVE_GNUTLS_MAX_SEND_SIZE
110+
uint16_t max_send_size;
111+
#endif
96112
int saved, ret;
97113
char *desc;
98114

@@ -125,6 +141,10 @@ void tlshd_start_tls_handshake(gnutls_session_t session,
125141
gnutls_free(desc);
126142

127143
parms->session_status = tlshd_initialize_ktls(session);
144+
#ifdef HAVE_GNUTLS_MAX_SEND_SIZE
145+
max_send_size = gnutls_record_get_max_send_size(session);
146+
tlshd_set_record_size(session, max_send_size);
147+
#endif
128148
}
129149

130150
/**

0 commit comments

Comments
 (0)