[Q]insmod and User mode address memory allocation?

Hi Linux Guru,

Can anybody tell me why insmod allocates a memory area in the User Mode address space during its internal step? (Module is a kernel only concept. Why UserMode memory allocation??)

Following is a excerpt from a book. Pls see bottom for detail.

" A user can link a module into the running kernel by executing the /sbin/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.

Computes the size of the memory area needed to store the module code, its name, and the module object.

Invokes the create_module( ) system call, passing to it the name and size of the new module. The corresponding sys_create_module( ) service routine performs the following operations:

Checks whether the user is allowed to link the module (the current process must have the CAP_SYS_MODULE capability). In any 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.

Invokes the find_module( ) function to scan the module_list list of module objects looking for a module with the specified name. If it is found, the module has already been linked, so the system call terminates.

Invokes vmalloc( ) to allocate a memory area for the new module.

Initializes the fields of the module object at the beginning of the memory area and copies the name of the module right below the object.

Inserts the module object into the list pointed to by module_list.

Returns the starting address of the memory area allocated to the module.

Invokes the query_module( ) system call with the QM_MODULES subcommand to get the name of all already linked modules.

Invokes the query_module( ) system call with the QM_SYMBOL subcommand repeatedly, to get the kernel symbol table and the symbol tables of all modules that are already linked in.

Using the kernel symbol table, the module symbol tables, and the address returned by the create_module( ) system call, relocates the object code included in the module's file. This means replacing all occurrences of external and global symbols with the corresponding logical address offsets.

Allocates a memory area in the User Mode address space and loads it with a copy of the module object, the module's name, and the module's code relocated for the running kernel. The address fields of the object point to the relocated code. The init field is set to the relocated address of the module's init_module( ) function, if the module defines one. (Virtually all modules define a function of that name, which is invoked in the next step to perform any initialization required by the module.) Similarly, the cleanup field is set to the relocated address of the module's cleanup_module( ) function, if one is present. ...

Reply to
Loading thread data ...

[ snip ]

insmod does the linking, and since insmod is a user process, it must be accessible in the user address space. Yes it is also loaded in the kernel memory address, but if it is only there, insmod can't do much with it.

-- Steve

Reply to
Steven Rostedt

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.