On some machines of linux x86_64, dlopen() may use movaps instruction, and this requires the target memory (often the stack) to be properly aligned. If not, it will crash the program.
For example, on my machine, the injection failed with this error:
instead of expected SIGTRAP, target stopped with signal 11: Segmentation fault
sending process 9862 a SIGSTOP signal for debugging purposes
Then after I attached gdb to the injected process. I found it stopped at movaps instruction
On some machines of linux x86_64, dlopen() may use movaps instruction, and this requires the target memory (often the stack) to be properly aligned. If not, it will crash the program.
For example, on my machine, the injection failed with this error:
Then after I attached gdb to the injected process. I found it stopped at movaps instruction
and current RSP is 0x7ffe3049fb78. It is not aligned as required.
You can find movaps's alignment issue in detail here: https://www.felixcloutier.com/x86/movaps
Adding a
and $0xfffffffffffff000, %rsp \n
to the beginning of the shellcode should fix this.