umh: Remove call_usermodehelper_setup_file.
authorEric W. Biederman <ebiederm@xmission.com>
Wed, 24 Jun 2020 22:01:18 +0000 (17:01 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Sat, 4 Jul 2020 14:34:26 +0000 (09:34 -0500)
The only caller of call_usermodehelper_setup_file is fork_usermode_blob.
In fork_usermode_blob replace call_usermodehelper_setup_file with
call_usermodehelper_setup and delete fork_usermodehelper_setup_file.

For this to work the argv_free is moved from umh_clean_and_save_pid
to fork_usermode_blob.

v1: https://lkml.kernel.org/r/87zh8qf0mp.fsf_-_@x220.int.ebiederm.org
v2: https://lkml.kernel.org/r/87o8p163u1.fsf_-_@x220.int.ebiederm.org
Link: https://lkml.kernel.org/r/20200702164140.4468-4-ebiederm@xmission.com
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Tested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
include/linux/umh.h
kernel/umh.c

index aae16a0ebd0f94799483ca4cef9cdc51bbd61654..de08af00c68a79f4aa75097e9554104e89270294 100644 (file)
@@ -39,9 +39,6 @@ call_usermodehelper_setup(const char *path, char **argv, char **envp,
                          int (*init)(struct subprocess_info *info, struct cred *new),
                          void (*cleanup)(struct subprocess_info *), void *data);
 
-struct subprocess_info *call_usermodehelper_setup_file(struct file *file,
-                         int (*init)(struct subprocess_info *info, struct cred *new),
-                         void (*cleanup)(struct subprocess_info *), void *data);
 struct umh_info {
        const char *cmdline;
        struct file *pipe_to_umh;
index 26c3d493f168a6fb47a96d7d254caf507a21af1e..b8fa9b99b366d51744c923af48e37d28c1aba989 100644 (file)
@@ -402,33 +402,6 @@ struct subprocess_info *call_usermodehelper_setup(const char *path, char **argv,
 }
 EXPORT_SYMBOL(call_usermodehelper_setup);
 
-struct subprocess_info *call_usermodehelper_setup_file(struct file *file,
-               int (*init)(struct subprocess_info *info, struct cred *new),
-               void (*cleanup)(struct subprocess_info *info), void *data)
-{
-       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);
-       if (!sub_info)
-               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);
-       sub_info->path = "none";
-       sub_info->file = file;
-       sub_info->init = init;
-       sub_info->cleanup = cleanup;
-       sub_info->data = data;
-       return sub_info;
-}
-
 static int umd_setup(struct subprocess_info *info, struct cred *new)
 {
        struct umh_info *umh_info = info->data;
@@ -479,8 +452,6 @@ static void umd_cleanup(struct subprocess_info *info)
                fput(umh_info->pipe_to_umh);
                fput(umh_info->pipe_from_umh);
        }
-
-       argv_free(info->argv);
 }
 
 /**
@@ -501,7 +472,9 @@ static void umd_cleanup(struct subprocess_info *info)
  */
 int fork_usermode_blob(void *data, size_t len, struct umh_info *info)
 {
+       const char *cmdline = (info->cmdline) ? info->cmdline : "usermodehelper";
        struct subprocess_info *sub_info;
+       char **argv = NULL;
        struct file *file;
        ssize_t written;
        loff_t pos = 0;
@@ -520,11 +493,16 @@ int fork_usermode_blob(void *data, size_t len, struct umh_info *info)
        }
 
        err = -ENOMEM;
-       sub_info = call_usermodehelper_setup_file(file, umd_setup, umd_cleanup,
-                                                 info);
+       argv = argv_split(GFP_KERNEL, cmdline, NULL);
+       if (!argv)
+               goto out;
+
+       sub_info = call_usermodehelper_setup("none", argv, NULL, GFP_KERNEL,
+                                            umd_setup, umd_cleanup, info);
        if (!sub_info)
                goto out;
 
+       sub_info->file = file;
        err = call_usermodehelper_exec(sub_info, UMH_WAIT_EXEC);
        if (!err) {
                mutex_lock(&umh_list_lock);
@@ -532,6 +510,8 @@ int fork_usermode_blob(void *data, size_t len, struct umh_info *info)
                mutex_unlock(&umh_list_lock);
        }
 out:
+       if (argv)
+               argv_free(argv);
        fput(file);
        return err;
 }