* [RFC PATCH] umh: Check if sub_info->path is exist in call_usermodehelper_setup()
@ 2021-06-16 7:17 Tiezhu Yang
0 siblings, 0 replies; only message in thread
From: Tiezhu Yang @ 2021-06-16 7:17 UTC (permalink / raw)
To: Luis Chamberlain, Andrew Morton; +Cc: linux-kernel, Xuefeng Li
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 <yangtiezhu@loongson.cn>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-06-16 7:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16 7:17 [RFC PATCH] umh: Check if sub_info->path is exist in call_usermodehelper_setup() Tiezhu Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).