Unless you have compiled your own kernel, you will not have a readily accessible vmlinux, which is an ELF executable. Instead, you will have a compressed kernel in /boot, usually named vmlinuz-<kernel_version>. This compressed kernel image can be decompressed, but the result is a kernel executable that has no symbol table. This poses a problem for forensics analysts or kernel debugging with GDB. The solution for most people in this case is to hope that their Linux distribution has a special package with their kernel version having debug symbols. If so, then they can download a copy of their kernel that has symbols from the distribution repository. In many cases, however, this is not possible, or not convenient for one reason or another. Nonetheless, this problem can be remedied with a custom utility that I designed and released in 2014. This tool is called
kdress, because it dresses the kernel symbol table.
Actually, it is named after an old tool by Michael Zalewskis, called dress. That tool would dress a static executable with a symbol table. This name originates from the fact that people run a program called strip
to remove symbols from an executable, and therefore "dress" is an appropriate name for a tool that rebuilds the symbol table. Our tool, kdress, simply takes information about symbols from either the System.map file or /proc/kallsyms depending on whichever is more readily available. Then, it reconstructs that information into the kernel executable by creating a section header for the symbol table. This tool can be found on my GitHub profile at https://github.com/elfmaster/kdress.
Here is an example that shows how to use the kdress utility to build a vmlinux image that can be loaded with GDB:
Usage: ./kdress vmlinuz_input vmlinux_output <system.map> $ ./kdress /boot/vmlinuz-`uname -r` vmlinux /boot/System.map-`uname -r` [+] vmlinux has been successfully extracted [+] vmlinux has been successfully instrumented with a complete ELF symbol table.
The utility has created an output file called vmlinux, which has a fully reconstructed symbol table. If, for example, we want to locate the sys_call_table in the kernel, then we can easily find it:
$ readelf -s vmlinux | grep sys_call_table 34214: ffffffff81801460 4368 OBJECT GLOBAL DEFAULT 4 sys_call_table 34379: ffffffff8180c5a0 2928 OBJECT GLOBAL DEFAULT 4 ia32_sys_call_table
Having a kernel image with symbols is very important for both debugging and forensic analysis. Nearly all forensics on the Linux kernel can be done with GDB and /proc/kcore.