Skip to content

Commit 1cc684a

Browse files
oleg-nesterovtorvalds
authored andcommitted
kmod: make __request_module() killable
As Tetsuo Handa pointed out, request_module() can stress the system while the oom-killed caller sleeps in TASK_UNINTERRUPTIBLE. The task T uses "almost all" memory, then it does something which triggers request_module(). Say, it can simply call sys_socket(). This in turn needs more memory and leads to OOM. oom-killer correctly chooses T and kills it, but this can't help because it sleeps in TASK_UNINTERRUPTIBLE and after that oom-killer becomes "disabled" by the TIF_MEMDIE task T. Make __request_module() killable. The only necessary change is that call_modprobe() should kmalloc argv and module_name, they can't live in the stack if we use UMH_KILLABLE. This memory is freed via call_usermodehelper_freeinfo()->cleanup. Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Tejun Heo <tj@kernel.org> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3e63a93 commit 1cc684a

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

‎kernel/kmod.c‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ static DECLARE_RWSEM(umhelper_sem);
6060
*/
6161
char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
6262

63+
static void free_modprobe_argv(struct subprocess_info *info)
64+
{
65+
kfree(info->argv[3]); /* check call_modprobe() */
66+
kfree(info->argv);
67+
}
68+
6369
static int call_modprobe(char *module_name, int wait)
6470
{
6571
static char *envp[] = {
@@ -69,10 +75,26 @@ static int call_modprobe(char *module_name, int wait)
6975
NULL
7076
};
7177

72-
char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
78+
char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
79+
if (!argv)
80+
goto out;
81+
82+
module_name = kstrdup(module_name, GFP_KERNEL);
83+
if (!module_name)
84+
goto free_argv;
85+
86+
argv[0] = modprobe_path;
87+
argv[1] = "-q";
88+
argv[2] = "--";
89+
argv[3] = module_name; /* check free_modprobe_argv() */
90+
argv[4] = NULL;
7391

7492
return call_usermodehelper_fns(modprobe_path, argv, envp,
75-
wait, NULL, NULL, NULL);
93+
wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
94+
free_argv:
95+
kfree(argv);
96+
out:
97+
return -ENOMEM;
7698
}
7799

78100
/**

0 commit comments

Comments
 (0)