我需要修改ELF加载器的Ubuntu 14.04发行版的内核实现。 使用下载的资源:
sudo apt-get source linux-image-$(uname -r)
我运行了configuration脚本:
make config
在根源树中。 在看似无尽的input请求序列之后,脚本创build了构build内核所需的.config文件(或一组模块)。 我正在使用的内核版本是linux-3.13.0,并具有以下源代码树布局:
$ 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
ELF加载器位于/path/to/source/fs/binfmt_elf.c中 。 在这个问题之后,为了编译一个单独的模块,运行就足够了
make /path/to/module/directory
在这种情况下,这将是:
make ./path/to/source/fs
汇编很长, 大约需要20分钟(在一台虚拟机上),并将输出写入(默认)在模块所在的同一目录中。 我已经find了运行的对象文件:
find . -name "*.o"
in / path / to / source / fs。 通过运行以下名称来筛选ELF加载器的名称:
find . -name "*elf*.o"
在当前的来源中,它被写入(默认)在:
/path/to/source/fs/binfmt_elf.o
通过本教程,我已经注意到内核模块具有命名约定[module_name] .ko ,以便将它们与用户空间对象文件区分开来。
我的问题是我如何插入新的(修改后的)ELF加载器到内核中,因为当前ELF加载器存在(因为卸载它可能会阻止二进制文件被执行)?
编辑#1:
运行lsmod给出:
$ lsmod Module Size Used by nls_utf8 12557 1 isofs 39835 1 vboxsf 39690 0 snd_intel8x0 38153 2 snd_ac97_codec 130285 1 snd_intel8x0 ac97_bus 12730 1 snd_ac97_codec snd_pcm 102099 2 snd_ac97_codec,snd_intel8x0 snd_page_alloc 18710 2 snd_intel8x0,snd_pcm snd_seq_midi 13324 0 snd_seq_midi_event 14899 1 snd_seq_midi rfcomm 69160 0 snd_rawmidi 30144 1 snd_seq_midi bnep 19624 2 bluetooth 391196 10 bnep,rfcomm snd_seq 61560 2 snd_seq_midi_event,snd_seq_midi snd_seq_device 14497 3 snd_seq,snd_rawmidi,snd_seq_midi snd_timer 29482 2 snd_pcm,snd_seq joydev 17381 0 snd 69238 12 snd_ac97_codec,snd_intel8x0,snd_timer,snd_pcm,snd_seq,snd_rawmidi,snd_seq_device,snd_seq_midi serio_raw 13462 0 vboxguest 248441 7 vboxsf i2c_piix4 22155 0 soundcore 12680 1 snd mac_hid 13205 0 parport_pc 32701 0 ppdev 17671 0 vboxvideo 12658 0 drm 303102 1 vboxvideo lp 17759 0 parport 42348 3 lp,ppdev,parport_pc hid_generic 12548 0 usbhid 52570 0 hid 106148 2 hid_generic,usbhid psmouse 106678 0 ahci 25819 2 libahci 32560 1 ahci e1000 145174 0
哪个模块需要编译为LKM才能包含ELF加载器。 默认情况下,加载器被内置到基础内核中。
尝试这个:
我如何构build一个单一的树内核模块?
或者,我通常这样做的方式如下所示。 这是来自记忆,可能会或可能不会为你工作。 它也构build了所有的模块。
安装当前的内核源码:
apt-get source linux-image-$(uname -r) cd /usr/src/linux-$(uname -r) cp /boot/config-$(uname -r) . make menuconfig ... enable the device then... make modules make modules_install reboot
如果某些设备没有自动加载,则需要将模块名称添加到/ etc / modules中。