fix(ktls): Validate record type in s2n_ktls_recvmsg - #6030
Open
alexw91 wants to merge 1 commit into
Open
Conversation
boquan-fang
approved these changes
Aug 10, 2026
jmayclin
self-requested a review
August 10, 2026 21:49
alexw91
force-pushed
the
ktls-record-validation
branch
from
August 10, 2026 22:05
dc8f4fc to
b501a6b
Compare
Reject unexpected TLS ContentType values received via kTLS ancillary data. Only alert (21), handshake (22), and application_data (23) are valid post-handshake record types. All other values now fail with S2N_ERR_BAD_MESSAGE per RFC 8446 Section 5. Add an exhaustive unit test that injects all 256 possible byte values as the record type and verifies the accept/reject behavior.
alexw91
force-pushed
the
ktls-record-validation
branch
from
August 10, 2026 23:06
b501a6b to
a063ced
Compare
jmayclin
reviewed
Aug 11, 2026
jmayclin
left a comment
Contributor
There was a problem hiding this comment.
This kind feels like the wrong place to handle this. All of the record types eventually bubble up through s2n_read_full_record, so I'd think that any validation we're doing should probably just be done there?
Also it might be easier to pause this until #6017, since that actually does some similar assertion cleanup?
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.
Goal
Validate the TLS ContentType received via kTLS ancillary data in
s2n_ktls_recvmsg.Why
RFC 8446 Section 5: "If a TLS implementation receives an unexpected record type, it MUST terminate the connection with an 'unexpected_message' alert."
How
Range check after extracting the record type from the control message. Only values 21–23 (alert, handshake, application_data) are accepted. All others fail with
S2N_ERR_BAD_MESSAGE.Testing
Exhaustive test iterating all 256 byte values as the record type. Values {21, 22, 23} succeed; all others are rejected.
Related
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.