0
votes

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 I am using is linux-3.13.0 and has the following source tree layout:

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

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.

My question is how can I insert the new(modified) ELF loader into the kernel given that the current ELF loader is present(as unloading it may prevent binaries from being executed)?

1
The obvious solution would be to compile a full kernel with your patched module, install it, and try booting with it. If it fails, you can fallback to the old safe kernel. - tux3
I still need to debug the new loader and the kernel compilation time takes half a day(if done entirely). It would be nicer to only work with as little files as possible. - Sebi
Compiling a kernel module is not a C++ issue. Please, untag it as C++. - Luis Colorado
@ Luis Colorado.Done you can reverse the down vote now. Thanks :) - Sebi

1 Answers

0
votes

What you have described is not really compiling a "kernel module" as it is commonly referred to. You have built an object that is statically linked into the kernel and there is no way that you can load just that object into a running kernel.

"kernel module" usually refers to "loadable kernel module" (LKM). Building and loading the fs as an LKM is what you need/want. Take a look at the below HOWTO. Follow that to build the desired fs as an LKM. Then you can just replace that one LKM (.ko) file and reboot (normally you can dynamically remove and insert LKMs but not sure how that will affect something fundamental like the ELF fs - you can try rmmod/modprobe without a reboot first if you ike).

http://www.tldp.org/HOWTO/Module-HOWTO/x73.html