fix - security : prevent OOB write in decrypt() for non-multiple-of-16 src_len#2069
Open
9hozt wants to merge 1 commit intomeshcore-dev:mainfrom
Open
fix - security : prevent OOB write in decrypt() for non-multiple-of-16 src_len#20699hozt wants to merge 1 commit intomeshcore-dev:mainfrom
9hozt wants to merge 1 commit intomeshcore-dev:mainfrom
Conversation
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.
Problem
Utils::decrypt()checks only that the start of the current block is withinbounds, but
aes.decryptBlock()always writes 16 bytes. Ifsrc_lenis nota multiple of 16, the last partial block causes an out-of-bounds write into
adjacent memory.
By brute-forcing the 2-byte HMAC (65,536 possible values, ~32,768 attempts on average for a 50% success rate), it is possible to craft and inject arbitrary messages outside of the official app.
Example with src_len=182:
176 < 182is truedecryptBlock()writes dest[176..191]The header comment in Utils.h:40 states that
src_lenshould be a multipleof block size, but this precondition was not enforced in the implementation.
Fix
Change the loop condition to verify that a full 16-byte block is available
before attempting to decrypt it:
while (sp - src < src_len)while (sp - src + 16 <= src_len)Impact
No behavioral change for legitimate messages —
encrypt()always outputsa multiple of 16, so
decrypt()always receives a valid multiple of 16 innormal operation. The fix only affects malformed inputs.