Skip to content

Commit 218ec6f

Browse files
committed
Can't use trampolines for data symbols.
Verify that the page containing the target symbol is marked executable before creating a trampoline.
1 parent 4ab8953 commit 218ec6f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

flexdll.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ static void relocate(resolver f, void *data, reloctbl *tbl, void **jmptbl) {
186186
char* reloc_type;
187187
/*
188188
DWORD old;
189-
MEMORY_BASIC_INFORMATION info;
190189
*/
190+
MEMORY_BASIC_INFORMATION info;
191191

192192
if (!tbl) return;
193193

@@ -249,7 +249,14 @@ static void relocate(resolver f, void *data, reloctbl *tbl, void **jmptbl) {
249249
if (s != (INT32) s) {
250250
if (jmptbl) {
251251
if (!sym->trampoline) {
252-
void* trampoline = sym->trampoline = *jmptbl;
252+
void* trampoline;
253+
/* trampolines cannot be created for data */
254+
if (VirtualQuery(sym->addr, &info, sizeof(info)) && !(info.Protect & 0xf0)) {
255+
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));
256+
error = 3;
257+
return;
258+
}
259+
trampoline = sym->trampoline = *jmptbl;
253260
/* movq $(sym->addr), %rax */
254261
*((short*)trampoline) = 0xb848;
255262
*((UINT_PTR*)((char*)trampoline + 2)) = (UINT_PTR)sym->addr;

0 commit comments

Comments
 (0)