aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/kernel
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-07-17 12:36:05 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-07-17 12:39:11 +0200
commitcc1c342923b30616acc9344fe5eade7eb1412850 (patch)
tree10899cc66516fcfc9e63acfa0c64218a5e6bd840 /pkg/kernel
parente489b6cafdd3702f6d14307ae2f2278c3c2f6783 (diff)
syz-ci: allow to specify cmdline/sysctls
Allow to specify per-kernel command line and sysctl values to more closely mimic the target kernel.
Diffstat (limited to 'pkg/kernel')
-rw-r--r--pkg/kernel/generated.go16
-rw-r--r--pkg/kernel/kernel.go4
2 files changed, 15 insertions, 5 deletions
diff --git a/pkg/kernel/generated.go b/pkg/kernel/generated.go
index e9b00b345..a3d0ffcd6 100644
--- a/pkg/kernel/generated.go
+++ b/pkg/kernel/generated.go
@@ -35,11 +35,13 @@ sudo sed -i "/^root/ { s/:x:/::/ }" disk.mnt/etc/passwd
echo "T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100" | sudo tee -a disk.mnt/etc/inittab
echo -en "auto lo\niface lo inet loopback\nauto eth0\niface eth0 inet dhcp\n" | sudo tee disk.mnt/etc/network/interfaces
echo "debugfs /sys/kernel/debug debugfs defaults 0 0" | sudo tee -a disk.mnt/etc/fstab
+
echo "kernel.printk = 7 4 1 3" | sudo tee -a disk.mnt/etc/sysctl.conf
echo "debug.exception-trace = 0" | sudo tee -a disk.mnt/etc/sysctl.conf
-echo "net.core.bpf_jit_enable = 1" | sudo tee -a disk.mnt/etc/sysctl.conf
-echo "net.core.bpf_jit_harden = 2" | sudo tee -a disk.mnt/etc/sysctl.conf
-echo "net.ipv4.ping_group_range = 0 65535" | sudo tee -a disk.mnt/etc/sysctl.conf
+if [ -f $SYZ_SYSCTL_FILE ]; then
+ cat $SYZ_SYSCTL_FILE | sudo tee -a disk.mnt/etc/sysctl.conf
+fi
+
echo -en "127.0.0.1\tlocalhost\n" | sudo tee disk.mnt/etc/hosts
echo "nameserver 8.8.8.8" | sudo tee -a disk.mnt/etc/resolve.conf
echo "ClientAliveInterval 420" | sudo tee -a disk.mnt/etc/ssh/sshd_config
@@ -50,6 +52,12 @@ sudo mkdir -p disk.mnt/root/.ssh
sudo cp key.pub disk.mnt/root/.ssh/authorized_keys
sudo chown root disk.mnt/root/.ssh/authorized_keys
sudo mkdir -p disk.mnt/boot/grub
+
+CMDLINE=""
+if [ -f $SYZ_CMDLINE_FILE ]; then
+ CMDLINE=$(awk '{printf("%s ", $0)}' $SYZ_CMDLINE_FILE)
+fi
+
cat << EOF | sudo tee disk.mnt/boot/grub/grub.cfg
terminal_input console
terminal_output console
@@ -63,7 +71,7 @@ menuentry 'linux' --class gnu-linux --class gnu --class os {
insmod part_msdos
insmod ext2
set root='(hd0,1)'
- linux /vmlinuz root=/dev/sda1 console=ttyS0 earlyprintk=serial vsyscall=native rodata=n ftrace_dump_on_oops=orig_cpu oops=panic panic_on_warn=1 nmi_watchdog=panic panic=86400 kvm-intel.nested=1 kvm-intel.unrestricted_guest=1 kvm-intel.vmm_exclusive=1 kvm-intel.fasteoi=1 kvm-intel.ept=1 kvm-intel.flexpriority=1 kvm-intel.vpid=1 kvm-intel.emulate_invalid_guest_state=1 kvm-intel.eptad=1 kvm-intel.enable_shadow_vmcs=1 kvm-intel.pml=1 kvm-intel.enable_apicv=1
+ linux /vmlinuz root=/dev/sda1 console=ttyS0 earlyprintk=serial vsyscall=native rodata=n ftrace_dump_on_oops=orig_cpu oops=panic panic_on_warn=1 nmi_watchdog=panic panic=86400 $CMDLINE
}
EOF
sudo grub-install --boot-directory=disk.mnt/boot --no-floppy /dev/nbd0
diff --git a/pkg/kernel/kernel.go b/pkg/kernel/kernel.go
index 208b61815..5b97715b4 100644
--- a/pkg/kernel/kernel.go
+++ b/pkg/kernel/kernel.go
@@ -68,8 +68,10 @@ func build(dir, compiler string) error {
// CreateImage creates a disk image that is suitable for syzkaller.
// Kernel is taken from kernelDir, userspace system is taken from userspaceDir.
+// If cmdlineFile is not empty, contents of the file are appended to the kernel command line.
+// If sysctlFile is not empty, contents of the file are appended to the image /etc/sysctl.conf.
// Produces image and root ssh key in the specified files.
-func CreateImage(kernelDir, userspaceDir, image, sshkey string) error {
+func CreateImage(kernelDir, userspaceDir, cmdlineFile, sysctlFile, image, sshkey string) error {
tempDir, err := ioutil.TempDir("", "syz-build")
if err != nil {
return err