John Byrd privately reported a crash in AES under Microsoft compilers due to use of _malloca, AliasedWithTables and _freea. _malloca and _freea are Microsoft SDLC functions (alloca is on Microsoft's SDLC banned function list). Microsoft sometimes uses the heap rather than the stack for _malloca, and that's the reason _freea is needed.
The bug is specific to Windows and Microsoft compilers because its guarded by _MSC_VER. The bug does not affect Unix and Linux; and does not affect non-Microsoft compilers, like ICC and Borland. The bug was introduced at Commit 823bc93357da32a3 and only affects Crypto++ 5.6.4.
The code in question asks _malloca for a block of memory. The code also over-commits the size and adjust the pointer to a 256-byte boundary. The pointer is sent AliasedWithTables to flush cache lines. If AliasedWithTables cannot perform the flush, then it returns false. Upon the false return, the code reallocates, adjusts the pointer and calls AliasedWithTables again. Eventually the call succeeds. After the code in question completes, it frees the adjusted pointer and not the original pointer using _freea.
We believe we failed to detect the issue during testing because the pointer did not require adjustment. We got [un]lucky, but Byrd's testing revealed it.
Fortune favored us, and we picked up Byrd's suggestion of avoiding unaligned data access last week at at Commit f57c4dced5bfbcd1. The issue is side stepped "out of the box" in Master. However, an unsuspecting user could wander back into the configuration.
We immediately disclosed the memory bug so decision makers could assess the risk, provide feedback, and select a remediation commensurate with the security posture and comfort level:
John Byrd privately reported a crash in AES under Microsoft compilers due to use of
_malloca,AliasedWithTablesand_freea._mallocaand_freeaare Microsoft SDLC functions (allocais on Microsoft's SDLC banned function list). Microsoft sometimes uses the heap rather than the stack for_malloca, and that's the reason_freeais needed.The bug is specific to Windows and Microsoft compilers because its guarded by
_MSC_VER. The bug does not affect Unix and Linux; and does not affect non-Microsoft compilers, like ICC and Borland. The bug was introduced at Commit 823bc93357da32a3 and only affects Crypto++ 5.6.4.The code in question asks
_mallocafor a block of memory. The code also over-commits the size and adjust the pointer to a 256-byte boundary. The pointer is sentAliasedWithTablesto flush cache lines. IfAliasedWithTablescannot perform the flush, then it returns false. Upon the false return, the code reallocates, adjusts the pointer and callsAliasedWithTablesagain. Eventually the call succeeds. After the code in question completes, it frees the adjusted pointer and not the original pointer using_freea.We believe we failed to detect the issue during testing because the pointer did not require adjustment. We got [un]lucky, but Byrd's testing revealed it.
Fortune favored us, and we picked up Byrd's suggestion of avoiding unaligned data access last week at at Commit f57c4dced5bfbcd1. The issue is side stepped "out of the box" in Master. However, an unsuspecting user could wander back into the configuration.
We immediately disclosed the memory bug so decision makers could assess the risk, provide feedback, and select a remediation commensurate with the security posture and comfort level: