1 --- a/arch/um/drivers/mconsole_kern.c 2008-04-17 04:49:44.000000000 +0200
2 +++ b/arch/um/drivers/mconsole_kern.c 2008-07-09 14:41:42.000000000 +0200
4 * Licensed under the GPL
7 +#include "linux/kmod.h"
8 #include <linux/console.h>
9 #include <linux/ctype.h>
10 #include <linux/interrupt.h>
12 #include <linux/utsname.h>
13 #include <linux/workqueue.h>
14 #include <linux/mutex.h>
15 +#include <linux/file.h>
16 #include <asm/uaccess.h>
23 +void mconsole_exec(struct mc_request *req)
27 + char buf[MCONSOLE_MAX_DATA];
30 + "HOME=/", "TERM=linux",
31 + "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin",
36 + req->request.data + strlen("exec "),
39 + res = call_usermodehelper_pipe("/bin/sh", argv, envp, NULL, &out);
42 + mconsole_reply(req, "call_usermodehelper_pipe failed", 1, 0);
47 + len = out->f_op->read(out, buf, sizeof(buf), 0);
49 + mconsole_reply(req, "reading output failed", 1, 0);
53 + mconsole_reply_len(req, buf, len, 0, 0);
56 + mconsole_reply_len(req, buf, len, 0, 1);
61 void mconsole_proc(struct mc_request *req)
65 stop - pause the UML; it will do nothing until it receives a 'go' \n\
66 go - continue the UML after a 'stop' \n\
67 log <string> - make UML enter <string> into the kernel log\n\
68 + exec <string> - pass <string> to /bin/sh -c synchronously\n\
69 proc <file> - returns the contents of the UML's /proc/<file>\n\
70 stack <pid> - returns the stack of the specified pid\n\
72 --- a/arch/um/drivers/mconsole_user.c 2008-05-21 18:34:47.000000000 +0200
73 +++ b/arch/um/drivers/mconsole_user.c 2008-07-07 13:47:13.000000000 +0200
75 { "stop", mconsole_stop, MCONSOLE_PROC },
76 { "go", mconsole_go, MCONSOLE_INTR },
77 { "log", mconsole_log, MCONSOLE_INTR },
78 + { "exec", mconsole_exec, MCONSOLE_PROC },
79 { "proc", mconsole_proc, MCONSOLE_PROC },
80 { "stack", mconsole_stack, MCONSOLE_INTR },
82 --- a/arch/um/include/mconsole.h 2008-04-17 04:49:44.000000000 +0200
83 +++ b/arch/um/include/mconsole.h 2008-07-07 13:46:56.000000000 +0200
85 extern void mconsole_stop(struct mc_request *req);
86 extern void mconsole_go(struct mc_request *req);
87 extern void mconsole_log(struct mc_request *req);
88 +extern void mconsole_exec(struct mc_request *req);
89 extern void mconsole_proc(struct mc_request *req);
90 extern void mconsole_stack(struct mc_request *req);
92 --- a/kernel/kmod.c 2008-05-21 18:34:56.000000000 +0200
93 +++ b/kernel/kmod.c 2008-07-08 13:50:37.000000000 +0200
98 + struct file *stdout;
99 void (*cleanup)(char **argv, char **envp);
103 FD_SET(0, fdt->open_fds);
104 FD_CLR(0, fdt->close_on_exec);
105 spin_unlock(&f->file_lock);
107 - /* and disallow core files too */
109 + if (sub_info->stdout) {
110 + struct files_struct *f = current->files;
111 + struct fdtable *fdt;
115 + get_file(sub_info->stdout);
116 + fd_install(1, sub_info->stdout);
117 + fd_install(2, sub_info->stdout);
118 + spin_lock(&f->file_lock);
119 + fdt = files_fdtable(f);
120 + FD_SET(1, fdt->open_fds);
121 + FD_CLR(1, fdt->close_on_exec);
122 + FD_SET(2, fdt->open_fds);
123 + FD_CLR(2, fdt->close_on_exec);
124 + spin_unlock(&f->file_lock);
126 + if (sub_info->stdin || sub_info->stdout) {
127 + /* disallow core files */
128 current->signal->rlim[RLIMIT_CORE] = (struct rlimit){0, 0};
133 EXPORT_SYMBOL(call_usermodehelper_stdinpipe);
135 +int call_usermodehelper_stdoutpipe(struct subprocess_info *sub_info,
136 + struct file **filp)
140 + f = create_write_pipe();
143 + sub_info->stdout = f;
145 + f = create_read_pipe(f);
147 + free_write_pipe(sub_info->stdout);
148 + sub_info->stdout = NULL;
155 +EXPORT_SYMBOL(call_usermodehelper_stdoutpipe);
159 * call_usermodehelper_exec - start a usermode application
160 * @sub_info: information about the subprocessa
162 * lower-level call_usermodehelper_* functions.
164 int call_usermodehelper_pipe(char *path, char **argv, char **envp,
165 - struct file **filp)
166 + struct file **in, struct file **out)
168 struct subprocess_info *sub_info;
171 if (sub_info == NULL)
174 - ret = call_usermodehelper_stdinpipe(sub_info, filp);
178 + ret = call_usermodehelper_stdinpipe(sub_info, in);
184 + ret = call_usermodehelper_stdoutpipe(sub_info, out);
189 return call_usermodehelper_exec(sub_info, UMH_WAIT_EXEC);
191 --- a/include/linux/kmod.h 2008-04-17 04:49:44.000000000 +0200
192 +++ b/include/linux/kmod.h 2008-07-08 10:29:29.000000000 +0200
196 extern int call_usermodehelper_pipe(char *path, char *argv[], char *envp[],
197 - struct file **filp);
198 + struct file **in, struct file **out);
200 #endif /* __LINUX_KMOD_H__ */
201 --- a/fs/exec.c 2008-06-05 14:00:42.000000000 +0200
202 +++ b/fs/exec.c 2008-07-08 10:28:33.000000000 +0200
203 @@ -1737,7 +1737,7 @@
205 /* SIGPIPE can happen, but it's just never processed */
206 if (call_usermodehelper_pipe(corename+1, helper_argv, NULL,
209 printk(KERN_INFO "Core dump to %s pipe failed\n",