03 Linux Modules
03 Linux Modules
Modules and
misc devices
Lionel Auroux
Modules
Lionel Auroux
2017-09-29
Lionel Auroux
Modules
Modules
Lionel Auroux
Modules
Lionel Auroux
$ file hello.ko
hello.ko: ELF 64-bit LSB relocatable, x86-64,
Modules
Lionel Auroux
Modules The Linux build system is complex, yet is very easy to use,
and almost always produce the desired result.
Compiling a module is trivial:
Makefile
obj-m := hello.o
Build
$ make -C ~/linux M=`pwd` modules
Lionel Auroux
Modules
The Linux build system is complex, yet is very easy to use,
and almost always produce the desired result.
Compiling a module is trivial:
Makefile
obj-m := hello.o
hello-objs := hello-file1.o hello-file2.o
Build
$ make -C ~/linux M=`pwd` modules
Lionel Auroux
Kconfig
config HELLO
tristate "Build with the hello support?"
Makefile
obj-$(CONFIG_HELLO) := hello.o
hello-objs := hello-file1.o hello-file2.o
Lionel Auroux
Lionel Auroux
Modules
Since Linux 3.7
Requires CONFIG_MODULE_SIG=y.
Cryptographically signs modules during installation (make
modules_install)
Uses RSA and SHA-{1,224,256,384,512}.
The private key is only needed during the build, after which
it can be deleted or stored securely.
The public key gets built into the kernel so that it can be
used to check the signatures as the modules are loaded.
See public keys in /proc/keys.
Lionel Auroux
Userspace tools: insmod and modprobe.
Modules
modprobe will try to insert other modules so that all
symbol are resolvable.
They use the init_module(2) syscall, which performs
(roughly):
signature checks (if enabled)
mernel memory allocation
module .text section copy
license and version checks
symbol resolving using the kernel symbol table
sysfs and internal registrations
Lionel Auroux
Modules
Lionel Auroux
Modules
A module has to be recompiled for each version fo the
kernel that you want to link it to.
If CONFIG_MODVERSIONS=y, a simple ABI consistency
check is performed over the prototypes of exported symbols.
When building a module, a CRC is computed for each
exported symbol, and stored in Module.symvers and in
the generated module.mod.c.
Versions checks can be bypassed, but it is not wise to do so.
module_param_array(name,type,num,perm);