Skip to content

Fix SuperscalarHash buffer overflows in the RISC-V vector JIT - #371

Open
thomasbuilds wants to merge 1 commit into
tevador:masterfrom
thomasbuilds:fix-riscv-vector-sshash-overflow
Open

thomasbuilds wants to merge 1 commit into
tevador:masterfrom
thomasbuilds:fix-riscv-vector-sshash-overflow

Conversation

@thomasbuilds

Copy link
Copy Markdown
Contributor

The RISC-V vector JIT compiles the SuperscalarHash programs into fixed areas of its template (512 IMUL_RCP literals in total and 8 KiB of code per Cache access) without checking that they fit. Larger values of RANDOMX_SUPERSCALAR_LATENCY or RANDOMX_CACHE_ACCESSES, which configuration.md permits, can need more (with 16 Cache accesses, about 0.8% of keys; with a latency of 500, every key), and the JIT then writes past them. On CPUs with VLEN ≥ 256 this crashes or hangs Dataset initialization and larger overflows also corrupt the JIT's other code or memory past its buffer, even at VLEN 128, where this code is generated but not run.

This checks the space while generating and, if a key's programs don't fit, uses the scalar Dataset init code for that key. Keys in the default configuration fit with a wide margin so they keep using the vector code which is unchanged. initCacheCompile now updates cache->datasetInit since the choice can change with the key.

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.

1 participant