# Linux Kernel Module Cheat

### 12.2. myinsmod

If you are feeling raw, you can insert and remove modules with our own minimal module inserter and remover!

    # init_module
    ./linux/myinsmod.out hello.ko
    # finit_module
    ./linux/myinsmod.out hello.ko "" 1
    ./linux/myrmmod.out hello

which teaches you how it is done from C code.

Source:

- userland/linux/myinsmod.c

- userland/linux/myrmmod.c

The Linux kernel offers two system calls for module insertion:

- `init_module`

- `finit_module`

and:

    man init_module

documents that:

> The finit_module() system call is like init_module(), but reads the module to be loaded from the file descriptor fd. It is useful when the authenticity of a kernel module can be determined from its location in the filesystem; in cases where that is possible, the overhead of using cryptographically signed modules to determine the authenticity of a module can be avoided. The param_values argument is as for init_module().

`finit` is newer and was added only in v3.8. More rationale: https://lwn.net/Articles/519010/

Bibliography: https://stackoverflow.com/questions/5947286/how-to-load-linux-kernel-modules-from-c-code