lkml.org 
[lkml]   [2020]   [Apr]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3 3/4] kmod: Return directly if module name is empty in request_module()
Date
If module name is empty, it is better to return directly at the beginning
of request_module() without doing the needless call_modprobe() operation.

Call trace:

request_module()
|
|
__request_module()
|
|
call_modprobe()
|
|
call_usermodehelper_exec() -- retval = sub_info->retval;
|
|
call_usermodehelper_exec_work()
|
|
call_usermodehelper_exec_sync() -- sub_info->retval = ret;
|
| --> call_usermodehelper_exec_async() --> do_execve()
|
kernel_wait4(pid, (int __user *)&ret, 0, NULL);

sub_info->retval is 256 after call kernel_wait4(), the function
call_usermodehelper_exec() returns sub_info->retval which is 256,
then call_modprobe() and __request_module() returns 256.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---

v3:
- no changes

v2:
- update the commit message to explain the detailed reason

kernel/kmod.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/kernel/kmod.c b/kernel/kmod.c
index 3cd075c..5851444 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -28,6 +28,8 @@

#include <trace/events/module.h>

+#define MODULE_NOT_FOUND 256
+
/*
* Assuming:
*
@@ -144,6 +146,9 @@ int __request_module(bool wait, const char *fmt, ...)
if (ret >= MODULE_NAME_LEN)
return -ENAMETOOLONG;

+ if (strlen(module_name) == 0)
+ return MODULE_NOT_FOUND;
+
ret = security_kernel_module_request(module_name);
if (ret)
return ret;
--
2.1.0
\
 
 \ /
  Last update: 2020-04-20 14:34    [W:0.155 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site