I want to call mknod in my kernel driver. but never work. I tested some simple command, but all failed. my system is fedora 40, kernel 6.9.7. here is my test code :
static int __init call_usermodehelper_init(void)
{
int ret = -1;
char path[] = "/bin/mkdir";
char *argv[] = {path, "-p", "/tmp/new_dir", NULL};
char *envp[] = {"HOME=/",
"SHELL=/bin/bash",
"TERM=linux",
"PATH=/sbin:/bin:/usr/bin",
NULL};
printk("call_usermodehelper module is starting..!\n");
ret = call_usermodehelper(path, argv, envp, UMH_WAIT_PROC);
printk("ret=%d\n", ret);
return 0;
}
module_init(call_usermodehelper_init);
and the code never succeed. after I load the ko, no /tmp/touchX.txt is found. I have changed the argv many times for these days, and no success, the func returns -2/-13/256..
but when I compile and run the ko on other linux, Ubuntu/rhel, the call_usermodehelper can run normally. can anybody tell me why call_usermodehelper always fail on fedora?
I have tested it on other systems and it works fine. I wonder why it doesn't work on the fedora system
The problem has been solved. The reason was selinux. I set selinux to disabled and the function call_usermodehelper can be executed successfully.