Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Linux kernel module (.ko)

From ReverseEngineering.wiki
Format
On this wiki Facts · Code · Notes · Topics

Loadable Linux kernel modules (.ko): ET_REL ELF objects with a .modinfo section of NUL-separated tag=value strings (vermagic, license, srcversion, depends), a `__versions` table of symbol CRCs, the struct module in .gnu.linkonce.this_module and the export tables __ksymtab and __kcrctab.

A .ko is a relocatable ELF object (ET_REL) that the kernel links itself at load time. Distributions also ship .ko.gz, .ko.xz (Format:XZ) and .ko.zst (Format:Zstandard).

.modinfo

Section .modinfo holds NUL-terminated tag=value strings, one per MODULE_INFO use, unaligned: Fact:Linux kernel module (.ko)/identification/modinfo tags. Read it with modinfo or strings. Tags: vermagic=, license=, srcversion= (checksum of the sources), depends=, name=, intree=Y, alias= (device matching), parm=/parmtype=, firmware=, import_ns=, description=, author=, version=.

The vermagic string is <UTS_RELEASE> SMP preempt mod_unload modversions <arch flags>: Fact:Linux kernel module (.ko)/behavior/vermagic string composition. A module loads only when it equals the running kernel's (or with force flags).

__versions (CONFIG_MODVERSIONS)

Section __versions is an array of struct modversion_info, one record per imported symbol: Fact:Linux kernel module (.ko)/struct/modversion info. The first record is module_layout (a CRC of struct module). Current sources also emit __version_ext_crcs (u32 array) and __version_ext_names (consecutive NUL-terminated names) for names too long for the old table. The loader compares the CRCs with the exporter's __kcrctab.

Exports

An exporting module has __ksymtab, __ksymtab_gpl, __ksymtab_strings (names and namespaces) and __kcrctab/__kcrctab_gpl. Entries are absolute pointers on old kernels and 32-bit self-relative offsets where CONFIG_HAVE_ARCH_PREL32_RELOCATIONS holds (x86-64, arm64): Fact:Linux kernel module (.ko)/struct/kernel symbol, Fact:Linux kernel module (.ko)/struct/kernel symbol absolute. How the sections are generated changed several times: Fact:Linux kernel module (.ko)/behavior/Export tables generated by modpost.

struct module

__this_module sits in section .gnu.linkonce.this_module (Fact:Linux kernel module (.ko)/identification/Module descriptor section); its init/exit members point at init_module/cleanup_module, so relocations against that section reveal the entry points.

Reversing tips

  • .symtab is normally kept; kernel functions the module calls are undefined symbols resolved by the loader through the export tables.
  • .BTF may be present (Format:BTF (BPF Type Format)).
  • license= values GPL, GPL v2, Dual MIT/GPL and similar are GPL compatible; other values taint the kernel and cannot import _gpl exports.

See Platform:Linux kernel.

Signature and compression

Signed modules

When CONFIG_MODULE_SIG is used the build appends, after the ELF, the PKCS#7 signature, a 12-byte struct module_signature and the 28-byte text marker ~Module signature appended~ plus newline at the very end of the file: Fact:Linux kernel module (.ko)/struct/module signature, Fact:Linux kernel module (.ko)/identification/signature marker. Section headers and e_shoff are untouched, so ELF tools read a signed module normally; the trailing bytes are not part of any section. This is recognition only: signed and unsigned modules differ just by the trailer, and the kernel strips it before parsing.

The loader refuses modules whose vermagic or modversions were forced off (the MODULE_INIT_IGNORE_* flags) in the signature check, because that would no longer be the signed module (kernel/module/signing.c).

Compressed modules (.ko.gz, .ko.xz, .ko.zst)

With CONFIG_MODULE_COMPRESS the kernel itself decompresses the file at load time (Fact:Linux kernel module (.ko)/identification/compressed modules). Decompress with gzip, xz or zstd first, then treat the result as a normal .ko. Unverified: that the signature trailer sits inside the compressed stream (sign, then compress); check by decompressing one signed distribution module and looking at its last 28 bytes.

Code & repositories

  • https://github.com/torvalds/linux @ f909e534f5e34feb2ea2701d54df63e21aa506fc · license: GPL-2.0 WITH Linux-syscall-note (declared by the contributor for the files used; GitHub reports GPL-2.0 WITH Linux-syscall-note (read from COPYING; GitHub's detector did not classify it) for the repository)
    Linux kernel (GPL-2.0): Documentation/arch/arm64/booting.rst, include/uapi/linux/module_signature.h, kernel/module/signing.c, kernel/module/decompress.c, init/version-timestamp.c, kernel/kallsyms.c
    Tested on: source read, not run: source read, not run · checked 2026-10-18; last activity 2026-10-18