Skip to content

Commit

Permalink
Can't use trampolines for data symbols.
Browse files Browse the repository at this point in the history
Verify that the page containing the target symbol is marked executable
before creating a trampoline.
  • Loading branch information
dra27 committed Feb 11, 2018
1 parent 4ab8953 commit 5a98545
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion flexdll.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ static void relocate(resolver f, void *data, reloctbl *tbl, void **jmptbl) {
char* reloc_type;
/*
DWORD old;
MEMORY_BASIC_INFORMATION info;
*/
MEMORY_BASIC_INFORMATION info;

if (!tbl) return;

Expand Down Expand Up @@ -249,6 +249,12 @@ static void relocate(resolver f, void *data, reloctbl *tbl, void **jmptbl) {
if (s != (INT32) s) {
if (jmptbl) {
if (!sym->trampoline) {
/* trampolines cannot be created for data */
if (VirtualQuery(sym->addr, &info, sizeof(info)) && !(info.Protect & 0xf0)) {
sprintf(error_buffer, "flexdll error: cannot relocate RELOC_REL32%s, target is too far, and not executable: %p %p", reloc_type, (void *)((UINT_PTR) s), (void *) ((UINT_PTR)(INT32) s));
error = 3;
return;
}
void* trampoline = sym->trampoline = *jmptbl;
/* movq $(sym->addr), %rax */
*((short*)trampoline) = 0xb848;
Expand Down

0 comments on commit 5a98545

Please sign in to comment.