Skip to content
Advertisement

How to use system() in a kernel module as stdlib.h cannot be used in a kernel program?

When developing a kernel module in Linux, using the C standard library isn’t allowed. However, in case I need to use some common functionality like system(), how do I implement this?

Advertisement

Answer

The answer is: you don’t. There are very, very few instances in which you would need to do something similar to system(), that is to call a user-space application from kernel space. In those special cases, there is the usermode-helper API available, which allows launching (and possibly waiting for) arbitrary user space programs from kernel space.

However, it must be noted that when designing a module you should really avoid being dependent on the output/execution of other user space programs. In the best case scenario, this slows the system down, while in the worst case it can also break kernel/user space isolation and introduce critical vulnerabilities. The existing instances of usage of the call_usermodehelper() function in modern kernel versions can almost be counted on the tips of your hands. You will basically never need to do such a thing when writing a kernel module. If you think you do, you should re-think about it twice first.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement