基于完整发行版搭建内核验证环境

0x01 虚拟机(VM)安装及启动 1. 选择一个发行版,下载其安装镜像 选择格式为 .iso 的安装镜像进行下载。 2. 制作根文件系统(rootfs)镜像 总体思路:启动一个 QEMU 虚拟机,以 rootfs 镜像文件为硬盘,以安装镜像 iso 文件为光盘。设置虚拟机从光盘启动,将系统安装至硬盘。 1# create an empty rootfs image file 2qemu-img create -f qcow2 rootfs.qcow2 128G 3 4# boot from CD-ROM, so that OS can be installed into the rootfs image …

ELF 调试器示例代码

这份调试器的示例代码来自《Learning Linux Binary Analysis》 书中第三章的“A simple ptrace-based debugger”一节,添加了一些调试打印和关于代码细节的注释。其他相关内容可查阅此书。 1#include <stdio.h> 2#include <string.h> 3#include <stdlib.h> 4#include <unistd.h> 5#include <fcntl.h> 6#include <errno.h> 7#include <signal.h> 8#include …

向 Linux 内核社区提交补丁的流程

制作补丁 下载代码, 如 linux-next 仓 : 1git clone https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 编辑文件,git diff 查看修改的内容。 添加文件到工作区: 1git add <file> 生成 commit(-s 添加 Signed-off-by): 1git commit -s 编写 Commit Message 的注意事项 补丁的标题要合适,可以使用 git log 参考已有补丁的标题;标题要反映补丁实际修改,避免太抽象或空乏。 Commit Message 要写清楚问题,根因分析,以及解决方 …

记一次 Android Native 层的 Debug 过程

记录这次 Debug 的原因主要是在 debug 过程中用到了之前写的另一篇贴文 所描述的一些做法,并且整个过程也比较曲折,其中的一些现象及其背后的原因也比较罕见。 先给个简单的 Takeaway:如果发生了段错误但 Logcat 中没有打印堆栈,可以考虑一下“人为捕获了 SIGSEGV 信号,但挂接的处理函数出错崩溃”这种情况。 问题现象 当时是在协助开发某 Android 底层框架 A 的新版本。在某次合入新代码后进行测试,发现其上层 App 在运行时会发生“必现但时间及场景不定”的崩溃。比较奇怪的是,Logcat 中完全没有打印 App 崩溃时的错误类型或堆栈信息。 原因定位 后面在 Logcat 中找到的一些边缘信息指出,崩 …

"Tricks and Craft" in Bash Scripting

Process Input Line by Line 1#!/bin/bash 2input="path/to/file" 3while IFS= read -r line 4do 5 # process each read-in line 6 echo "$line" 7done < "$input" # NORICE HERE Pay attention to the < part following done on the last line. It redirects the $input file to stdin of read process, making …