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

i#2144: better patch for single step with sandboxing #2586

Merged
merged 4 commits into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions core/arch/mangle_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,11 +1016,15 @@ mangle(dcontext_t *dcontext, instrlist_t *ilist, uint *flags INOUT,
mangle_possible_single_step(dcontext, ilist, instr);
continue;
}
else if (dcontext->single_step_addr != NULL &&
else if (dcontext->single_step_addr != NULL && instr_is_app(instr) &&
dcontext->single_step_addr == instr->translation) {
mangle_single_step(dcontext, ilist, *flags, instr);
/* Resets to generate single step exception only once. */
dcontext->single_step_addr = NULL;
instr_t * last_addr = instr_get_next_app(instr);
/* Checks if sandboxing added another app instruction. */
if (last_addr == NULL || last_addr->translation != instr->translation) {
mangle_single_step(dcontext, ilist, *flags, instr);
/* Resets to generate single step exception only once. */
dcontext->single_step_addr = NULL;
}
}
#endif
#ifdef FOOL_CPUID
Expand Down
11 changes: 9 additions & 2 deletions suite/tests/security-win32/singlestep.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ main(void)
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) our_top_handler);

print("start of test, count = %d\n", count);
protect_mem(foo, 1024, ALLOW_READ|ALLOW_WRITE|ALLOW_EXEC);
count+=foo();
print("end of test, count = %d\n", count);

Expand All @@ -78,12 +79,18 @@ main(void)
START_FILE

/* int foo()
* Generates a single step execution on jump and should return 1.
* Generates a single step execution on jump and should return 2.
*/
#define FUNCNAME foo
DECLARE_FUNC(FUNCNAME)
GLOBAL_LABEL(FUNCNAME:)
xor eax, eax
/* sets sandoxing mode in dynamorio by doing a self modification. */
mov REG_XAX, HEX(1)
lea REG_XDX, SYMREF(sandbox_immediate_addr_plus_four - 4)
mov DWORD [REG_XDX], eax /* selfmod write */
mov REG_XDX, HEX(0) /* mov_imm to modify */
ADDRTAKEN_LABEL(sandbox_immediate_addr_plus_four:)
mov REG_XAX, REG_XDX
/* push flags on the stack */
PUSHF
/* setting the trap flag to 1 on top of the stack */
Expand Down
2 changes: 1 addition & 1 deletion suite/tests/security-win32/singlestep.expect
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
start of test, count = 0
single step exception
end of test, count = 2
end of test, count = 3