infrastructure for saner ret_from_kernel_thread semantics
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 11 Oct 2012 01:28:25 +0000 (21:28 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 12 Oct 2012 17:35:07 +0000 (13:35 -0400)
* allow kernel_execve() leave the actual return to userland to
caller (selected by CONFIG_GENERIC_KERNEL_EXECVE).  Callers
updated accordingly.
* architecture that does select GENERIC_KERNEL_EXECVE in its
Kconfig should have its ret_from_kernel_thread() do this:
call schedule_tail
call the callback left for it by copy_thread(); if it ever
returns, that's because it has just done successful kernel_execve()
jump to return from syscall
IOW, its only difference from ret_from_fork() is that it does call the
callback.
* such an architecture should also get rid of ret_from_kernel_execve()
and __ARCH_WANT_KERNEL_EXECVE

This is the last part of infrastructure patches in that area - from
that point on work on different architectures can live independently.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
arch/Kconfig
include/linux/syscalls.h
init/main.c
kernel/kmod.c
kernel/kthread.c

index d397e11d167d9c9923e418dcb3599a3a14de6590..d27efb9bfafd1296cf2a44111b9608d525fa6967 100644 (file)
@@ -261,6 +261,9 @@ config ARCH_WANT_OLD_COMPAT_IPC
 config GENERIC_KERNEL_THREAD
        bool
 
+config GENERIC_KERNEL_EXECVE
+       bool
+
 config HAVE_ARCH_SECCOMP_FILTER
        bool
        help
index 19439c75c5b255751e2467b5405861763f131fd5..727f0cd739213cc70054d3412b181527f504d2f2 100644 (file)
@@ -827,7 +827,15 @@ asmlinkage long sys_fanotify_mark(int fanotify_fd, unsigned int flags,
                                  const char  __user *pathname);
 asmlinkage long sys_syncfs(int fd);
 
+#ifndef CONFIG_GENERIC_KERNEL_EXECVE
 int kernel_execve(const char *filename, const char *const argv[], const char *const envp[]);
+#else
+#define kernel_execve(filename, argv, envp) \
+       do_execve(filename, \
+               (const char __user *const __user *)argv, \
+               (const char __user *const __user *)envp, \
+               current_pt_regs())
+#endif
 
 
 asmlinkage long sys_perf_event_open(
index a490ffecb7b9e245d0c96da7c2f19410a1913ceb..02df2ddc5f83a36f0de98b184656b2773a2a98c2 100644 (file)
@@ -69,6 +69,7 @@
 #include <linux/slab.h>
 #include <linux/perf_event.h>
 #include <linux/file.h>
+#include <linux/ptrace.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -788,10 +789,10 @@ static void __init do_pre_smp_initcalls(void)
                do_one_initcall(*fn);
 }
 
-static void run_init_process(const char *init_filename)
+static int run_init_process(const char *init_filename)
 {
        argv_init[0] = init_filename;
-       kernel_execve(init_filename, argv_init, envp_init);
+       return kernel_execve(init_filename, argv_init, envp_init);
 }
 
 static void __init kernel_init_freeable(void);
@@ -810,7 +811,8 @@ static int __ref kernel_init(void *unused)
        flush_delayed_fput();
 
        if (ramdisk_execute_command) {
-               run_init_process(ramdisk_execute_command);
+               if (!run_init_process(ramdisk_execute_command))
+                       return 0;
                printk(KERN_WARNING "Failed to execute %s\n",
                                ramdisk_execute_command);
        }
@@ -822,14 +824,16 @@ static int __ref kernel_init(void *unused)
         * trying to recover a really broken machine.
         */
        if (execute_command) {
-               run_init_process(execute_command);
+               if (!run_init_process(execute_command))
+                       return 0;
                printk(KERN_WARNING "Failed to execute %s.  Attempting "
                                        "defaults...\n", execute_command);
        }
-       run_init_process("/sbin/init");
-       run_init_process("/etc/init");
-       run_init_process("/bin/init");
-       run_init_process("/bin/sh");
+       if (!run_init_process("/sbin/init") ||
+           !run_init_process("/etc/init") ||
+           !run_init_process("/bin/init") ||
+           !run_init_process("/bin/sh"))
+               return 0;
 
        panic("No init found.  Try passing init= option to kernel. "
              "See Linux Documentation/init.txt for guidance.");
index b6e5ca9c758a54cac68805cf1c840ca0b8cd107f..1c317e386831869a3c4ff17a675a06b3b985c06d 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/notifier.h>
 #include <linux/suspend.h>
 #include <linux/rwsem.h>
+#include <linux/ptrace.h>
 #include <asm/uaccess.h>
 
 #include <trace/events/module.h>
@@ -221,6 +222,8 @@ static int ____call_usermodehelper(void *data)
        retval = kernel_execve(sub_info->path,
                               (const char *const *)sub_info->argv,
                               (const char *const *)sub_info->envp);
+       if (!retval)
+               return 0;
 
        /* Exec failed? */
 fail:
index b579af57ea107af579e6a155730258166dd4e176..7ba65c1aa6b382904e25c65d9591a0fcc86eade9 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/freezer.h>
+#include <linux/ptrace.h>
 #include <trace/events/sched.h>
 
 static DEFINE_SPINLOCK(kthread_create_lock);