2018-09-13 22:34:34 +00:00
#!/bin/bash
2018-09-10 16:28:00 +00:00
# Copyright 2018 syzkaller project authors. All rights reserved.
2020-02-18 15:02:42 +00:00
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
2018-09-10 16:28:00 +00:00
# Produces GCE image of syz-ci running on OpenBSD.
# Mostly derived from Go buildlet generator with blessing from bradfitz@.
set -eu -o pipefail
2018-10-28 09:18:59 +00:00
readonly MIRROR = " ${ MIRROR :- cdn .openbsd.org } "
2020-04-17 00:39:55 +00:00
readonly VERSION = " ${ VERSION :- 6 .7 } "
2018-09-10 16:28:00 +00:00
readonly DOWNLOAD_VERSION = " ${ DOWNLOAD_VERSION :- snapshots } "
readonly RELNO = " ${ 2 :- ${ VERSION /./ } } "
# The only supported setting.
readonly ARCH = "amd64"
readonly ISO = " install ${ RELNO } - ${ ARCH } .iso "
readonly ISO_PATCHED = " install ${ RELNO } - ${ ARCH } -patched.iso "
if [ [ ! -f " ${ ISO } " ] ] ; then
curl -o " ${ ISO } " " https:// ${ MIRROR } /pub/OpenBSD/ ${ DOWNLOAD_VERSION } / ${ ARCH } /install ${ RELNO } .iso "
fi
# Create custom siteXX.tgz set.
2018-10-11 17:32:25 +00:00
rm -fr etc && mkdir -p etc
2018-09-10 16:28:00 +00:00
cat >install.site <<EOF
#!/bin/sh
2019-02-09 18:11:37 +00:00
PKGS = "bash gcc%8 git gmake go llvm nano wget"
2018-10-11 17:32:25 +00:00
PKG_PATH = https://${ MIRROR } /pub/OpenBSD/${ DOWNLOAD_VERSION } /packages/${ ARCH } / pkg_add -I \$ PKGS
2018-11-25 19:43:09 +00:00
PKG_PATH = pkg_info -I \$ PKGS && echo pkg_add OK
2018-09-10 16:28:00 +00:00
echo 'set tty com0' > boot.conf
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config
2018-09-26 07:41:21 +00:00
echo 'pass in on egress proto tcp from any to any port 80 rdr-to 127.0.0.1 port 8080' >> /etc/pf.conf
2018-09-28 09:13:51 +00:00
echo 'permit keepenv nopass syzkaller as root' > /etc/doas.conf
2018-09-10 16:28:00 +00:00
mkdir /syzkaller
echo '/dev/sd1a /syzkaller ffs rw,noauto 1 0' >> /etc/fstab
EOF
cat >etc/installurl <<EOF
https://${ MIRROR } /pub/OpenBSD
EOF
2018-09-13 22:34:34 +00:00
2018-09-10 16:28:00 +00:00
cat >etc/rc.local <<EOF
(
2018-12-09 03:56:43 +00:00
nc metadata.google.internal 80 <<EOF2 | tail -n1 > /etc/myname.gce \
2018-12-02 09:53:06 +00:00
&& echo >> /etc/myname.gce \
&& mv /etc/myname{ .gce,} \
&& hostname \$ ( cat /etc/myname)
2018-12-09 03:56:43 +00:00
GET /computeMetadata/v1/instance/hostname HTTP/1.0
Host: metadata.google.internal
Metadata-Flavor: Google
EOF2
2018-09-26 07:41:21 +00:00
set -eux
2018-09-10 16:28:00 +00:00
echo "starting syz-ci"
fsck -y /dev/sd1a
mount /syzkaller
2018-09-26 07:41:21 +00:00
su -l syzkaller <<EOF2
cd /syzkaller
set -eux
2018-12-19 18:30:56 +00:00
ulimit -d 8000000
2018-09-26 07:41:21 +00:00
test -x syz-ci || (
go get github.com/google/syzkaller/syz-ci &&
go build github.com/google/syzkaller/syz-ci)
2018-09-28 09:13:51 +00:00
./syz-ci -config ./config-openbsd.ci 2>& 1 | tee syz-ci.log &
2018-09-26 07:41:21 +00:00
EOF2
2018-09-10 16:28:00 +00:00
)
EOF
chmod +x install.site
2018-09-13 22:34:34 +00:00
cat >etc/rc.conf.local <<EOF
2018-09-16 07:19:10 +00:00
slaacd_flags = NO
smtpd_flags = NO
sndiod_flags = NO
2018-09-13 22:34:34 +00:00
EOF
2018-10-28 09:18:59 +00:00
cat >etc/sysctl.conf <<EOF
hw.smt= 1
EOF
2018-09-13 22:34:34 +00:00
tar --owner= root --group= root -zcvf site${ RELNO } .tgz install.site etc/*
2018-09-10 16:28:00 +00:00
# Autoinstall script.
cat >auto_install.conf <<EOF
System hostname = ci-openbsd
DNS domain name = syzkaller
Which network interface = vio0
IPv4 address for vio0 = dhcp
IPv6 address for vio0 = none
Password for root account = root
Public ssh key for root account = ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJeLpmSq+Dgrk01Ht+QtY0GDsY2gcwhT12SqizmacAF67TCa0n8OcpjVOpiiurb01Aa5lcl2WbakUFYmsp1U1l8=
Do you expect to run the X Window System = no
Change the default console to com0 = yes
Which speed should com0 use = 115200
Setup a user = syzkaller
Full name for user syzkaller = Syz Kaller
Password for user syzkaller = syzkaller
Public ssh key for user syzkaller = ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJeLpmSq+Dgrk01Ht+QtY0GDsY2gcwhT12SqizmacAF67TCa0n8OcpjVOpiiurb01Aa5lcl2WbakUFYmsp1U1l8=
Allow root ssh login = prohibit-password
What timezone = US/Pacific
Which disk = sd0
Use ( W) hole disk or ( E) dit the MBR = whole
Use ( A) uto layout, ( E) dit auto layout, or create ( C) ustom layout = auto
2019-05-15 19:08:03 +00:00
URL to autopartitioning template for disklabel = file:/disklabel.template
2018-09-13 22:34:34 +00:00
Set name( s) = +* -x* -game* done
2018-09-10 16:28:00 +00:00
Directory does not contain SHA256.sig. Continue without verification = yes
2019-05-09 17:40:00 +00:00
Location of sets = cd0
2018-09-10 16:28:00 +00:00
EOF
# Disklabel template.
cat >disklabel.template <<EOF
/ 5G-* 95%
swap 1G
EOF
# Hack install CD a bit.
echo 'set tty com0' > boot.conf
dd if = /dev/urandom of = random.seed bs = 4096 count = 1
cp " ${ ISO } " " ${ ISO_PATCHED } "
growisofs -M " ${ ISO_PATCHED } " -l -R -graft-points \
/${ VERSION } /${ ARCH } /site${ RELNO } .tgz= site${ RELNO } .tgz \
/auto_install.conf= auto_install.conf \
/disklabel.template= disklabel.template \
/etc/boot.conf= boot.conf \
/etc/random.seed= random.seed
# Initialize disk image.
rm -f disk.raw
qemu-img create -f raw disk.raw 10G
# Run the installer to create the disk image.
2018-09-13 22:34:34 +00:00
expect 2>& 1 <<EOF | tee install_log
2018-09-10 16:28:00 +00:00
set timeout 1800
spawn qemu-system-x86_64 -nographic -smp 2 \
-drive if = virtio,file= disk.raw,format= raw -cdrom " ${ ISO_PATCHED } " \
2018-09-26 07:41:21 +00:00
-net nic,model= virtio -net user -boot once = d -m 4000 -enable-kvm
2018-09-10 16:28:00 +00:00
expect timeout { exit 1 } "boot>"
send "\n"
# Need to wait for the kernel to boot.
expect timeout { exit 1 } "\(I\)nstall, \(U\)pgrade, \(A\)utoinstall or \(S\)hell\?"
send "s\n"
expect timeout { exit 1 } "# "
send "mount /dev/cd0c /mnt\n"
send "cp /mnt/auto_install.conf /mnt/disklabel.template /\n"
send "chmod a+r /disklabel.template\n"
send "umount /mnt\n"
send "exit\n"
expect timeout { exit 1 } "CONGRATULATIONS!"
proc login { } {
send "root\n"
expect "Password:"
send "root\n"
expect "# "
send "cat /etc/ssh/ssh_host_*_key.pub\nhalt -p\n"
expect eof
}
# There is some form of race condition with OpenBSD 6.2 MP
# and qemu, which can result in init(1) failing to run /bin/sh
# the first time around...
expect {
timeout { exit 1 }
"Enter pathname of shell or RETURN for sh:" {
send "\nexit\n"
expect "login:" {
login
}
}
"login:" {
login
}
}
EOF
2018-09-13 22:34:34 +00:00
grep 'pkg_add OK' install_log > /dev/null \
|| { echo Package installation failed. Inspect install_log. 2>& 1 ; exit 1; }
2018-09-10 16:28:00 +00:00
# Create Compute Engine disk image.
echo "Archiving disk.raw... (this may take a while)"
2018-09-19 23:28:02 +00:00
i = " openbsd- ${ ARCH } - ${ RELNO } -gce.tar.gz "
2018-09-10 16:28:00 +00:00
tar -Szcf " $i " disk.raw
cat <<EOF
Done.
To create GCE image run the following commands:
gsutil cp -a public-read " $i " gs://syzkaller/
2018-11-25 19:43:09 +00:00
gcloud compute images create ci-openbsd-root --source-uri gs://syzkaller/" $i "
2018-09-13 22:34:34 +00:00
2018-09-10 16:28:00 +00:00
EOF