mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Brian Gerst <bgerst@didntduck.org>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] x86 execve from kernel
Date: Sun, 14 Mar 2004 19:42:11 -0500	[thread overview]
Message-ID: <4054FBE3.6010905@quark.didntduck.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 87 bytes --]

Remove the jump through int $0x80 for execve from a kernel thread.

--
				Brian Gerst

[-- Attachment #2: execve-1 --]
[-- Type: text/plain, Size: 1710 bytes --]

diff -urN linux-bk/arch/i386/kernel/process.c linux/arch/i386/kernel/process.c
--- linux-bk/arch/i386/kernel/process.c	2004-03-14 18:25:39.000000000 -0500
+++ linux/arch/i386/kernel/process.c	2004-03-14 19:39:47.333293016 -0500
@@ -630,6 +630,33 @@
 }
 
 /*
+ * execs a userspace program from a kernel thread
+ */
+int execve(char *filename, char **argv, char **envp)
+{
+	struct pt_regs regs;
+	int error;
+	unsigned long flags;
+
+	memset(&regs, 0, sizeof(regs));
+	regs.eflags = X86_EFLAGS_IF;
+
+	error = do_execve(filename,
+			(char __user * __user *) argv,
+			(char __user * __user *) envp,
+			&regs);
+	if (error == 0) {
+		current->ptrace &= ~PT_DTRACE;
+		__asm__ __volatile__(
+		       "movl %0,%%esp\n\t"
+		       "movl %1,%%ebp\n\t"
+		       "jmp resume_userspace\n\t"
+		       : : "r" (&regs), "r" (current_thread_info()));
+	}
+	return error;
+}
+
+/*
  * These bracket the sleeping functions..
  */
 extern void scheduling_functions_start_here(void);
diff -urN linux-bk/include/asm-i386/unistd.h linux/include/asm-i386/unistd.h
--- linux-bk/include/asm-i386/unistd.h	2004-03-14 18:25:46.000000000 -0500
+++ linux/include/asm-i386/unistd.h	2004-03-14 19:12:38.000000000 -0500
@@ -395,7 +395,7 @@
 static inline _syscall3(int,read,int,fd,char *,buf,off_t,count)
 static inline _syscall3(off_t,lseek,int,fd,off_t,offset,int,count)
 static inline _syscall1(int,dup,int,fd)
-static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
+extern int execve(char *, char **, char **);
 static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
 static inline _syscall1(int,close,int,fd)
 static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)

                 reply	other threads:[~2004-03-15  0:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4054FBE3.6010905@quark.didntduck.org \
    --to=bgerst@didntduck.org \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.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®