Execute shell command in kernel module

前端 未结 3 939
半阙折子戏
半阙折子戏 2021-02-10 03:18

Is it possible to execute shell command in kernel module. I know that we can do it in user space C code using system subroutine.
I am debugging a kernel module

3条回答
  •  轮回少年
    2021-02-10 03:46

    You can use call_usermodehelper function. See the example of how to use it at the LXR#1 or LXR#2.

    UPD:

    argv[0] = "/bin/bash";
    argv[1] = "-c";
    argv[2] = "/usr/bin/free";
    argv[3] = NULL;
    
    envp[0] = "HOME=/";
    envp[1] = "TERM=linux";
    envp[2] = "PATH=/sbin:/usr/sbin:/bin:/usr/bin";
    envp[3] = NULL;
    
    call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
    

提交回复
热议问题