Fix integer overflow in _wc_Hash_Grow and TI hashUpdate#9984
Closed
Scottcjn wants to merge 1 commit intowolfSSL:masterfrom
Closed
Fix integer overflow in _wc_Hash_Grow and TI hashUpdate#9984Scottcjn wants to merge 1 commit intowolfSSL:masterfrom
Scottcjn wants to merge 1 commit intowolfSSL:masterfrom
Conversation
Both _wc_Hash_Grow() and hashUpdate() compute buffer sizes via unchecked addition of used + inSz/len. If used is near UINT32_MAX, the sum wraps to a small value, causing a small allocation followed by a large memcpy — a heap buffer overflow. Fix: use WC_SAFE_SUM_WORD32() to check for overflow before the addition, consistent with the fix applied in wolfSSL#9954 for SE050. Affects: - wolfcrypt/src/hash.c: _wc_Hash_Grow() (WOLFSSL_HASH_KEEP) - wolfcrypt/src/port/ti/ti-hash.c: hashUpdate() (WOLFSSL_TI_HASH) Fixes wolfSSL#9955 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Can one of the admins verify this patch? |
Author
|
Thanks @dgarske — confirmed #9954 covers the same overflow in hash.c and ti-hash.c with WC_SAFE_SUM_WORD32. Same bug, your preferred fix style. Glad the pattern got caught across all three paths. Our other PR #9932 (POWER8 AES vcipher pipeline) is independent — still hoping that makes a future release. |
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
Fix integer overflow in hash buffer size computation that could lead to heap buffer overflow.
Problem
Both
_wc_Hash_Grow()(hash.c) andhashUpdate()(ti-hash.c) compute the new buffer size asused + inSzwithout overflow checking. Ifusedis nearUINT32_MAX, the addition wraps to a small value, causing:XMALLOCwith wrapped size)XMEMCPYwith originalinSz) → heap overflowSame pattern as the SE050 fix in #9954.
Fix
Use
WC_SAFE_SUM_WORD32()to detect overflow before the addition:Then use
newSzfor all allocation and length comparisons.Files Changed
wolfcrypt/src/hash.c—_wc_Hash_Grow()(requiresWOLFSSL_HASH_KEEP)wolfcrypt/src/port/ti/ti-hash.c—hashUpdate()(requiresWOLFSSL_TI_HASH)Severity
Low — requires ~4GB of hash input to trigger, which will OOM on most systems first. But defense-in-depth is the right call, and this keeps the codebase consistent with the SE050 fix.
Fixes #9955
CLA: Previously signed (on file from PR #9932).