aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>2008-07-25 04:45:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-25 13:53:28 -0400
commitac331d158e198d2a91a5b0a3ec4ca9991fdb57af (patch)
treeb0921e2bc8e59d5df2c554c41c3b9f04e05d6d7c
parentf557d0996a6f9c06912528ea85e1dba0fb7d485f (diff)
call_usermodehelper(): increase reliability
Presently call_usermodehelper_setup() uses GFP_ATOMIC. but it can return NULL _very_ easily. GFP_ATOMIC is needed only when we can't sleep. and, GFP_KERNEL is robust and better. thus, I add gfp_mask argument to call_usermodehelper_setup(). So, its callers pass the gfp_t as below: call_usermodehelper() and call_usermodehelper_keys(): depend on 'wait' argument. call_usermodehelper_pipe(): always GFP_KERNEL because always run under process context. orderly_poweroff(): pass to GFP_ATOMIC because may run under interrupt context. Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: "Paul Menage" <menage@google.com> Reviewed-by: Li Zefan <lizf@cn.fujitsu.com> Acked-by: Jeremy Fitzhardinge <jeremy@xensource.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Andi Kleen <andi@firstfloor.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/kmod.h11
-rw-r--r--kernel/kmod.c9
-rw-r--r--kernel/sys.c2
3 files changed, 13 insertions, 9 deletions
diff --git a/include/linux/kmod.h b/include/linux/kmod.h
index 0509c4ce4857..a1a91577813c 100644
--- a/include/linux/kmod.h
+++ b/include/linux/kmod.h
@@ -19,6 +19,7 @@
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#include <linux/gfp.h>
22#include <linux/stddef.h> 23#include <linux/stddef.h>
23#include <linux/errno.h> 24#include <linux/errno.h>
24#include <linux/compiler.h> 25#include <linux/compiler.h>
@@ -41,8 +42,8 @@ struct file;
41struct subprocess_info; 42struct subprocess_info;
42 43
43/* Allocate a subprocess_info structure */ 44/* Allocate a subprocess_info structure */
44struct subprocess_info *call_usermodehelper_setup(char *path, 45struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
45 char **argv, char **envp); 46 char **envp, gfp_t gfp_mask);
46 47
47/* Set various pieces of state into the subprocess_info structure */ 48/* Set various pieces of state into the subprocess_info structure */
48void call_usermodehelper_setkeys(struct subprocess_info *info, 49void call_usermodehelper_setkeys(struct subprocess_info *info,
@@ -69,8 +70,9 @@ static inline int
69call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait) 70call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait)
70{ 71{
71 struct subprocess_info *info; 72 struct subprocess_info *info;
73 gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
72 74
73 info = call_usermodehelper_setup(path, argv, envp); 75 info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
74 if (info == NULL) 76 if (info == NULL)
75 return -ENOMEM; 77 return -ENOMEM;
76 return call_usermodehelper_exec(info, wait); 78 return call_usermodehelper_exec(info, wait);
@@ -81,8 +83,9 @@ call_usermodehelper_keys(char *path, char **argv, char **envp,
81 struct key *session_keyring, enum umh_wait wait) 83 struct key *session_keyring, enum umh_wait wait)
82{ 84{
83 struct subprocess_info *info; 85 struct subprocess_info *info;
86 gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
84 87
85 info = call_usermodehelper_setup(path, argv, envp); 88 info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
86 if (info == NULL) 89 if (info == NULL)
87 return -ENOMEM; 90 return -ENOMEM;
88 91
diff --git a/kernel/kmod.c b/kernel/kmod.c
index 2989f67c4446..2456d1a0befb 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -352,16 +352,17 @@ static inline void register_pm_notifier_callback(void) {}
352 * @path: path to usermode executable 352 * @path: path to usermode executable
353 * @argv: arg vector for process 353 * @argv: arg vector for process
354 * @envp: environment for process 354 * @envp: environment for process
355 * @gfp_mask: gfp mask for memory allocation
355 * 356 *
356 * Returns either %NULL on allocation failure, or a subprocess_info 357 * Returns either %NULL on allocation failure, or a subprocess_info
357 * structure. This should be passed to call_usermodehelper_exec to 358 * structure. This should be passed to call_usermodehelper_exec to
358 * exec the process and free the structure. 359 * exec the process and free the structure.
359 */ 360 */
360struct subprocess_info *call_usermodehelper_setup(char *path, 361struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
361 char **argv, char **envp) 362 char **envp, gfp_t gfp_mask)
362{ 363{
363 struct subprocess_info *sub_info; 364 struct subprocess_info *sub_info;
364 sub_info = kzalloc(sizeof(struct subprocess_info), GFP_ATOMIC); 365 sub_info = kzalloc(sizeof(struct subprocess_info), gfp_mask);
365 if (!sub_info) 366 if (!sub_info)
366 goto out; 367 goto out;
367 368
@@ -494,7 +495,7 @@ int call_usermodehelper_pipe(char *path, char **argv, char **envp,
494 struct subprocess_info *sub_info; 495 struct subprocess_info *sub_info;
495 int ret; 496 int ret;
496 497
497 sub_info = call_usermodehelper_setup(path, argv, envp); 498 sub_info = call_usermodehelper_setup(path, argv, envp, GFP_KERNEL);
498 if (sub_info == NULL) 499 if (sub_info == NULL)
499 return -ENOMEM; 500 return -ENOMEM;
500 501
diff --git a/kernel/sys.c b/kernel/sys.c
index 14e97282eb6c..6c2188046048 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1795,7 +1795,7 @@ int orderly_poweroff(bool force)
1795 goto out; 1795 goto out;
1796 } 1796 }
1797 1797
1798 info = call_usermodehelper_setup(argv[0], argv, envp); 1798 info = call_usermodehelper_setup(argv[0], argv, envp, GFP_ATOMIC);
1799 if (info == NULL) { 1799 if (info == NULL) {
1800 argv_free(argv); 1800 argv_free(argv);
1801 goto out; 1801 goto out;