Skip to content

Commit d332b52

Browse files
committed
Address Yichao's review
1 parent df8d55c commit d332b52

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/Monkeypatcher.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ remote_code_ptr Monkeypatcher::get_jump_stub_exit_breakpoint(remote_code_ptr ip,
501501
patched_syscall *ps = &syscall_stub_list[it->second];
502502
auto bp = it->first + ps->size - ps->safe_suffix;
503503
if (pp == bp - 4 || pp == bp - 8) {
504-
return remote_code_ptr((it->first + ps->size - 4).as_int());
504+
return remote_code_ptr((it->first + ps->size - 12).as_int());
505505
}
506506
return nullptr;
507507
}
@@ -717,13 +717,13 @@ bool patch_syscall_with_hook_arch<ARM64Arch>(Monkeypatcher& patcher,
717717
2 * 4,
718718
/**
719719
* safe_suffix:
720-
* We've returned from syscallbuf and continue execution
721-
* won't hit syscallbuf breakpoint
722-
* (this also include the 8 bytes that stores the return address)
723-
* Note that stack restore instruction also belongs to the syscallbuf return path
724-
* However, since it is still using the scratch memory,
725-
* it doesn't belong to the safe area.
726-
* The caller needs to have special handling for that instruction.
720+
* The safe suffix are all instructions that are no longer using syscallbuf
721+
* private stack memory. On aarch64, that is the bail path svc instruction
722+
* and the final jump instruction (including the 8 byte return address).
723+
* See the detailed extended jump patch assembly above for details.
724+
* Note that the stack restore instructions also occurr on the syscallbuf
725+
* return path, but are not considered part of the safe suffix, since they
726+
* still rely on the syscallbuf stack memory to function properly.
727727
*/
728728
2 * 4 + 8
729729
});

src/preload/syscall_hook.S

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,9 @@ retq
891891
_syscallbuf_code_start:
892892

893893
_syscall_hook_trampoline:
894-
// stack frame:
894+
// parent frame:
895+
// 0 (688): lr from the extended jump patch [this gets rewritten here in the bail path]
896+
// this stack frame:
895897
// 208-688: q2 - q31
896898
// 128-200: x10 - x18
897899
// 112-128: x7, x9
@@ -952,6 +954,7 @@ _syscall_hook_trampoline:
952954
cbnz x0, 1f
953955

954956
// If the function requested the bail path, rewrite the return address
957+
// N.B.: This modifies the stack address saved in the parent frame.
955958
ldr x0, [sp, 688]
956959
add x0, x0, 8
957960
str x0, [sp, 688]

0 commit comments

Comments
 (0)