Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

Arnd Bergmann and committed by
Linus Torvalds
67608567 2453a306

+31 -11
+2 -3
arch/sparc64/kernel/power.c
··· 4 4 * Copyright (C) 1999 David S. Miller (davem@redhat.com) 5 5 */ 6 6 7 - #define __KERNEL_SYSCALLS__ 8 - 9 7 #include <linux/kernel.h> 10 8 #include <linux/module.h> 11 9 #include <linux/init.h> ··· 12 14 #include <linux/delay.h> 13 15 #include <linux/interrupt.h> 14 16 #include <linux/pm.h> 17 + #include <linux/syscalls.h> 15 18 16 19 #include <asm/system.h> 17 20 #include <asm/auxio.h> ··· 97 98 98 99 /* Ok, down we go... */ 99 100 button_pressed = 0; 100 - if (execve("/sbin/shutdown", argv, envp) < 0) { 101 + if (kernel_execve("/sbin/shutdown", argv, envp) < 0) { 101 102 printk("powerd: shutdown execution failed\n"); 102 103 add_wait_queue(&powerd_wait, &wait); 103 104 goto again;
+1 -2
init/do_mounts_initrd.c
··· 1 - #define __KERNEL_SYSCALLS__ 2 1 #include <linux/unistd.h> 3 2 #include <linux/kernel.h> 4 3 #include <linux/fs.h> ··· 34 35 (void) sys_open("/dev/console",O_RDWR,0); 35 36 (void) sys_dup(0); 36 37 (void) sys_dup(0); 37 - return execve(shell, argv, envp_init); 38 + return kernel_execve(shell, argv, envp_init); 38 39 } 39 40 40 41 static void __init handle_initrd(void)
+1 -3
init/main.c
··· 9 9 * Simplified starting of init: Michael A. Griffith <grif@acm.org> 10 10 */ 11 11 12 - #define __KERNEL_SYSCALLS__ 13 - 14 12 #include <linux/types.h> 15 13 #include <linux/module.h> 16 14 #include <linux/proc_fs.h> ··· 701 703 static void run_init_process(char *init_filename) 702 704 { 703 705 argv_init[0] = init_filename; 704 - execve(init_filename, argv_init, envp_init); 706 + kernel_execve(init_filename, argv_init, envp_init); 705 707 } 706 708 707 709 static int init(void * unused)
+2 -3
kernel/kmod.c
··· 18 18 call_usermodehelper wait flag, and remove exec_usermodehelper. 19 19 Rusty Russell <rusty@rustcorp.com.au> Jan 2003 20 20 */ 21 - #define __KERNEL_SYSCALLS__ 22 - 23 21 #include <linux/module.h> 24 22 #include <linux/sched.h> 25 23 #include <linux/syscalls.h> ··· 167 169 168 170 retval = -EPERM; 169 171 if (current->fs->root) 170 - retval = execve(sub_info->path, sub_info->argv, sub_info->envp); 172 + retval = kernel_execve(sub_info->path, 173 + sub_info->argv, sub_info->envp); 171 174 172 175 /* Exec failed? */ 173 176 sub_info->retval = retval;
+2
lib/Makefile
··· 35 35 lib-y += dec_and_lock.o 36 36 endif 37 37 38 + lib-y += execve.o 39 + 38 40 obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o 39 41 obj-$(CONFIG_CRC16) += crc16.o 40 42 obj-$(CONFIG_CRC32) += crc32.o
+23
lib/execve.c
··· 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