From f0422f56d11ab3f4d9cde32fb38ab074bd5c88d7 Mon Sep 17 00:00:00 2001 From: yi chen <94xhn1@gmail.com> Date: Fri, 10 Jul 2026 08:05:51 +0800 Subject: [PATCH] Reject empty ALPN protocol list in mbedtls_ssl_conf_alpn_protocols() mbedtls_ssl_conf_alpn_protocols() validates that no individual protocol name is empty or too long, but never checked that the list itself has at least one entry. Configuring an empty list (a NULL-terminated array whose first element is already NULL) was silently accepted, and the list is later used as-is by ssl_write_alpn_ext() to build the ALPN extension - producing a protocol_name_list of length 0. RFC 7301 3.1 requires the ALPN extension's protocol_name_list to contain at least one entry; a zero-length list is not a valid encoding. Peers that correctly validate the extension respond with a fatal decode_error alert, breaking the handshake. Reject an empty list up front with MBEDTLS_ERR_SSL_BAD_INPUT_DATA, matching how this function already rejects other invalid inputs (empty individual protocol names, names or total length exceeding the configured maximums). Fixes #10461 Signed-off-by: yi chen <94xhn1@gmail.com> --- ChangeLog.d/fix-alpn-empty-list.txt | 7 +++++++ library/ssl_tls.c | 10 ++++++++++ 2 files changed, 17 insertions(+) create mode 100644 ChangeLog.d/fix-alpn-empty-list.txt diff --git a/ChangeLog.d/fix-alpn-empty-list.txt b/ChangeLog.d/fix-alpn-empty-list.txt new file mode 100644 index 0000000000..03b9345686 --- /dev/null +++ b/ChangeLog.d/fix-alpn-empty-list.txt @@ -0,0 +1,7 @@ +Bugfix + * Fix mbedtls_ssl_conf_alpn_protocols() silently accepting an empty + protocol list, which caused an invalid ALPN extension with a + zero-length protocol_name_list to be sent during the handshake, + violating RFC 7301 and causing conforming peers to reject the + connection with a fatal decode error. mbedtls_ssl_conf_alpn_protocols() + now returns MBEDTLS_ERR_SSL_BAD_INPUT_DATA for an empty list. diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 0195576213..dbebdf9c57 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -2526,6 +2526,16 @@ int mbedtls_ssl_conf_alpn_protocols(mbedtls_ssl_config *conf, size_t cur_len, tot_len; const char *const *p; + /* + * RFC 7301 3.1: the ALPN extension's protocol_name_list must contain + * at least one entry - an empty list is not a valid ProtocolNameList + * and must not be sent. Reject it here rather than silently sending + * an ALPN extension with a zero-length list later. + */ + if (*protos == NULL) { + return MBEDTLS_ERR_SSL_BAD_INPUT_DATA; + } + /* * RFC 7301 3.1: "Empty strings MUST NOT be included and byte strings * MUST NOT be truncated."