umh: Add command line to user mode helpers
User mode helpers were spawned without a command line, and because
an empty command line is used by many tools to identify processes as
kernel threads, this could cause some issues.
Notably during killing spree on shutdown, since such helper would then
be skipped (i.e. not killed) which would result in the process remaining
alive, and thus preventing unmouting of the rootfs (as experienced with
the bpfilter umh).
Fixes: 449325b52b
("umh: introduce fork_usermode_blob() helper")
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
c94f026fb7
commit
876dcf2f3a
@ -44,6 +44,7 @@ struct subprocess_info *call_usermodehelper_setup_file(struct file *file,
|
|||||||
int (*init)(struct subprocess_info *info, struct cred *new),
|
int (*init)(struct subprocess_info *info, struct cred *new),
|
||||||
void (*cleanup)(struct subprocess_info *), void *data);
|
void (*cleanup)(struct subprocess_info *), void *data);
|
||||||
struct umh_info {
|
struct umh_info {
|
||||||
|
const char *cmdline;
|
||||||
struct file *pipe_to_umh;
|
struct file *pipe_to_umh;
|
||||||
struct file *pipe_from_umh;
|
struct file *pipe_from_umh;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
16
kernel/umh.c
16
kernel/umh.c
@ -405,11 +405,19 @@ struct subprocess_info *call_usermodehelper_setup_file(struct file *file,
|
|||||||
void (*cleanup)(struct subprocess_info *info), void *data)
|
void (*cleanup)(struct subprocess_info *info), void *data)
|
||||||
{
|
{
|
||||||
struct subprocess_info *sub_info;
|
struct subprocess_info *sub_info;
|
||||||
|
struct umh_info *info = data;
|
||||||
|
const char *cmdline = (info->cmdline) ? info->cmdline : "usermodehelper";
|
||||||
|
|
||||||
sub_info = kzalloc(sizeof(struct subprocess_info), GFP_KERNEL);
|
sub_info = kzalloc(sizeof(struct subprocess_info), GFP_KERNEL);
|
||||||
if (!sub_info)
|
if (!sub_info)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
sub_info->argv = argv_split(GFP_KERNEL, cmdline, NULL);
|
||||||
|
if (!sub_info->argv) {
|
||||||
|
kfree(sub_info);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
INIT_WORK(&sub_info->work, call_usermodehelper_exec_work);
|
INIT_WORK(&sub_info->work, call_usermodehelper_exec_work);
|
||||||
sub_info->path = "none";
|
sub_info->path = "none";
|
||||||
sub_info->file = file;
|
sub_info->file = file;
|
||||||
@ -458,10 +466,11 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void umh_save_pid(struct subprocess_info *info)
|
static void umh_clean_and_save_pid(struct subprocess_info *info)
|
||||||
{
|
{
|
||||||
struct umh_info *umh_info = info->data;
|
struct umh_info *umh_info = info->data;
|
||||||
|
|
||||||
|
argv_free(info->argv);
|
||||||
umh_info->pid = info->pid;
|
umh_info->pid = info->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,6 +480,9 @@ static void umh_save_pid(struct subprocess_info *info)
|
|||||||
* @len: length of the blob
|
* @len: length of the blob
|
||||||
* @info: information about usermode process (shouldn't be NULL)
|
* @info: information about usermode process (shouldn't be NULL)
|
||||||
*
|
*
|
||||||
|
* If info->cmdline is set it will be used as command line for the
|
||||||
|
* user process, else "usermodehelper" is used.
|
||||||
|
*
|
||||||
* Returns either negative error or zero which indicates success
|
* Returns either negative error or zero which indicates success
|
||||||
* in executing a blob of bytes as a usermode process. In such
|
* in executing a blob of bytes as a usermode process. In such
|
||||||
* case 'struct umh_info *info' is populated with two pipes
|
* case 'struct umh_info *info' is populated with two pipes
|
||||||
@ -500,7 +512,7 @@ int fork_usermode_blob(void *data, size_t len, struct umh_info *info)
|
|||||||
|
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
sub_info = call_usermodehelper_setup_file(file, umh_pipe_setup,
|
sub_info = call_usermodehelper_setup_file(file, umh_pipe_setup,
|
||||||
umh_save_pid, info);
|
umh_clean_and_save_pid, info);
|
||||||
if (!sub_info)
|
if (!sub_info)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user