mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chuck Ebbert <76306.1226@compuserve.com>
To: erg0t <ergot86@gmail.com>
Cc: Andrew Morton <akpm@osdl.org>, Ingo Molnar <mingo@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@osdl.org>,
	Chuck Ebbert <76306.1226@compuserve.com>
Subject: Re: [PATCH] i386 - sys_clone from vsyscall
Date: Wed, 25 Jan 2006 22:43:49 -0500	[thread overview]
Message-ID: <200601252247_MC3-1-B6BF-F209@compuserve.com> (raw)

In-Reply-To: <401b11ae0601110953h2389f118t3d4d11c33eece4f8@mail.gmail.com>

On Wed, 11 Jan 2006 at 17:53:10 +0000, erg0t wrote:

> 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.

glibc works around this bug by hardcoding "int 0x80" at
glibc-2.3.5/sysdeps/unix/sysv/linux/i386/clone.S line 99.

> Sorry for use the 0xffffe410 constant I didn't find another way
> to reference it.

It's SYSENTER_RETURN.

> Signed-off-by: Daniel F <ergot86@gmail.com>

Your patch almost works but it copies the stack into the parent's address space.
Using access_process_vm() fixes it.  However, that still leaves unfixed the case
where vsyscall-int80 is used.


[patch] i386: fix sys_clone when using vsyscall-sysenter

Fix a problem when sys_clone is called from sysenter vsyscall and a new stack
for the child is specified.  Some data needs to be copied from the parent
to the child stack or the child will segfault.

Bug report and initial patch from Daniel F <ergot86@gmail.com>

Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>

--- 2.6.15a.orig/arch/i386/kernel/process.c
+++ 2.6.15a/arch/i386/kernel/process.c
@@ -429,12 +429,15 @@ void prepare_to_copy(struct task_struct 
 	unlazy_fpu(tsk);
 }
 
+void SYSENTER_RETURN(void);
+
 int copy_thread(int nr, unsigned long clone_flags, unsigned long esp,
 	unsigned long unused,
 	struct task_struct * p, struct pt_regs * regs)
 {
 	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;
@@ -451,6 +454,19 @@ 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 things are pushed on the stack;
+	 * we need to copy the stuff to the new stack.
+	 */
+	if (regs->esp != esp && (void *)regs->eip == SYSENTER_RETURN) {
+		int size = sizeof(vsyscall_stack);
+
+		if (copy_from_user(vsyscall_stack, (void *)regs->esp, size))
+			return -EFAULT;
+		if (access_process_vm(p, esp - size, vsyscall_stack, size, 1) != size)
+			return -EFAULT;
+		esp -= size;
+	}
 	childregs->esp = esp;
 
 	p->thread.esp = (unsigned long) childregs;
-- 
Chuck

             reply	other threads:[~2006-01-26  3:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-26  3:43 Chuck Ebbert [this message]
2006-01-26 15:12 ` Daniel fernandez
  -- strict thread matches above, loose matches on Subject: below --
2006-01-26 16:41 Chuck Ebbert
2006-01-11 17:53 erg0t

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200601252247_MC3-1-B6BF-F209@compuserve.com \
    --to=76306.1226@compuserve.com \
    --cc=akpm@osdl.org \
    --cc=ergot86@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®