环境
- linux kernel版本:4.10.1
- gcc编译: 7.4
linux kernel开启KASAN和debug信息
1
2
3
4
5
6
7CONFIG_KCOV=y
CONFIG_DEBUG_INFO=y
CONFIG_KASAN=y
CONFIG_KASAN_INLINE=y
CONFIG_CONFIGFS_FS=y
CONFIG_SECURITYFS=y在编译的时候出现‘undefined reference to `____ilog2_NaN’ ‘
解决方案:patch 将该patch保存为patch.diff,拷贝到linux内核根目录下。
运行命令:patch -i patch.diff,提示输入文件时,先后输入include/linux/log2.h和tools/include/linux/log2.h即可。
Debug
编译Linux内核
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
CONFIG_DEBUG_KERNEL=y
CONFIG_DEBUG_INFO=y
CONFIG_CONSOLE_POLL=y
CONFIG_KDB_CONTINUE_CATASTROPHIC=0
CONFIG_KDB_DEFAULT_ENABLE=0x1
CONFIG_KDB_KEYBOARD=y
CONFIG_KGDB=y
CONFIG_KGDB_KDB=y
CONFIG_KGDB_LOW_LEVEL_TRAP=y
CONFIG_KGDB_SERIAL_CONSOLE=y
CONFIG_KGDB_TESTS=y
CONFIG_KGDB_TESTS_ON_BOOT=n
CONFIG_MAGIC_SYSRQ=y
CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE=0x1
CONFIG_SERIAL_KGDB_NMI=n
Add to your QEMU command:
1
2
append 'kgdbwait kgdboc=ttyS0,115200' \
serial tcp::1234,server,nowait
gdb连接
- gdb vmlinux
- target remote :1234
- c
PoC
- poc
- 在qemu里面的虚拟机里面运行poc
- 此时发生crash:
可以发现其访问了(rcx+rax)的地址区域, 而该地址是不可访问地址区域
- 手动下断点
- echo g > /proc/sysrq-trigger