Skip to content

Commit

Permalink
i#2371: fix native exec regression on gateway vs entry checks (#2378)
Browse files Browse the repository at this point in the history
Split off the uses of is_native_pc() as a test for targets that should
not re-takeover as a new routine is_stay_native_pc().  Use of
dr_app_running_under_dynamorio() was broken in the presence of non-empty
native_exec_areas by 6a8d7d2, causing its execution to go native.

Fixes #2371
  • Loading branch information
derekbruening authored Apr 21, 2017
1 parent 9c48083 commit 96ea594
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 7 additions & 1 deletion core/native_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ is_dr_native_pc(app_pc pc)

bool
is_native_pc(app_pc pc)
{
return vmvector_overlap(native_exec_areas, pc, pc+1);
}

bool
is_stay_native_pc(app_pc pc)
{
/* only used for native exec */
ASSERT(DYNAMO_OPTION(native_exec) && !vmvector_empty(native_exec_areas));
return (is_dr_native_pc(pc) || vmvector_overlap(native_exec_areas, pc, pc+1));
return (is_dr_native_pc(pc) || is_native_pc(pc));
}

static bool
Expand Down
8 changes: 7 additions & 1 deletion core/native_exec.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2012 Google, Inc. All rights reserved.
* Copyright (c) 2012-2017 Google, Inc. All rights reserved.
* **********************************************************/

/*
Expand Down Expand Up @@ -53,6 +53,12 @@ native_exec_exit(void);
bool
is_native_pc(app_pc pc);

/* Includes regions where we execute natively as well as DR entry points where
* we should not re-takeover if we're already native.
*/
bool
is_stay_native_pc(app_pc pc);

/* Gets called on every call into a native module. */
void
call_to_native(app_pc *sp);
Expand Down
10 changes: 5 additions & 5 deletions core/unix/native_elf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2013-2014 Google, Inc. All rights reserved.
* Copyright (c) 2013-2017 Google, Inc. All rights reserved.
* **********************************************************/

/*
Expand Down Expand Up @@ -396,7 +396,7 @@ update_plt_relocations(module_area_t *ma, os_privmod_data_t *opd, bool add_hooks
* Either way we ignore it.
*/
/* We also ignore it if the PLT target is in a native module */
if (!module_contains_addr(ma, gotval) && !is_native_pc(gotval)) {
if (!module_contains_addr(ma, gotval) && !is_stay_native_pc(gotval)) {
LOG(THREAD_GET, LOG_LOADER, 4,
"%s: hooking cross-module PLT entry to "PFX"\n",
__FUNCTION__, gotval);
Expand Down Expand Up @@ -529,7 +529,7 @@ dynamorio_dl_fixup(struct link_map *l_map, uint reloc_arg)
__FUNCTION__, reloc_arg, res);
});
/* the target is in a native module, so no need to change */
if (is_native_pc(res))
if (is_stay_native_pc(res))
return res;
app_pc stub = create_plt_stub(res);
rel = find_plt_reloc(l_map, reloc_arg);
Expand Down Expand Up @@ -762,7 +762,7 @@ dr_app_handle_mbr_target(void *target)
void *stub;
if (!DYNAMO_OPTION(native_exec) || !DYNAMO_OPTION(native_exec_retakeover))
return target;
if (is_native_pc(target))
if (is_stay_native_pc(target))
return target;
stub = create_plt_stub(target);
return native_module_htable_add(native_mbr_table, plt_stub_heap,
Expand Down Expand Up @@ -797,7 +797,7 @@ native_module_at_runtime_resolve_ret(app_pc xsp, int ret_imm)
ASSERT(false && "fail to read app stack!\n");
return;
}
if (is_native_pc(call_tgt) && !is_native_pc(ret_tgt)) {
if (is_stay_native_pc(call_tgt) && !is_stay_native_pc(ret_tgt)) {
/* replace the return target for regaining control later */
dcontext_t *dcontext = get_thread_private_dcontext();
app_pc stub_pc = native_module_get_ret_stub(dcontext, ret_tgt);
Expand Down

0 comments on commit 96ea594

Please sign in to comment.