环境:
vmware:VMware® Workstation 17 Pro;17.5.0 build-22583795
ubuntu:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 23.10
Release: 23.10
Codename: mantic
内核版本
Linux version 6.5.0-21-generic (buildd@bos03-amd64-037) (x86_64-linux-gnu-gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0,
GNU ld (GNU Binutils for Ubuntu) 2.41) #21-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 7 14:17:40 UTC 2024
gmp、mpfr、mpc、gcc、
gcc version 9.5.0
go语言:go1.21.7 linux/amd64
qemu:
syzkaller:
go语言安装
wget https://golang.google.cn/dl/go1.21.7.linux-amd64.tar.gz
tar -xf go1.21.7.linux-amd64.tar.gz
解压后重命名为goroot
export GOROOT=`pwd`/goroot
export PATH=$GOROOT/bin:$PATH
以上两个名称重启会失效(先不管)
$ go version
go version go1.21.7 linux/amd64
$ git clone https://github.com/google/syzkaller
$ cd syzkaller
$ make
# 如果fuzz目标是arm 64位,则需指定交叉编译器,如下
# make CC=aarch64-linux-gnu-g++ TARGETARCH=arm64
等待---完成后
推荐一下另一个链接,非官方的链接 Index of /sites/ftp.kernel.org/pub/linux/kernel/
cd ~/workspace/source/kernel
tar -zxvf linux-5.4.tar.gz
cd linux-5.4
make defconfig
make kvm_guest.config
更改.config文件
pluma .config
一个个查找修改(对应参数没有设置的语句要删掉)
# Coverage collection.
CONFIG_KCOV=y # must
# Debug info for symbolization.
CONFIG_DEBUG_INFO=y
# Memory bug detector
CONFIG_KASAN=y
CONFIG_KASAN_INLINE=y
CONFIG_CONFIGFS_FS=y
CONFIG_SECURITYFS=y
#这个一定要加上
CONFIG_CMDLINE_BOOL=y
CONFIG_CMDLINE="net.ifnames=0"
make olddefconfig
make -j`nproc`
使用gcc 12.1.0编译旧linux内核时的会有警告,切换版本
改用gcc低版本
gcc/g++ 多版本间切换 - 知乎 (zhihu.com)
sudo apt-get install gcc-9(具体见另一篇切换gcc版本)
再次编译
make olddefconfig
make -j`nproc`
sudo apt-get install debootstrap
cd $IMAGE/
wget https://raw.githubusercontent.com/google/syzkaller/tools/create-image.sh -O create-image.sh
chmod +x create-image.sh
./create-image.sh
syzkaller安装与使用 - Zhiyu's Blog (qgrain.github.io)
创建image(注意,自2023-04-12 syzkaller的d4d447c commit之后,create-image.sh中的默认release由stretch变更为了bullseye)
~/source/image$ ls -l
总计 706844
-rw------- 1 root root 2602 3月 3 18:46 bullseye.id_rsa
-rw-r--r-- 1 root root 567 3月 3 18:46 bullseye.id_rsa.pub
-rw-r--r-- 1 root root 2147483648 3月 3 18:46 bullseye.img
drwxr-xr-x 17 root root 4096 3月 3 18:46 chroot
-rwxrwxr-x 1 ubuntu ubuntu 6436 3月 3 17:59 create-image.sh
:~/source/image$ egrep -c '(vmx|svm)' /proc/cpuinfo
8
自己的bzimage文件路径eg:/home/ubuntu/source/kernel/linux-5.4/arch/x86/boot/
验证
创建boot.sh文件
放入内容
-
测试构建镜像是否正常。(使用以下qemu启动命令测试,正常无任何报错进入系统,然后init 0 关机。)
qemu-system-x86_64 -m 2G -smp 2 -kernel 路径bzImage -append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" -drive file=路径source/image/bullseye.img,format=raw -net user,hostfwd=tcp:127.0.0.1:10021-:22 -net nic,model=e1000 -enable-kvm -nographic -pidfile vm.pid 2>&1 | tee vm.log
chmod +x boot.sh
执行文件sudo ./boot.sh
输入 root
root@syzkaller:~# ifconfig
-bash: ifconfig: command not found
发现ifconfig没有命令
下载net-tools
root@syzkaller:~# sudo apt install net-tools
再开一个终端
在这进行测试
ssh -i 路径bullseye.id_rsa -p 10021 -o "StrictHostKeyChecking no" root@localhost
my.cfg配置对应的syzkaller(syscall只有chmod)
my.cfg配置对应的syzkaller(syscall只有chmod)
{
"target": "linux/amd64",
"http": "127.0.0.1:56741",
"workdir": "/home/ubuntu/syzkaller/workdir",
"kernel_obj": "/home/ubuntu/source/kernel/linux-5.4",
"image": "/home/ubuntu/source/image/bullseye.img",
"sshkey": "/home//ubuntu/source/image/bullseye.id_rsa",
"syzkaller": "/home/ubuntu/syzkaller/",
"enable_syscalls": ["chmod"],
"procs": 8,
"type": "qemu",
"vm": {
"count": 4,
"kernel": "/home/ubuntu/source/kernel/linux-5.4/arch/x86/boot/bzImage",
"cpu": 2,
"mem": 2048,
"cmdline": "net.ifnames=0"
}
}
在syzkaller文件夹
sudo ./bin/syz-manager -config=my.cfg