Reject empty ALPN protocol list in mbedtls_ssl_conf_alpn_protocols() - #10825
Open
94xhn wants to merge 1 commit into
Open
Reject empty ALPN protocol list in mbedtls_ssl_conf_alpn_protocols()#1082594xhn wants to merge 1 commit into
94xhn wants to merge 1 commit into
Conversation
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 Mbed-TLS#10461 Signed-off-by: yi chen <94xhn1@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #10461.
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 alreadyNULL) makes the loop body never execute, so it's silently accepted. The list is later used as-is byssl_write_alpn_ext()to build the ALPN extension, producing aprotocol_name_listof length 0.RFC 7301 §3.1 requires the ALPN extension's
protocol_name_listto contain at least one entry — a zero-length list isn't a valid encoding. Peers that correctly validate the extension respond with a fataldecode_erroralert, breaking the handshake, as described in the issue.Fix
Following the direction from @davidhorstmann-arm on the issue, 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) rather than silently unsetting the list later.Testing
I don't have the test suite building locally right now (this repo's ASN.1/crypto internals now live in the
tf-psa-cryptosubmodule, and I didn't want to stand up the full CMake build just for this), so I can't provide atest_suite_sslrun. What I did instead: extracted the exact validation logic into a standalone host-C reproduction and confirmed:{NULL}) returns0(accepted).MBEDTLS_ERR_SSL_BAD_INPUT_DATA; a real, non-empty list ({"h2", NULL}) is unaffected and still returns0.Added a
ChangeLog.dentry perCONTRIBUTING.md. Happy to add a propertest_suite_sslcase callingmbedtls_ssl_conf_alpn_protocols()directly with an empty list if that's wanted before merge — I didn't see an existing direct unit test for this function to model one on, so wanted to check the preferred style first rather than guess.Generative AI
I used generative AI tools when creating this PR, but a human has checked the code and is responsible for the code and the description above.