From ef2fa499124934626b1182bb236872f40a841b19 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 15 Feb 2018 04:32:16 +0000 Subject: [PATCH] x86: trampoline: fix GOT clobbering, pointed out by fabled --- arch/x86/startcontext.S | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/x86/startcontext.S b/arch/x86/startcontext.S index 2bb87ee..3304863 100644 --- a/arch/x86/startcontext.S +++ b/arch/x86/startcontext.S @@ -15,15 +15,26 @@ __start_context: /* get the proper context into position and test for NULL */ leal (%esp,%ebx,4), %esp cmpl $0, (%esp) - je hosed + + /* restore global offset table, exit@plt and __setcontext@plt need this */ + call __i686.get_pc_thunk.bx + addl $_GLOBAL_OFFSET_TABLE_, %ebx + + /* if we have no linked context, lets get out of here */ + je no_linked_context /* call setcontext to switch to the linked context */ call __setcontext@plt movl %eax, (%esp) -hosed: +no_linked_context: /* we are returning into a null context, it seems, so maybe we should exit */ call exit@plt /* something is really hosed, call hlt to force termination */ hlt + + +__i686.get_pc_thunk.bx: + mov (%esp), %ebx + ret