Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix target crash issue caused by movaps alignment requirement #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CubicStone31
Copy link

@CubicStone31 CubicStone31 commented Feb 23, 2022

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

   0x7f4d7be675cc:      mov    %r12,0x30(%rsp)
   0x7f4d7be675d1:      movhps 0xb0(%rsp),%xmm0
   0x7f4d7be675d9:      mov    %ebp,0x38(%rsp)
=> 0x7f4d7be675dd:      movaps %xmm0,0x60(%rsp)
   0x7f4d7be675e2:      movq   $0x0,0x48(%rsp)
   0x7f4d7be675eb:      mov    %rbx,0x50(%rsp)

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.

Copy link

@justanothermatt justanothermatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solved my segfault problem as well and would explain multiple issues on the issue board. This should be pulled asap

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