Fix buffer overreads on malformed inputs in sample programs - #10852
Open
felipereyesmurcia wants to merge 1 commit into
Open
Fix buffer overreads on malformed inputs in sample programs#10852felipereyesmurcia wants to merge 1 commit into
felipereyesmurcia wants to merge 1 commit into
Conversation
Fixes Mbed-TLS#10803. Signed-off-by: Felipe Reyes Murcia <felipereyesmurcia@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.
Fixes #10803.
Description
This fixes the two memory errors reported in #10803, both in sample programs (not in the library).
ssl_server2.c —
dummy_ticket_parse()length underflow. Tickets written bydummy_ticket_write()start with a 4-byte lifetime header, so the parser calledmbedtls_ssl_session_load(session, buf + 4, len - 4)unconditionally. A remote client can send a ticket shorter than 4 bytes;lenis asize_t, solen - 4underflows and the loader reads past the end of the ticket buffer. The fix rejects tickets shorter than 4 bytes withMBEDTLS_ERR_SSL_BAD_INPUT_DATAbefore the subtraction.ssl_context_info.c —
strlen()on non-null-terminated ALPN data. The tool calledstrlen()on the serialized ALPN name, which is stored as exactlyalpn_lenbytes with no terminator, so a crafted input file made it read past the decoded buffer. The fix reads exactlyalpn_lenbytes, usingmemchr()to detect an embedded null (still reported as "ALPN negotiation is incorrect") and printing with"%.*s".Verified with Valgrind before and after each fix: the ALPN "uninitialised value ... strlen" error and the ticket "Invalid read of size 4 ... 3 bytes after a block of size 1" both disappear after the change. Both sample programs rebuild with no new warnings.
PR checklist