Skip to content

Fix out-of-bounds memory accesses#35

Merged
danirod merged 1 commit into
danirod:develfrom
DavidBuchanan314:devel
Jun 23, 2022
Merged

Fix out-of-bounds memory accesses#35
danirod merged 1 commit into
danirod:develfrom
DavidBuchanan314:devel

Conversation

@DavidBuchanan314

@DavidBuchanan314 DavidBuchanan314 commented Jun 23, 2022

Copy link
Copy Markdown
Contributor

If I ends up greater than 0xfff, then the memory array can be indexed out-of-bounds (e.g. repeated use of the ADD I, Vx instruction). This is a security vulnerability. A malicious ROM can leverage this to escape the emulator, and execute arbitrary native code on the host system.

I noticed this comment in cpu.h:

chip8/src/lib8/cpu.h

Lines 49 to 54 in d952e57

/**
* This is the maximum amount of memory addressable by the machine.
* It should be used as a bitmask when overflows could possibly happen
* due to memory address management.
*/
#define ADDRESS_MASK 0xFFF

However, this ADDRESS_MASK constant is never used anywhere! So, I used it to add masking to all memory reads and writes, fixing the vulnerability.

@danirod

danirod commented Jun 23, 2022

Copy link
Copy Markdown
Owner

That is true, good caught, thanks.

@danirod danirod merged commit 1fc1679 into danirod:devel Jun 23, 2022
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.

2 participants