Skip to contentSkip to conversation

i386 - sys_clone from vsyscall

PATCH New erg0t 1 participant 1 message Jan 11, 2006

lore
Share & tools
lore

erg0t

author
#0 lore raw

PATCH 1/1 i386 - sys_clone from vsyscall

This patch fixes a little problem when sys_clone is called from a vsyscall and a new stack
for the child is specifed.
Some regs, and return address are pushed in the stack before sysenter, so when the syscall returns, pop the regs and return, if we made a new stack for the thread
we need to copy that to the new stack or the thread will segfault. Sorry for use the 0xffffe410 constant I didn't find another way to reference it. And sorry for my english :S

--- /usr/src/linux-2.6.14/arch/i386/kernel/process.c.orig

2005-12-13 17:06:46.000000000 +0000
+++ /usr/src/linux-2.6.14/arch/i386/kernel/process.c  2006-01-11
15:19:01.000000000 +0000
@@ -446,6 +446,7 @@ int copy_thread(int nr, unsigned long cl
 {
        struct pt_regs * childregs;
        struct task_struct *tsk;

+ unsigned long vsyscall_stack[4] ;
int err;

childregs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long)
p->thread_info)) - 1;
@@ -462,6 +463,17 @@ int copy_thread(int nr, unsigned long cl

        childregs = (struct pt_regs *) ((unsigned long) childregs - 8);
        *childregs = *regs;
        childregs->eax = 0;

+ /*
+ * When we were called from a vsyscall some thigs are pushed
on the stack,
+ * we need to copy the stuff to the new stack.
+ */
+ if ((regs->esp != esp) && (regs->eip == 0xffffe410)) {
+ if (copy_from_user(vsyscall_stack,(void
*)regs->esp,sizeof(vsyscall_stack)))
+ return -EFAULT ;
+ if (copy_to_user((void
*)esp-sizeof(vsyscall_stack),vsyscall_stack,sizeof(vsyscall_stack)))
+ return -EFAULT ;
+ esp -= sizeof(vsyscall_stack) ;
+ }

        childregs->esp = esp;

        p->thread.esp = (unsigned long) childregs;