此源代码仓库是一系列示例,随博客文章 https://research.nccgroup.com/?p=18577 一并提供。
除跟随博客文章外,请勿将这些示例用于其他任何用途。它们特意包含漏洞,即便是“已修复”的版本也可能存在缺陷。
如果你想运行博客文章中的示例,以下指南应当能让你轻松完成。
获取 Rust for Linux 源代码。你可能需要安装 https://github.com/Rust-for-Linux/linux/blob/rust/Documentation/rust/quick-start.rst 上列出的一些依赖。
git clone https://github.com/Rust-for-Linux/linux rust-for-linux
cd rust-for-linux
git checkout bd123471269354fdd504b65b1f1fe5167cb555fc # latest commit at the point of writing
获取 virtme。你可能还需要安装 QEMU 和一些其他依赖。
git clone https://github.com/amluto/virtme
我发现 virtme 在快速测试核心内核或内核模块中的更改时非常有用。
构建大多数示例将运行的基础内核:
cd rust-for-linux
mkdir `pwd`.out
cp ../rustproofing-linux/configs/config-base `pwd`.out/.config
KBUILD_OUTPUT=`pwd`.out make -j$(nproc) LLVM=1
以及配置选项略有不同的变体:
mkdir `pwd`.out.ovf
cp `pwd`.out/.config `pwd`.out.ovf
scripts/config --file `pwd`.out.ovf/.config -d CONFIG_RUST_OVERFLOW_CHECKS
KBUILD_OUTPUT=`pwd`.out.ovf make -j$(nproc) LLVM=1
mkdir `pwd`.out.stackinit
cp `pwd`.out/.config `pwd`.out.stackinit
scripts/config --file `pwd`.out.stackinit/.config -e CONFIG_INIT_STACK_ALL_ZERO
KBUILD_OUTPUT=`pwd`.out.stackinit make -j$(nproc) LLVM=1
使用以下命令在 QEMU 中启动已构建的内核:
../virtme/virtme-run --kdir `pwd`.out --show-command --show-boot-console --mods=auto -a "kasan_multi_shot" --qemu-opts -cpu core2duo -m 1G -smp 2
当你需要运行另外两个内核时,请更改 --kdir 选项。
随后使用以下命令编译模块。请注意,KDIR 需要指向包含已编译内核的目录,并且在测试需要不同编译内核的示例时,你需要为 ../rust-for-linux.out.stackinit 和 ../rust-for-linux.out.ovf 重新编译。
cd ../rustproofing-linux
make LLVM=1 KDIR=../rust-for-linux.out
借助 test.sh 脚本加载模块并运行概念验证(proof-of-concept)漏洞利用。相关示例见博客文章。