3

I need to modify the ELF loader's kernel implementation of an Ubuntu 14.04 distribution. Having downloaded the sources using:

sudo apt-get source linux-image-$(uname -r)

I ran the configuration script:

make config

in the root source tree. After a seemingly endless sequence of input requests, the script created the .config file needed to build the kernel (or a set of modules). The kernel version that I am using is linux-3.13.0, and it has the following source tree layout:

$ ls 
arch              Documentation      fs          kernel          README             sound
block             drivers            include     lib             REPORTING-BUGS     tools
COPYING           dropped.txt        init        MAINTAINERS     samples            ubuntu
CREDITS           elf.dat            ipc         Makefile        scripts            usr
crypto            FileSystemMake     Kbuild      mm              security           virt
debian.master     firmware           Kconfig     net             shortcuts

The ELF loader is located in /path/to/source/fs/binfmt_elf.c. Following this question, in order to compile an individual module it is sufficient to run

make /path/to/module/directory

In this case that would be:

make /path/to/source/fs

The compilation is quite lengthy; it takes about twenty minutes (on a virtual machine) and the output is written (by default) in the same directory in which the module is located. I've found the object files by running:

find . -name "*.o"

in /path/to/source/fs. Filtering by name, the ELF loader can be located by running:

find . -name "*elf*.o"

In the current sources it is written (by default) in:

/path/to/source/fs/binfmt_elf.o

Having gone through this tutorial, I've noticed that kernel modules have the naming convention module_name.ko in order to distinguish them from user space object files.

How can I insert the new (modified) ELF loader into the kernel, given that the current ELF loader is present (and unloading it may prevent binaries from being executed)?

  • I'm just curious why you needed to use find to find binfmt_elf.o in /path/to/source/fs when you already knew that binfmt_elf.c was in that directory. – G-Man Says 'Reinstate Monica' Mar 10 '15 at 21:37
  • Yes, the source file was indeed but I haven't found any documentation on the output layout(where exactly are the kernel modules written) so I had to find() it. – Sebi Mar 10 '15 at 21:47
  • You need a make modules step to adapt the .o files to be suitable for loading as modules, givin you the .ko files. – wurtel Mar 11 '15 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.