aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2006-10-02 05:18:26 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-02 10:57:23 -0400
commit6760856791c6e527da678021ee6a67896549d4da (patch)
tree31bf78dac3a2ea68282ae394aeedb15bc92ae7d7
parent2453a3062d36f39f01302f9f1ad18e7a0c54fe38 (diff)
[PATCH] introduce kernel_execve
The use of execve() in the kernel is dubious, since it relies on the __KERNEL_SYSCALLS__ mechanism that stores the result in a global errno variable. As a first step of getting rid of this, change all users to a global kernel_execve function that returns a proper error code. This function is a terrible hack, and a later patch removes it again after the kernel syscalls are gone. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Cc: Andi Kleen <ak@muc.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Richard Henderson <rth@twiddle.net> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Russell King <rmk@arm.linux.org.uk> Cc: Ian Molton <spyro@f2s.com> Cc: Mikael Starvik <starvik@axis.com> Cc: David Howells <dhowells@redhat.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: Hirokazu Takata <takata.hirokazu@renesas.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Kyle McMartin <kyle@mcmartin.ca> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Kazumoto Kojima <kkojima@rr.iij4u.or.jp> Cc: Richard Curnow <rc@rc0.org.uk> Cc: William Lee Irwin III <wli@holomorphy.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Jeff Dike <jdike@addtoit.com> Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> Cc: Miles Bader <uclinux-v850@lsi.nec.co.jp> Cc: Chris Zankel <chris@zankel.net> Cc: "Luck, Tony" <tony.luck@intel.com> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Roman Zippel <zippel@linux-m68k.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--arch/sparc64/kernel/power.c5
-rw-r--r--init/do_mounts_initrd.c3
-rw-r--r--init/main.c4
-rw-r--r--kernel/kmod.c5
-rw-r--r--lib/Makefile2
-rw-r--r--lib/execve.c23
6 files changed, 31 insertions, 11 deletions
diff --git a/arch/sparc64/kernel/power.c b/arch/sparc64/kernel/power.c
index e55466c77b61..0b9c70627ce4 100644
--- a/arch/sparc64/kernel/power.c
+++ b/arch/sparc64/kernel/power.c
@@ -4,8 +4,6 @@
4 * Copyright (C) 1999 David S. Miller (davem@redhat.com) 4 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
5 */ 5 */
6 6
7#define __KERNEL_SYSCALLS__
8
9#include <linux/kernel.h> 7#include <linux/kernel.h>
10#include <linux/module.h> 8#include <linux/module.h>
11#include <linux/init.h> 9#include <linux/init.h>
@@ -14,6 +12,7 @@
14#include <linux/delay.h> 12#include <linux/delay.h>
15#include <linux/interrupt.h> 13#include <linux/interrupt.h>
16#include <linux/pm.h> 14#include <linux/pm.h>
15#include <linux/syscalls.h>
17 16
18#include <asm/system.h> 17#include <asm/system.h>
19#include <asm/auxio.h> 18#include <asm/auxio.h>
@@ -98,7 +97,7 @@ again:
98 97
99 /* Ok, down we go... */ 98 /* Ok, down we go... */
100 button_pressed = 0; 99 button_pressed = 0;
101 if (execve("/sbin/shutdown", argv, envp) < 0) { 100 if (kernel_execve("/sbin/shutdown", argv, envp) < 0) {
102 printk("powerd: shutdown execution failed\n"); 101 printk("powerd: shutdown execution failed\n");
103 add_wait_queue(&powerd_wait, &wait); 102 add_wait_queue(&powerd_wait, &wait);
104 goto again; 103 goto again;
diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
index a06f037fa000..919a80cb322e 100644
--- a/init/do_mounts_initrd.c
+++ b/init/do_mounts_initrd.c
@@ -1,4 +1,3 @@
1#define __KERNEL_SYSCALLS__
2#include <linux/unistd.h> 1#include <linux/unistd.h>
3#include <linux/kernel.h> 2#include <linux/kernel.h>
4#include <linux/fs.h> 3#include <linux/fs.h>
@@ -35,7 +34,7 @@ static int __init do_linuxrc(void * shell)
35 (void) sys_open("/dev/console",O_RDWR,0); 34 (void) sys_open("/dev/console",O_RDWR,0);
36 (void) sys_dup(0); 35 (void) sys_dup(0);
37 (void) sys_dup(0); 36 (void) sys_dup(0);
38 return execve(shell, argv, envp_init); 37 return kernel_execve(shell, argv, envp_init);
39} 38}
40 39
41static void __init handle_initrd(void) 40static void __init handle_initrd(void)
diff --git a/init/main.c b/init/main.c
index 0766e69712b2..a49b00235bda 100644
--- a/init/main.c
+++ b/init/main.c
@@ -9,8 +9,6 @@
9 * Simplified starting of init: Michael A. Griffith <grif@acm.org> 9 * Simplified starting of init: Michael A. Griffith <grif@acm.org>
10 */ 10 */
11 11
12#define __KERNEL_SYSCALLS__
13
14#include <linux/types.h> 12#include <linux/types.h>
15#include <linux/module.h> 13#include <linux/module.h>
16#include <linux/proc_fs.h> 14#include <linux/proc_fs.h>
@@ -703,7 +701,7 @@ static void do_pre_smp_initcalls(void)
703static void run_init_process(char *init_filename) 701static void run_init_process(char *init_filename)
704{ 702{
705 argv_init[0] = init_filename; 703 argv_init[0] = init_filename;
706 execve(init_filename, argv_init, envp_init); 704 kernel_execve(init_filename, argv_init, envp_init);
707} 705}
708 706
709static int init(void * unused) 707static int init(void * unused)
diff --git a/kernel/kmod.c b/kernel/kmod.c
index f8121b95183f..bb4e29d924e4 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -18,8 +18,6 @@
18 call_usermodehelper wait flag, and remove exec_usermodehelper. 18 call_usermodehelper wait flag, and remove exec_usermodehelper.
19 Rusty Russell <rusty@rustcorp.com.au> Jan 2003 19 Rusty Russell <rusty@rustcorp.com.au> Jan 2003
20*/ 20*/
21#define __KERNEL_SYSCALLS__
22
23#include <linux/module.h> 21#include <linux/module.h>
24#include <linux/sched.h> 22#include <linux/sched.h>
25#include <linux/syscalls.h> 23#include <linux/syscalls.h>
@@ -169,7 +167,8 @@ static int ____call_usermodehelper(void *data)
169 167
170 retval = -EPERM; 168 retval = -EPERM;
171 if (current->fs->root) 169 if (current->fs->root)
172 retval = execve(sub_info->path, sub_info->argv, sub_info->envp); 170 retval = kernel_execve(sub_info->path,
171 sub_info->argv, sub_info->envp);
173 172
174 /* Exec failed? */ 173 /* Exec failed? */
175 sub_info->retval = retval; 174 sub_info->retval = retval;
diff --git a/lib/Makefile b/lib/Makefile
index ddf3e676e1f4..4d752be0edc0 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -35,6 +35,8 @@ ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
35 lib-y += dec_and_lock.o 35 lib-y += dec_and_lock.o
36endif 36endif
37 37
38lib-y += execve.o
39
38obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o 40obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
39obj-$(CONFIG_CRC16) += crc16.o 41obj-$(CONFIG_CRC16) += crc16.o
40obj-$(CONFIG_CRC32) += crc32.o 42obj-$(CONFIG_CRC32) += crc32.o
diff --git a/lib/execve.c b/lib/execve.c
new file mode 100644
index 000000000000..2667ebc15045
--- /dev/null
+++ b/lib/execve.c
@@ -0,0 +1,23 @@
1#include <asm/bug.h>
2#include <asm/uaccess.h>
3
4#define __KERNEL_SYSCALLS__
5static int errno __attribute__((unused));
6#include <asm/unistd.h>
7
8#ifdef _syscall3
9int kernel_execve (const char *filename, char *const argv[], char *const envp[])
10 __attribute__((__weak__));
11int kernel_execve (const char *filename, char *const argv[], char *const envp[])
12{
13 mm_segment_t fs = get_fs();
14 int ret;
15
16 WARN_ON(segment_eq(fs, USER_DS));
17 ret = execve(filename, (char **)argv, (char **)envp);
18 if (ret)
19 ret = -errno;
20
21 return ret;
22}
23#endif