Fix KWS NODE_MEMREQ instance header underallocation#95
Open
goyalpalak18 wants to merge 1 commit intoeembc:mainfrom
Open
Fix KWS NODE_MEMREQ instance header underallocation#95goyalpalak18 wants to merge 1 commit intoeembc:mainfrom
goyalpalak18 wants to merge 1 commit intoeembc:mainfrom
Conversation
Signed-off-by: goyalpalak18 <goyalpalak1806@gmail.com>
Author
|
Hey @llefaucheur @joseph-yiu, could you take a look at this when you have a chance? Thanks! |
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.
While looking at the recent ABF memory patch (commit edc44cf), I noticed the exact same under-allocation bug exists in the KWS component.
The Bug
In
src/ee_kws.c,NODE_MEMREQallocates memory using a magic number:sizeof(mfcc_instance_t) + 8. The+ 8was probably meant to cover two 32-bit pointers, but it ignores thechunk_idxfield entirely and breaks on 64-bit platforms (where pointers are 8 bytes). There's literally a/* TODO : justift this */comment sitting right next to it.Because of this, the
kws_instance_tstruct overflows its heap block. This eats into the 12-byte CMSIS vectorized-read safety padding, leading to undefined behavior. On 64-bit RISC-V evaluation targets, this overflow can silently corrupt heap metadata or cause sliding window drifts that completely invalidate benchmark scores.The Fix
I mirrored the ABF fix by replacing the manual calculation with a standard
sizeof(kws_instance_t). Since the struct already includesmfcc_instance_tas its first member, this naturally accounts for all pointers,chunk_idx, and any compiler-inserted alignment padding across all architectures and pointer widths.This restores the full CMSIS 12-byte guard padding, eliminates the undefined behavior risk, and brings KWS up to the same correctness baseline as ABF.