• 主页
所有文章 友链 关于我

  • 主页

Linux kernel 源码调试踩坑记录

2020-05-12

捣鼓了一整天,记录下踩的坑

参考平凡之路公众号

在参考钞sir

一路编译下来,都没啥问题,但是调试的时候就出毛病了:

YYB9b9.png

启动脚本是这样的:

1
2
3
4
5
6
7
qemu-system-x86_64 \
-kernel ~/linux-5.2.9/arch/x86_64/boot/bzImage \
-initrd ~/busybox-1.31.0/rootfs.img \
-append "console=ttyS0 root=/dev/ram rdinit=/sbin/init" \
-cpu kvm64,+smep,+smap \
-nographic \
-gdb tcp::1234

感jio没什么毛病,但就是没有符号,百度谷歌搜索了3个多小时还是没解决,我直接裂开.jpg

无奈只能重新在编译一次 (编译一次要好久啊)。因为这个内核是我寒假的时候编译的,时间隔得有点久,所以不知道当时有没有漏掉了哪一步

重新编译好后,谷歌到一篇文章说可能是开了kaslr的问题,所以在启动脚本里加了一句nokaslr,奇迹发生了(好吧,是我太蠢了):

YYBdVs.png

gef真好用.jpg

知道了原因后,开了aslr的话,也没问题了,只要手动填下vmlinux的基地址就好:

1
2
3
4
gef➤  add-symbol-file ./vmlinux 0xffffffffaa600000
add symbol table from file "./vmlinux" at
.text_addr = 0xffffffffaa600000
Reading symbols from ./vmlinux...done.

YYDcfP.png

现在想想,我有点傻

第二天编译低版本的内核时,又报错了:

1
2
3
4
5
6
7
8
9
cc1: sorry, unimplemented: -mfentry isn’t supported for 32-bit in combination with -fpic
scripts/Makefile.build:294: recipe for target 'arch/x86/entry/vdso/vdso32/note.o' failed
make[3]: *** [arch/x86/entry/vdso/vdso32/note.o] Error 1
scripts/Makefile.build:403: recipe for target 'arch/x86/entry/vdso' failed
make[2]: *** [arch/x86/entry/vdso] Error 2
scripts/Makefile.build:403: recipe for target 'arch/x86/entry' failed
make[1]: *** [arch/x86/entry] Error 2
Makefile:949: recipe for target 'arch/x86' failed
make: *** [arch/x86] Error 2

不过这次没花多少时间就解决了,参考了 https://patchwork.kernel.org/patch/9409661/

对Makefile打上Patch就好:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/Makefile b/Makefile
index 93beca4312c4..3e0a9afa428f 100644
--- a/Makefile
+++ b/Makefile
@@ -398,12 +398,12 @@ KBUILD_CPPFLAGS := -D__KERNEL__
KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-fno-strict-aliasing -fno-common \
-Werror-implicit-function-declaration \
- -Wno-format-security \
+ -Wno-format-security -fno-PIE \
-std=gnu89

KBUILD_AFLAGS_KERNEL :=
KBUILD_CFLAGS_KERNEL :=
-KBUILD_AFLAGS := -D__ASSEMBLY__
+KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
KBUILD_AFLAGS_MODULE := -DMODULE
KBUILD_CFLAGS_MODULE := -DMODULE
KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds

扫一扫,分享到微信

微信分享二维码
空指针5月公开赛pwn题解
Sudo CVE-2019-18634 复现
目录,不存在的…
© 2022 ruan
Hexo Theme Yilia by Litten
  • 所有文章
  • 友链
  • 关于我

tag:

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • 好舍友
beginner