Skip to content

EEFS_LibInitFS: detect pointer-arithmetic wrap on EEPROM offsets - #11

Open
nurdymuny wants to merge 2 commits into
nasa:masterfrom
nurdymuny:fix/inode-init-offset-overflow
Open

nurdymuny wants to merge 2 commits into
nasa:masterfrom
nurdymuny:fix/inode-init-offset-overflow

Conversation

@nurdymuny

Copy link
Copy Markdown

Summary

EEFS_LibInitFS() adds the EEPROM-loaded FreeMemoryOffset / FileHeaderOffset to BaseAddress with no sanity check. On a 32-bit flight CPU the unsigned addition wraps when the offset is high-bits set (0xFFFFFFFF from a corrupted EEPROM image or SEU flip), and subsequent writes through FreeMemoryPointer / FileHeaderPointer scribble on arbitrary memory.

Closes #10.

Fix

For each pointer-arithmetic, compute the sum in uintptr_t and compare against the base; if the sum is less than the base, the unsigned addition wrapped and we reject the EEPROM as EEFS_NO_SUCH_DEVICE — the same status the existing "invalid file allocation table" path returns.

Diff

 libraries/eepromfs/eefs_fileapi.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

Tests

  • Manual: hand-built an EEPROM image with FreeMemoryOffset = 0xFFFFFFFF, mounted via the standalone driver on a 32-bit build; before the fix this corrupted heap on next EEFS_Create; after the fix the mount fails cleanly with EEFS_NO_SUCH_DEVICE.
  • Same with FileHeaderOffset on a per-file entry.
  • Normal (well-formed) EEPROM images still mount successfully — the wrap check only fires on actual wraparound.

Scope

The same shape exists in tools/eefstool/src/eefs_fileapi.c (the eefstool variant). Same fix applies; I left it out of this PR to keep the review small, happy to extend if you want.

nurdymuny added 2 commits June 9, 2026 06:49
The FreeMemoryOffset and per-file FileHeaderOffset fields are loaded
from EEPROM (untrusted on a corrupted, tampered, or single-event-
upset-flipped image). The previous code added them directly to
BaseAddress with no sanity check; on 32-bit flight CPUs that can
wrap around 2^32 and the resulting pointer ends up scribbling on
arbitrary memory on the next write through FreeMemoryPointer or
FileHeaderPointer.

The validators check Magic, Version, and NumberOfFiles but leave
the offset fields uninspected. This commit adds a wrap-check on
each addition by computing the sum in uintptr_t and comparing
against the base address; if the sum is below the base the offset
wrapped and we reject the EEPROM with EEFS_NO_SUCH_DEVICE, same
status the existing 'invalid file allocation table' path returns.
scj-hunt's per-target eefs catalog flagged this function at score 7.4 —
same bug class as EEFS_LibInitFS (already fixed earlier in this PR):
pointer arithmetic on BaseAddress + EEFS-loaded uint32 offset with no
wrap check. MicroEEFS is the lighter-weight variant used in bootstrap
code, so this lives on the same flight CPU and shares the corrupted-
EEPROM threat model.

Applied the identical uintptr_t-cast + 'below base' wrap-check pattern.
The two EEFS_LIB_EEPROM_READ calls for FileHeader are merged into one
guarded block since they use the same computed offset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integer overflow in EEFS_LibInitFS pointer arithmetic (EEPROM offsets)

1 participant