Welcome! Log In Create A New Profile

Advanced

Spawning processes with display output from Linux kernel module

Posted by yaronshr 
Spawning processes with display output from Linux kernel module
March 29, 2017 07:35PM
I am trying to spawn a process from a kernel module, that has visual output - for now, I'm just trying to spawn xeyes. I am trying to do this using call_usermodehelper. I am getting a return value of 256.

I am specifying these environmental variables in envp:
    [*] HOME=/
    [*] DISPLAY=:0 (this is what I get when I echo $DISPLAY in any of my terminals)
    [*] PATH=/sbin:/bin:/usr/sbin:/usr/bin

Here is my module code:

#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>

int spawnProcess(void) {

    char *argv[] = { "/usr/bin/xeyes", NULL };
    static char *envp[] = { "HOME=/","DISPLAY=:0", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL };

    printk(KERN_DEBUG "Inside spawnProcess\n" ) ;

    return call_usermodehelper( argv[0], argv, envp, UMH_WAIT_PROC ) ;
}

static int __init moduleLoader(void) {
    int i;
    printk(KERN_INFO "My module is loading...\n" ) ;
    i = spawnProcess();
    printk(KERN_DEBUG "return value %d\n",i) ;
    printk(KERN_INFO "My module is done loading.\n" ) ;
    return 0;
}

static void __exit moduleUnloader(void) {
    printk(KERN_INFO "My module was unloaded.\n" ) ;
    return;
}

module_init(moduleLoader) ;
module_exit(moduleUnloader) ;

MODULE_AUTHOR("Yaron Shragai" ) ;
MODULE_LICENSE("GPL" ) ;
MODULE_DESCRIPTION("Lorem ipsum dolor sit amet" ) ;

Here is the output in the system log:

Mar 29 17:38:16 yaron-VirtualBox kernel: [84070.533179] My module is loading...
Mar 29 17:38:16 yaron-VirtualBox kernel: [84070.533180] Inside spawnProcess
Mar 29 17:38:16 yaron-VirtualBox kernel: [84070.534297] return value 256
Mar 29 17:38:16 yaron-VirtualBox kernel: [84070.534299] My module is done loading.

I have been able to successfully spawn a process that does not generate display output (namely, /usr/bin/logger), as per the example here: [www.ibm.com]

I am running 64-bit Ubuntu 16.04 LTS on a VirtualBox VM.
Output from uname -a:
Linux yaron-VirtualBox 4.4.0-57-generic #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Thanks for any help!
Author:

Your Email:


Subject:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 8 plus 2?
Message: