Fix ARM ptrace compatibility and improve remote call safety (#94)
- Implement fallbacks to `PTRACE_GETREGS` and `PTRACE_SETREGS` for 32-bit ARM (`__arm__`). Some kernels return `EIO` or `EINVAL` when attempting to access `NT_PRSTATUS` via `PTRACE_GETREGSET`/`PTRACE_SETREGSET`. - Update `transfer_fd_to_remote` to use `libc_return_addr` instead of `0` as the return address during the `recvmsg` split-call. This ensures the remote process stops predictably at a known non-executable location rather than relying on a potentially unsafe jump to `0x0`. - Clarify comments regarding i386 argument passing in `utils.cpp`. Correctly note that a linear `write_proc` starting at the new SP matches the `cdecl` Right-to-Left memory layout (since stacks grow downwards while memory writes move upwards), removing the suggestion that arguments needed reversing.
This commit is contained in:
@@ -374,7 +374,7 @@ static std::optional<int> transfer_fd_to_remote(int pid, const char *lib_path, s
|
||||
|
||||
// 12. Initiate the remote recvmsg call. This will block the remote process.
|
||||
args = {static_cast<uintptr_t>(remote_fd), remote_hdr, MSG_WAITALL};
|
||||
if (!remote_pre_call(pid, regs, reinterpret_cast<uintptr_t>(funcs.recvmsg_addr), 0, args)) {
|
||||
if (!remote_pre_call(pid, regs, reinterpret_cast<uintptr_t>(funcs.recvmsg_addr), libc_return_addr, args)) {
|
||||
LOGE("Failed to initiate remote recvmsg call.");
|
||||
close_remote(remote_fd);
|
||||
return std::nullopt;
|
||||
@@ -414,7 +414,7 @@ static std::optional<int> transfer_fd_to_remote(int pid, const char *lib_path, s
|
||||
|
||||
// 15. Complete the remote recvmsg call. This will retrieve the return value.
|
||||
auto recvmsg_result =
|
||||
static_cast<ssize_t>(remote_post_call(pid, regs, 0)); // No specific expected return address for recvmsg
|
||||
static_cast<ssize_t>(remote_post_call(pid, regs, libc_return_addr));
|
||||
if (recvmsg_result == -1) {
|
||||
errno = get_remote_errno();
|
||||
PLOGE("Remote recvmsg call failed.");
|
||||
|
||||
Reference in New Issue
Block a user