Re: [PATCH v3 3/4] kmod: Return directly if module name is empty in request_module()

From: Luis Chamberlain
Date: Mon Apr 20 2020 - 14:19:37 EST


On Mon, Apr 20, 2020 at 08:33:54PM +0800, Tiezhu Yang wrote:
> 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@xxxxxxxxxxx>

Thanks for looking into this. I still cannot find where
userspace it returns 256. Can you? If I run modprobe without
an argument I see 1 returned.

At least kmod [0] has a series of cmd helper structs, the one for modprobe
seems to be kmod_cmd_compat_modprobe, and I can see -1 returned which
can be converted to 255. It can also return EXIT_FAILURE or EXIT_SUCCESS
and /usr/include/stdlib.h defines these as 1 and 0 respectively.

https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/

Luis