Skip to content

Commit d6dc859

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

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/Monkeypatcher.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ remote_code_ptr Monkeypatcher::get_jump_stub_exit_breakpoint(remote_code_ptr ip,
500500
--it;
501501
patched_syscall *ps = &syscall_stub_list[it->second];
502502
auto bp = it->first + ps->size - ps->safe_suffix;
503-
if (pp == bp - 4 || pp == bp - 8) {
504-
return remote_code_ptr((it->first + ps->size - 4).as_int());
503+
if (pp == bp - 4 || pp == bp - 8 || pp == bp - 12) {
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]

src/record_signal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ bool handle_syscallbuf_breakpoint(RecordTask* t) {
298298
LOG(debug) << "Reached syscallstub exit instruction, singlestepping to "
299299
"enable signal dispatch";
300300
ASSERT(t, t->arch() == aarch64 && t->syscallstub_exit_breakpoint);
301-
auto retaddr_addr = t->syscallstub_exit_breakpoint.to_data_ptr<uint8_t>() + 3 * 4;
301+
auto retaddr_addr = t->syscallstub_exit_breakpoint.to_data_ptr<uint8_t>() + 4;
302302
uint64_t retaddr;
303303
t->read_bytes_helper(retaddr_addr, sizeof(retaddr), &retaddr);
304304
Registers r = t->regs();

0 commit comments

Comments
 (0)