Linking and Unlinking Modules
A user can link a module into the running kernel by executing the insmod external program. This program performs the following operations:
Reads from the command line the name of the module to be linked.
Locates the file containing the module’s object code in the system directory tree. The file is usually placed in some subdirectory below /lib/modules.
Reads from disk the file containing the module’s object code.
Invokes the
init_module( )system call, passing to it the address of the User Mode buffer containing the module’s object code, the length of the object code, and the User Mode memory area containing the parameters of the insmod program.Terminates.
The sys_init_module( ) service
routine does all the real work; it performs the following main
operations:
Checks whether the user is allowed to link the module (the current process must have the
CAP_SYS_MODULEcapability). In every situation where one is adding functionality to a kernel, which has access to all data and processes on the system, security is a paramount concern.Allocates a temporary memory area for the module’s object code; then, copies into this memory area the data in the User Mode buffer passed as first parameter of the system call.
Checks that the data in the memory area effectively represents a module’s ELF object; otherwise, returns an error code.
Allocates a memory area for the parameters passed to the insmod program, and fills it with the data in the User Mode buffer whose address ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access