2021-06-16 07:18:56

by Tiezhu Yang

[permalink] [raw]
Subject: [RFC PATCH] umh: Check if sub_info->path is exist in call_usermodehelper_setup()

In call_usermodehelper_setup(), if strlen(sub_info->path) is not 0,
but in fact there is no such file, in this case, there is no need to
execute it, set sub_info->path as empty string to avoid meaningless
operations in call_usermodehelper_exec().

Here is an example:
init/do_mounts_initrd.c
static void __init handle_initrd(void)
{
[...]
info = call_usermodehelper_setup("/linuxrc", argv, envp_init,
GFP_KERNEL, init_linuxrc, NULL, NULL);
if (!info)
return;
call_usermodehelper_exec(info, UMH_WAIT_PROC);
[...]
}

$ ls /linuxrc
ls: cannot access '/linuxrc': No such file or directory

Signed-off-by: Tiezhu Yang <[email protected]>
---
kernel/umh.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/kernel/umh.c b/kernel/umh.c
index 36c1233..2312cc0 100644
--- a/kernel/umh.c
+++ b/kernel/umh.c
@@ -373,6 +373,17 @@ struct subprocess_info *call_usermodehelper_setup(const char *path, char **argv,
#else
sub_info->path = path;
#endif
+ if (strlen(sub_info->path) != 0) {
+ struct file *fp;
+
+ fp = filp_open(sub_info->path, O_RDONLY, 0);
+ if (IS_ERR(fp)) {
+ sub_info->path = "";
+ return sub_info;
+ }
+ filp_close(fp, NULL);
+ }
+
sub_info->argv = argv;
sub_info->envp = envp;

--
2.1.0