SwordWorth
SwordWorth

Reputation: 31

How to cross-compile ARM version of LKM?

I need to perform MITM attack on a router, which is embedded linux system and its architecture is ARM. The linux kernel is 2.4.24. By MITM attack I mean intercept the packet, reedit it and send it forward. I want to use netfilter. But when I try to cross compile the LKM, I encountered plenty of problems.

As usual, a LKM Makefile is as below:

obj-m+=hello.o
KDIR = /lib/modules/$(shell uname -r)/build

all:
    make -C $(KDIR) M=$(shell pwd) modules
clean:
    make -C $(KDIR) M=$(shell pwd) clean

I downloaded linux kernel 2.4.24. But when it comes to the cross compile environment, the problems arise.

How to set KDIR path? The Path where linux_kernel_2.4.24.tar.gz is extracted? Do I need to cross-compile the kernel first? How?

Firstly, I set KDIR to the path of linux_kernel_2.4.24, then make, the error is "The present kernel configuration has modules disabled". By now I have not successfully make menuconfig this verion of kernel.

Secondly, I try to cross-compile on CentOS 5.4 32bit, whose kernel is 2.6.18. When I add CC=arm-linux-gcc to Makefile and set KDIR as /lib/modules/$(shell uname -r)/build, the result says "there is no arm...".

Can anyone specify how to compile LKM of the old version kernel on the latest linux? And how to cross-compile ARM version of LKM?

Upvotes: 0

Views: 745

Answers (1)

Marco Bonelli
Marco Bonelli

Reputation: 69346

How to set KDIR path? The Path where linux_kernel_2.4.24.tar.gz is extracted?

Yes, just as you normally would for any other kind of module, KDIR needs to point to the built kernel source root.

Do I need to cross-compile the kernel first? How?

Yes you do. You do this by:

  1. Downloading/compiling/installing the correct cross-compilation toolchain. For example, on Debian to get an ARM cross-compilation toolchain I can do sudo apt install binutils-arm-linux-gnueabi, which will install all the binaries you normally have in binutils with the prefix arm-linux-gnueabi- (e.g. arm-linux-gnueabi-gcc, arm-linux-gnueabi-objdump, etc...). You need all of the binutils, not only gcc.
  2. Setting ARCH= to your desired target architecture, for example ARCH=arm.
  3. Setting CROSS_COMPILE= to your cross-compilation toolchain prefix, for example CROSS_COMPILE=arm-linux-. This also works if you want to use a downloaded toolchain as you can specify CROSS_COMPILE=/path/to/toolchain/ assuming this directory contains all the needed executables.
  4. Getting a valid config for the target system. If you have a .config on the system you can use that one (simply copy it from the target system into KDIR/.config) and then update it with make menuconfig.
  5. Building with make all or whatever other target you need.

Upvotes: 1

Related Questions