linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / kernel / kmod.c
index 8754003..5a5ec77 100644 (file)
@@ -47,7 +47,7 @@ static struct workqueue_struct *khelper_wq;
 /*
        modprobe_path is set via /proc/sys.
 */
-char modprobe_path[256] = "/sbin/modprobe";
+char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
 
 /**
  * request_module - try to load a kernel module
@@ -115,34 +115,12 @@ int request_module(const char *fmt, ...)
 EXPORT_SYMBOL(request_module);
 #endif /* CONFIG_KMOD */
 
-#ifdef CONFIG_HOTPLUG
-/*
-       hotplug path is set via /proc/sys
-       invoked by hotplug-aware bus drivers,
-       with call_usermodehelper
-
-       argv [0] = hotplug_path;
-       argv [1] = "usb", "scsi", "pci", "network", etc;
-       ... plus optional type-specific parameters
-       argv [n] = 0;
-
-       envp [*] = HOME, PATH; optional type-specific parameters
-
-       a hotplug bus should invoke this for device add/remove
-       events.  the command is expected to load drivers when
-       necessary, and may perform additional system setup.
-*/
-char hotplug_path[256] = "/sbin/hotplug";
-
-EXPORT_SYMBOL(hotplug_path);
-
-#endif /* CONFIG_HOTPLUG */
-
 struct subprocess_info {
        struct completion *complete;
        char *path;
        char **argv;
        char **envp;
+       struct key *ring;
        int wait;
        int retval;
 };
@@ -153,19 +131,23 @@ struct subprocess_info {
 static int ____call_usermodehelper(void *data)
 {
        struct subprocess_info *sub_info = data;
+       struct key *new_session, *old_session;
        int retval;
-       cpumask_t mask = CPU_MASK_ALL;
 
-       /* Unblock all signals. */
+       /* Unblock all signals and set the session keyring. */
+       new_session = key_get(sub_info->ring);
        flush_signals(current);
        spin_lock_irq(&current->sighand->siglock);
+       old_session = __install_session_keyring(current, new_session);
        flush_signal_handlers(current, 1);
        sigemptyset(&current->blocked);
        recalc_sigpending();
        spin_unlock_irq(&current->sighand->siglock);
 
+       key_put(old_session);
+
        /* We can run anywhere, unlike our parent keventd(). */
-       set_cpus_allowed(current, mask);
+       set_cpus_allowed(current, CPU_MASK_ALL);
 
        retval = -EPERM;
        if (current->fs->root)
@@ -192,10 +174,20 @@ static int wait_for_helper(void *data)
        allow_signal(SIGCHLD);
 
        pid = kernel_thread(____call_usermodehelper, sub_info, SIGCHLD);
-       if (pid < 0)
+       if (pid < 0) {
                sub_info->retval = pid;
-       else
-               sys_wait4(pid, &sub_info->retval, 0, NULL);
+       } else {
+               /*
+                * Normally it is bogus to call wait4() from in-kernel because
+                * wait4() wants to write the exit code to a userspace address.
+                * But wait_for_helper() always runs as keventd, and put_user()
+                * to a kernel address works OK for kernel threads, due to their
+                * having an mm_segment_t which spans the entire address space.
+                *
+                * Thus the __user pointer cast is valid here.
+                */
+               sys_wait4(pid, (int __user *) &sub_info->retval, 0, NULL);
+       }
 
        complete(sub_info->complete);
        return 0;
@@ -205,12 +197,13 @@ static int wait_for_helper(void *data)
 static void __call_usermodehelper(void *data)
 {
        struct subprocess_info *sub_info = data;
+       int wait = sub_info->wait;
        pid_t pid;
 
        /* CLONE_VFORK: wait until the usermode helper has execve'd
         * successfully We need the data structures to stay around
         * until that is done.  */
-       if (sub_info->wait)
+       if (wait)
                pid = kernel_thread(wait_for_helper, sub_info,
                                    CLONE_FS | CLONE_FILES | SIGCHLD);
        else
@@ -220,15 +213,16 @@ static void __call_usermodehelper(void *data)
        if (pid < 0) {
                sub_info->retval = pid;
                complete(sub_info->complete);
-       } else if (!sub_info->wait)
+       } else if (!wait)
                complete(sub_info->complete);
 }
 
 /**
- * call_usermodehelper - start a usermode application
+ * call_usermodehelper_keys - start a usermode application
  * @path: pathname for the application
  * @argv: null-terminated argument list
  * @envp: null-terminated environment list
+ * @session_keyring: session keyring for process (NULL for an empty keyring)
  * @wait: wait for the application to finish and return status.
  *
  * Runs a user-space application.  The application is started
@@ -238,7 +232,8 @@ static void __call_usermodehelper(void *data)
  * Must be called from process context.  Returns a negative error code
  * if program was not execed successfully, or 0.
  */
-int call_usermodehelper(char *path, char **argv, char **envp, int wait)
+int call_usermodehelper_keys(char *path, char **argv, char **envp,
+                            struct key *session_keyring, int wait)
 {
        DECLARE_COMPLETION(done);
        struct subprocess_info sub_info = {
@@ -246,6 +241,7 @@ int call_usermodehelper(char *path, char **argv, char **envp, int wait)
                .path           = path,
                .argv           = argv,
                .envp           = envp,
+               .ring           = session_keyring,
                .wait           = wait,
                .retval         = 0,
        };
@@ -261,12 +257,10 @@ int call_usermodehelper(char *path, char **argv, char **envp, int wait)
        wait_for_completion(&done);
        return sub_info.retval;
 }
-EXPORT_SYMBOL(call_usermodehelper);
+EXPORT_SYMBOL(call_usermodehelper_keys);
 
-static __init int usermodehelper_init(void)
+void __init usermodehelper_init(void)
 {
        khelper_wq = create_singlethread_workqueue("khelper");
        BUG_ON(!khelper_wq);
-       return 0;
 }
-__initcall(usermodehelper_init);