Skip to content

Commit 6760856

Browse files
arndbLinus Torvalds
authored andcommitted
[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>
1 parent 2453a30 commit 6760856

6 files changed

Lines changed: 31 additions & 11 deletions

File tree

‎arch/sparc64/kernel/power.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* Copyright (C) 1999 David S. Miller (davem@redhat.com)
55
*/
66

7-
#define __KERNEL_SYSCALLS__
8-
97
#include <linux/kernel.h>
108
#include <linux/module.h>
119
#include <linux/init.h>
@@ -14,6 +12,7 @@
1412
#include <linux/delay.h>
1513
#include <linux/interrupt.h>
1614
#include <linux/pm.h>
15+
#include <linux/syscalls.h>
1716

1817
#include <asm/system.h>
1918
#include <asm/auxio.h>
@@ -98,7 +97,7 @@ static int powerd(void *__unused)
9897

9998
/* Ok, down we go... */
10099
button_pressed = 0;
101-
if (execve("/sbin/shutdown", argv, envp) < 0) {
100+
if (kernel_execve("/sbin/shutdown", argv, envp) < 0) {
102101
printk("powerd: shutdown execution failed\n");
103102
add_wait_queue(&powerd_wait, &wait);
104103
goto again;

‎init/do_mounts_initrd.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define __KERNEL_SYSCALLS__
21
#include <linux/unistd.h>
32
#include <linux/kernel.h>
43
#include <linux/fs.h>
@@ -35,7 +34,7 @@ static int __init do_linuxrc(void * shell)
3534
(void) sys_open("/dev/console",O_RDWR,0);
3635
(void) sys_dup(0);
3736
(void) sys_dup(0);
38-
return execve(shell, argv, envp_init);
37+
return kernel_execve(shell, argv, envp_init);
3938
}
4039

4140
static void __init handle_initrd(void)

‎init/main.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* Simplified starting of init: Michael A. Griffith <grif@acm.org>
1010
*/
1111

12-
#define __KERNEL_SYSCALLS__
13-
1412
#include <linux/types.h>
1513
#include <linux/module.h>
1614
#include <linux/proc_fs.h>
@@ -703,7 +701,7 @@ static void do_pre_smp_initcalls(void)
703701
static void run_init_process(char *init_filename)
704702
{
705703
argv_init[0] = init_filename;
706-
execve(init_filename, argv_init, envp_init);
704+
kernel_execve(init_filename, argv_init, envp_init);
707705
}
708706

709707
static int init(void * unused)

‎kernel/kmod.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
call_usermodehelper wait flag, and remove exec_usermodehelper.
1919
Rusty Russell <rusty@rustcorp.com.au> Jan 2003
2020
*/
21-
#define __KERNEL_SYSCALLS__
22-
2321
#include <linux/module.h>
2422
#include <linux/sched.h>
2523
#include <linux/syscalls.h>
@@ -169,7 +167,8 @@ static int ____call_usermodehelper(void *data)
169167

170168
retval = -EPERM;
171169
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);
173172

174173
/* Exec failed? */
175174
sub_info->retval = retval;

‎lib/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
3535
lib-y += dec_and_lock.o
3636
endif
3737

38+
lib-y += execve.o
39+
3840
obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
3941
obj-$(CONFIG_CRC16) += crc16.o
4042
obj-$(CONFIG_CRC32) += crc32.o

‎lib/execve.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <asm/bug.h>
2+
#include <asm/uaccess.h>
3+
4+
#define __KERNEL_SYSCALLS__
5+
static int errno __attribute__((unused));
6+
#include <asm/unistd.h>
7+
8+
#ifdef _syscall3
9+
int kernel_execve (const char *filename, char *const argv[], char *const envp[])
10+
__attribute__((__weak__));
11+
int 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

0 commit comments

Comments
 (0)