Nginx crashes with hardened_malloc on Alpine
I am testng nginx 1.26.2 on Alpine Linux 3.21 with hardened_malloc from the Alpine testing repos invoked by an OpenRC unit file using
LD_PRELOAD="/usr/lib/libhardened_malloc.so"
I get "Illegal instruction" immediatly upon starting the service and dmesg shows:
traps: nginx[30059] trap invalid opcode ip:7f5f5ecb1c80 sp:7ffd967b1768 error:0 in libhardened_malloc.so[2c80,7f5f5ecb1000+5000]
What can be the issue here?
Need to build it with CONFIG_NATIVE=false if you're using it another machine. Is that the issue?
This was not the issue. I could get it to run (not exiting throwing above error) by setting CPU type to "host" on my hypervisor. Though, I can not get any apps to use libhardened_malloc.so by setting LD_PRELOAD environment variable. Either by invoking directly or setting the variable in OpenRC unit files.
# ./preload.sh vi &
[2] 817
# ldd /usr/bin/vi
/lib/ld-musl-x86_64.so.1 (0x7eee57f4f000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7eee57f4f000)
Edit:
After setting export LD_PRELOAD=/usr/lib/libhardened_malloc.so in /etc/profile and rebooting, running ldd /usr/sbin/nginx shows:
# ldd /usr/sbin/nginx | grep malloc
/usr/lib/libhardened_malloc.so => /usr/lib/libhardened_malloc.so (0x7fc836da2000)
Does this mean the library is loaded and used by nginx?
lsof | grep malloc returns nothing.
I have tried both from the Alpine repository and by cloning this repo and building while setting CONFIG_NATIVE=false