Fix correctness bugs: NULL symbol deref, register-buffer overflow, memory-range calculation - #1
Open
HeavenlyDevv wants to merge 1 commit into
Conversation
…unds, memory-range calculation Three pre-existing bugs in the fault-injection flow, fixed independently of any RISC-V feature work: 1. intercept.c: getSymbolValue() and the serviceHandler variable-trace paths dereferenced a NULL symbol (vmirtGetSymbolAddr/Size/Name) when the traced symbol did not exist, aborting the simulator. Guard every pointer and only read memory when the symbol is found (processor first, SMP-parent fallback). 2. commonStructsAndEnumerators.h + faultInjector.c: possibleRegisters[50] is too small for the ARMv8 list (int+SIMD+END = 66 entries) and overflows in the strcpy copy loop. Size it via MAX_REGISTERS (80) and clamp the loop count so the write can never run past the array. 3. FI.sh: the memory-range block passed FlashSize (a size) as the high address and read RAMEnd from a non-existent .heap section. Compute FlashEnd = EntryAddress + FlashSize and RAMEnd = RAMDataAddress + RAMBSSSize. Verified: all three compile cleanly (-Werror) against a fresh clone of the extensions branch.
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
Three pre-existing correctness bugs in the fault-injection flow. Each is independent of any feature work and can be reviewed/merged on its own. All three compile cleanly (
-Werror) against a fresh clone ofextensions.Bug 1 — NULL symbol dereference aborts the simulator
What happens:
getSymbolValue()(and the variable-trace paths inserviceHandler) callvmirtGetSymbolAddr/Size(funcSymbol)before checking the symbol for NULL, and the "not found" branch callsvmirtGetSymbolName(funcSymbol)withfuncSymbol == NULL. If the traced symbol does not exist (e.g. a mistypedTRACE_VARIABLE), the run aborts:Fix: guard every pointer (
processor,symbolName,buffer,dataDomain,funcSymbol/varSymbol) and only read memory when the symbol is actually found — looking it up on the processor first, then on its SMP parent. Applied togetSymbolValue()and the five symbol-resolution paths inserviceHandler.platformOP/intercept/intercept.cBug 2 —
possibleRegisters[50]buffer overflowWhat happens:
initialize()copies the active architecture's register list into the global bufferpossibleRegisters[50][10]:possibleRegistersV8has 65 entries (x0..x30,sp,pc,v0..v31,END_LIST) — already more than 50 — so thestrcpywrites past the array and corrupts adjacent global memory.Fix: size the buffer through a named
MAX_REGISTERS(80) and clamp the loop count in each of the three copy loops so the write can never run past the array.platformOP/commonStructsAndEnumerators.h,platformOP/harness/faultInjector.cBug 3 — Memory-range calculation (size used as address,
.heapdoesn't exist)What happens: the baremetal memory-range block passes
--memhighaddress=$FlashSize— the section size — where an end address is expected, and readsRAMEndfrom a.heapsection that does not exist in typical baremetal binaries (so it comes out empty). A memory campaign then gets an empty or negative range.Example (
.textat0x10120, size0x7d4, no.heap):[65824 .. <empty>](RAMEnd from absent.heap)[65824 .. 2004]→ span −63820 (size used as address)[65824 .. 67828]span 2004 (=.textsize)Fix: compute
FlashEnd = EntryAddress + FlashSizeandRAMEnd = RAMDataAddress + RAMBSSSize.FI.shValidation
All three fixes compile cleanly under
-Werrorin the OVP environment against a freshextensionscheckout. ARM code paths are unaffected — the changes only correct incorrect behavior, they do not alter control flow.