Fix Linux hook/unhook crashes#16
Conversation
|
For 1, |
|
1 - In my case I just inject/eject my lib.so in the running process. So can't have any guarantees |
I would have another look over it |
|
Yes, you are right. Is there a method to check if it is in an edge? So that we don't need to modify 2 pages every time. |
|
I assume need to check what is the page size (I guess 4KB for most) and then check if (addr + length) % page < length then we know it overflows. Tho havent checked how exactly paging works. Allocating 2 pages just solve the issue |
|
I would prefer to use a more precise method to modify the memory attributes. If you're willing to provide the code, please make the changes directly in the PR. Otherwise, I will try to modify it myself later. |
While using the lib I noticed 3 issues.
I call hook/unhook with ptrace so there is a risk that code is currently in the trampoline. If that is the case it crashes.
LEAVE_TRAMPOLINEsolves itThere is a chance that when we do
mprotectaligned to page that trampoline code goes in next page as well.Changed protection to next page as well
I'm not too sure about this one, but
movapsrequires stack to be aligned at 0x16 bytes. Windows programs compile to it by default, but not linux.movupsdoesnt need that