OpenBSD amd64: RandomX JIT SIGSEGV reading execute-only text
Description
monerod v0.18.5.1 reproducibly crashes during initial synchronization when it reaches the RandomX activation height on OpenBSD 7.9/amd64.
The crash occurs while randomx::JitCompilerX86 copies randomx_program_prologue from the executable's text segment into its allocated JIT buffer.
Setting:
MONERO_RANDOMX_UMASK=8disables the RandomX JIT and allows synchronization to continue beyond the exact point where it previously crashed.
This appears to be an incompatibility between the RandomX JIT implementation and OpenBSD's execute-only text segments.
Possibly related to #10286, although that issue does not contain a RandomX JIT backtrace.
Environment
- OpenBSD 7.9 amd64
- Monero
v0.18.5.1-release - Built from source using the documented OpenBSD build process
- Running inside a Proxmox/QEMU VM
- CPU type:
host - 2 virtual CPUs
- 8 GB RAM
- 16 GB swap
- Pruned blockchain
- Daemon user:
_monero
Version output:
Monero 'Fluorine Fermi' (v0.18.5.1-release)The installed and build-tree binaries were verified to be identical:
SHA256 (/usr/local/sbin/monerod) = bc843268c824719f53029ca31121a93ce0e3efa1437207ab1c4be2ba3412cdbf
SHA256 (/usr/local/src/monero/build/OpenBSD/_no_branch_/release/bin/monerod) = bc843268c824719f53029ca31121a93ce0e3efa1437207ab1c4be2ba3412cdbfReproduction
Start synchronization from a blockchain state before the RandomX activation height.
The daemon synchronizes normally until approximately:
Synced 1978416/3746199The last relevant log entry is:
Validating txpool for v12The daemon then terminates with:
Segmentation fault (core dumped)Restarting from the same blockchain state reproduces the crash.
There was sufficient memory and swap available, and no out-of-memory or process-killed messages were present.
Backtrace
The core was inspected with GDB:
Core was generated by `monerod'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 memcpy (
dst0=0xa4c0fdb8000,
src0=<optimized out>,
length=256)
at /usr/src/lib/libc/string/memcpy.c:103
#1 randomx::JitCompilerX86::JitCompilerX86()
#2 randomx_alloc_cache()
#3 rx_alloc_cache()
#4 rx_set_main_seedhash_thread()
#5 _rthread_start()
#6 __tfork_thread()Relevant values:
dst = 0xa4c0fdb8000
src = 0xa49282377c0 <randomx_program_prologue>
length = 256The faulting instruction is the initial read from the source address:
=> movups (%rsi,%r14,8),%xmm0
movups 0x10(%rsi,%r14,8),%xmm1
movups %xmm0,(%r8,%r14,8)
movups %xmm1,0x10(%r8,%r14,8)Relevant registers:
rsi = 0xa49282377c0 <randomx_program_prologue>
rdi = 0xa4c0fdb8000
rdx = 0x100This suggests that the fault occurs while reading the JIT template from the executable text segment, before writing it to the destination buffer.
Analysis
OpenBSD enables execute-only binaries by default on amd64. On CPUs supporting the required protection-key functionality, executable text may be executed but cannot be read as ordinary data.
The RandomX JIT constructor appears to rely on executable text also being readable:
codeProloguepoints torandomx_program_prologue.- A writable JIT buffer is allocated.
memcpy(code, codePrologue, prologueSize)attempts to read the template from the executable text segment.- OpenBSD raises
SIGSEGVon the source read.
OpenBSD documents execute-only binaries here:
https://www.openbsd.org/73.html
This diagnosis is an inference from the backtrace, faulting instruction, source address and successful no-JIT workaround.
Workaround
Starting monerod with the following environment variable avoids the crash:
export MONERO_RANDOMX_UMASK=8With this setting, the daemon successfully passes the previous failure point and continues synchronizing.
For an OpenBSD rc.d service, I applied it through a matching login class:
monerod:\
:setenv=MONERO_RANDOMX_UMASK=8:\
:tc=daemon:Expected behavior
monerod should either:
- run the RandomX JIT correctly on OpenBSD;
- automatically disable the JIT when its implementation is incompatible with execute-only text; or
- fail gracefully with a useful diagnostic rather than segmentation-faulting.
A possible source-level solution may be to place the copied JIT templates in a readable section instead of assuming that executable text is readable. Building the entire executable with --no-execute-only might also avoid the crash, but would weaken OpenBSD's default hardening and seems less desirable.
Source: monero-project/monero