wire: bound decoded auth.token_size and num_sn to destination sizes#1243
Merged
Conversation
decode_buf() verifies that the source packet still holds the requested number of bytes, but not that the requested length fits the destination buffer. The REGISTER_SUPER / UNREGISTER_SUPER / REGISTER_SUPER_ACK / REGISTER_SUPER_NAK decoders read auth.token_size (a 16-bit field) and num_sn (an 8-bit count) directly from the wire and pass them to decode_buf() targeting fixed-size destinations: auth.token is N2N_AUTH_MAX_TOKEN_SIZE (48) bytes, and the REGISTER_SUPER_ACK backup list is bounded by REG_SUPER_ACK_PAYLOAD_SPACE. A length field larger than its destination therefore lets a malformed packet write past the end of the buffer. Validate token_size against N2N_AUTH_MAX_TOKEN_SIZE and num_sn against REG_SUPER_ACK_PAYLOAD_SPACE before calling decode_buf(), returning a decode error otherwise. A conforming peer never sends a larger value, so well-formed traffic is unaffected. Signed-off-by: Michael Bommarito <michael.bommarito@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.
decode_buf() checks that the source packet holds the requested number of bytes, but not that the requested length fits the destination buffer. The REGISTER_SUPER / UNREGISTER_SUPER / REGISTER_SUPER_ACK / REGISTER_SUPER_NAK decoders read auth.token_size (16-bit) and num_sn (8-bit) directly from the wire and pass them to decode_buf() targeting fixed-size destinations (auth.token is N2N_AUTH_MAX_TOKEN_SIZE = 48 bytes; the backup-supernode list is bounded by REG_SUPER_ACK_PAYLOAD_SPACE).
A length field larger than its destination lets a malformed packet write past the buffer. This validates token_size and num_sn against those limits before the copy and returns a decode error otherwise. Well-formed peers never send larger values, so legitimate traffic is unaffected.
Built clean with -Wall (no new warnings); tools/tests-wire passes.