Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What will happen if two kernel module export same symbol

Tags:

linux-kernel

If two kernel module contain EXPORT_SYMBOL(a), a is defined as: int a, what will happen if two module was inserted? which "a" will be used?

like image 298
Jianzhong Avatar asked Aug 11 '10 01:08

Jianzhong


People also ask

What does export symbol do?

It is used to qualify a declaration to a non-static symbol from another translation unit. EXPORT_SYMBOL() is specific to the Linux kernel. It is used in the translation unit of the definition to make the symbol available to loadable modules.

How are kernel modules linked?

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.

What can kernel modules do?

Kernel modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system. A module can be configured as built-in or loadable.

What two commands are used to load kernel modules?

To load a kernel module, use the /sbin/modprobe command followed by the kernel module name. By default, modprobe attempts to load the module from the /lib/modules/<kernel-version>/kernel/drivers/ subdirectories.


1 Answers

You can't insert duplicate symbols into the kernel. Example:

The xor module loaded in my kernel

nwatkins@kyoto:~$ lsmod | grep xor
xor                     4685  1 async_xor

The exported xor_blocks symbol in the xor module

nwatkins@kyoto:~$ nm /lib/modules/2.6.32-24-generic/kernel/crypto/xor.ko  | grep xor_blocks
0000000000000000 r __kcrctab_xor_blocks
0000000000000000 r __kstrtab_xor_blocks
0000000000000000 r __ksymtab_xor_blocks
0000000000000bb0 T xor_blocks

Another exported xor_blocks symbol in a module I created

nwatkins@kyoto:~$ nm mod-t1.ko  | grep xor
0000000000000000 r __kcrctab_xor_blocks
0000000000000000 r __kstrtab_xor_blocks
0000000000000000 r __ksymtab_xor_blocks
0000000000000000 T xor_blocks

Error reported from insmod

nwatkins@kyoto:~$ sudo insmod mod-t1.ko 
insmod: error inserting 'mod-t1.ko': -1 Invalid module format

Duplicate error message from dmesg

[422002.174033] mod_t1: exports duplicate symbol xor_blocks (owned by xor)
like image 79
Noah Watkins Avatar answered Sep 22 '22 17:09

Noah Watkins