aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kmod.h
diff options
context:
space:
mode:
authorNeil Horman <nhorman@tuxdriver.com>2010-05-26 17:42:58 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-05-27 12:12:44 -0400
commita06a4dc3a08201ff6a8a958f935b3cbf7744115f (patch)
treeb338edde5edb31f51e0b7eb86e6c4ce8063c703f /include/linux/kmod.h
parent065add3941bdca54fe04ed3471a96bce9af88793 (diff)
kmod: add init function to usermodehelper
About 6 months ago, I made a set of changes to how the core-dump-to-a-pipe feature in the kernel works. We had reports of several races, including some reports of apps bypassing our recursion check so that a process that was forked as part of a core_pattern setup could infinitely crash and refork until the system crashed. We fixed those by improving our recursion checks. The new check basically refuses to fork a process if its core limit is zero, which works well. Unfortunately, I've been getting grief from maintainer of user space programs that are inserted as the forked process of core_pattern. They contend that in order for their programs (such as abrt and apport) to work, all the running processes in a system must have their core limits set to a non-zero value, to which I say 'yes'. I did this by design, and think thats the right way to do things. But I've been asked to ease this burden on user space enough times that I thought I would take a look at it. The first suggestion was to make the recursion check fail on a non-zero 'special' number, like one. That way the core collector process could set its core size ulimit to 1, and enable the kernel's recursion detection. This isn't a bad idea on the surface, but I don't like it since its opt-in, in that if a program like abrt or apport has a bug and fails to set such a core limit, we're left with a recursively crashing system again. So I've come up with this. What I've done is modify the call_usermodehelper api such that an extra parameter is added, a function pointer which will be called by the user helper task, after it forks, but before it exec's the required process. This will give the caller the opportunity to get a call back in the processes context, allowing it to do whatever it needs to to the process in the kernel prior to exec-ing the user space code. In the case of do_coredump, this callback is ues to set the core ulimit of the helper process to 1. This elimnates the opt-in problem that I had above, as it allows the ulimit for core sizes to be set to the value of 1, which is what the recursion check looks for in do_coredump. This patch: Create new function call_usermodehelper_fns() and allow it to assign both an init and cleanup function, as we'll as arbitrary data. The init function is called from the context of the forked process and allows for customization of the helper process prior to calling exec. Its return code gates the continuation of the process, or causes its exit. Also add an arbitrary data pointer to the subprocess_info struct allowing for data to be passed from the caller to the new process, and the subsequent cleanup process Also, use this patch to cleanup the cleanup function. It currently takes an argp and envp pointer for freeing, which is ugly. Lets instead just make the subprocess_info structure public, and pass that to the cleanup and init routines Signed-off-by: Neil Horman <nhorman@tuxdriver.com> Reviewed-by: Oleg Nesterov <oleg@redhat.com> Cc: Andi Kleen <andi@firstfloor.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/kmod.h')
-rw-r--r--include/linux/kmod.h51
1 files changed, 41 insertions, 10 deletions
diff --git a/include/linux/kmod.h b/include/linux/kmod.h
index facb27fe7de..f9edf63e90e 100644
--- a/include/linux/kmod.h
+++ b/include/linux/kmod.h
@@ -23,6 +23,7 @@
23#include <linux/stddef.h> 23#include <linux/stddef.h>
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/compiler.h> 25#include <linux/compiler.h>
26#include <linux/workqueue.h>
26 27
27#define KMOD_PATH_LEN 256 28#define KMOD_PATH_LEN 256
28 29
@@ -45,7 +46,27 @@ static inline int request_module_nowait(const char *name, ...) { return -ENOSYS;
45 46
46struct key; 47struct key;
47struct file; 48struct file;
48struct subprocess_info; 49
50enum umh_wait {
51 UMH_NO_WAIT = -1, /* don't wait at all */
52 UMH_WAIT_EXEC = 0, /* wait for the exec, but not the process */
53 UMH_WAIT_PROC = 1, /* wait for the process to complete */
54};
55
56struct subprocess_info {
57 struct work_struct work;
58 struct completion *complete;
59 struct cred *cred;
60 char *path;
61 char **argv;
62 char **envp;
63 enum umh_wait wait;
64 int retval;
65 struct file *stdin;
66 int (*init)(struct subprocess_info *info);
67 void (*cleanup)(struct subprocess_info *info);
68 void *data;
69};
49 70
50/* Allocate a subprocess_info structure */ 71/* Allocate a subprocess_info structure */
51struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, 72struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
@@ -56,14 +77,10 @@ void call_usermodehelper_setkeys(struct subprocess_info *info,
56 struct key *session_keyring); 77 struct key *session_keyring);
57int call_usermodehelper_stdinpipe(struct subprocess_info *sub_info, 78int call_usermodehelper_stdinpipe(struct subprocess_info *sub_info,
58 struct file **filp); 79 struct file **filp);
59void call_usermodehelper_setcleanup(struct subprocess_info *info, 80void call_usermodehelper_setfns(struct subprocess_info *info,
60 void (*cleanup)(char **argv, char **envp)); 81 int (*init)(struct subprocess_info *info),
61 82 void (*cleanup)(struct subprocess_info *info),
62enum umh_wait { 83 void *data);
63 UMH_NO_WAIT = -1, /* don't wait at all */
64 UMH_WAIT_EXEC = 0, /* wait for the exec, but not the process */
65 UMH_WAIT_PROC = 1, /* wait for the process to complete */
66};
67 84
68/* Actually execute the sub-process */ 85/* Actually execute the sub-process */
69int call_usermodehelper_exec(struct subprocess_info *info, enum umh_wait wait); 86int call_usermodehelper_exec(struct subprocess_info *info, enum umh_wait wait);
@@ -73,18 +90,32 @@ int call_usermodehelper_exec(struct subprocess_info *info, enum umh_wait wait);
73void call_usermodehelper_freeinfo(struct subprocess_info *info); 90void call_usermodehelper_freeinfo(struct subprocess_info *info);
74 91
75static inline int 92static inline int
76call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait) 93call_usermodehelper_fns(char *path, char **argv, char **envp,
94 enum umh_wait wait,
95 int (*init)(struct subprocess_info *info),
96 void (*cleanup)(struct subprocess_info *), void *data)
77{ 97{
78 struct subprocess_info *info; 98 struct subprocess_info *info;
79 gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; 99 gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
80 100
81 info = call_usermodehelper_setup(path, argv, envp, gfp_mask); 101 info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
102
82 if (info == NULL) 103 if (info == NULL)
83 return -ENOMEM; 104 return -ENOMEM;
105
106 call_usermodehelper_setfns(info, init, cleanup, data);
107
84 return call_usermodehelper_exec(info, wait); 108 return call_usermodehelper_exec(info, wait);
85} 109}
86 110
87static inline int 111static inline int
112call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait)
113{
114 return call_usermodehelper_fns(path, argv, envp, wait,
115 NULL, NULL, NULL);
116}
117
118static inline int
88call_usermodehelper_keys(char *path, char **argv, char **envp, 119call_usermodehelper_keys(char *path, char **argv, char **envp,
89 struct key *session_keyring, enum umh_wait wait) 120 struct key *session_keyring, enum umh_wait wait)
90{ 121{