github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/tools/create-openbsd-gce-ci.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2018 syzkaller project authors. All rights reserved. 4 # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 5 6 # Produces GCE image of syz-ci running on OpenBSD. 7 8 # Mostly derived from Go buildlet generator with blessing from bradfitz@. 9 10 set -eu -o pipefail 11 12 readonly MIRROR="${MIRROR:-cdn.openbsd.org}" 13 # The only supported setting. 14 readonly ARCH="amd64" 15 readonly SNAPSHOTS="https://${MIRROR}/pub/OpenBSD/snapshots/" 16 17 readonly VERSION=$(curl -s "${SNAPSHOTS}${ARCH}/" | perl -ne 'print "$1.$2" if m/>base(.)(.)\.tgz/') 18 echo "Found snapshots for version ${VERSION}" 19 20 readonly RELNO="${2:-${VERSION/./}}" 21 readonly ISO="install${RELNO}-${ARCH}.iso" 22 readonly ISO_PATCHED="install${RELNO}-${ARCH}-patched.iso" 23 24 if [[ ! -f "${ISO}" ]]; then 25 curl -o "${ISO}" "${SNAPSHOTS}${ARCH}/install${RELNO}.iso" 26 fi 27 28 # Create custom siteXX.tgz set. 29 rm -fr etc && mkdir -p etc 30 cat >install.site <<EOF 31 #!/bin/sh 32 PKGS="bash gcc%8 git gmake go llvm%19 nano wget" 33 PKG_PATH=${SNAPSHOTS}packages/${ARCH}/ pkg_add -I \$PKGS 34 PKG_PATH= pkg_info -I \$PKGS && echo pkg_add OK 35 ln -s /usr/local/bin/clang-format{-19,} 36 37 echo 'set tty com0' > boot.conf 38 echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config 39 echo 'pass in on egress proto tcp from any to any port 80 rdr-to 127.0.0.1 port 8080' >> /etc/pf.conf 40 echo 'permit keepenv nopass syzkaller as root' > /etc/doas.conf 41 42 mkdir /syzkaller 43 echo '/dev/sd1a /syzkaller ffs rw,noauto 1 0' >> /etc/fstab 44 45 mkdir -p /usr/lib/clang/19/lib/openbsd 46 ln -s /usr/lib/clang/19/lib/libclang_rt.ubsan_minimal.a /usr/lib/clang/19/lib/openbsd/libclang_rt.ubsan_standalone-x86_64.a 47 touch /usr/lib/clang/19/lib/openbsd/libclang_rt.ubsan_standalone_cxx-x86_64.a 48 EOF 49 50 cat >etc/installurl <<EOF 51 https://${MIRROR}/pub/OpenBSD 52 EOF 53 54 cat >etc/rc.local <<EOF 55 ( 56 nc metadata.google.internal 80 <<EOF2 | tail -n1 > /etc/myname.gce \ 57 && echo >> /etc/myname.gce \ 58 && mv /etc/myname{.gce,} \ 59 && hostname \$(cat /etc/myname) 60 GET /computeMetadata/v1/instance/hostname HTTP/1.0 61 Host: metadata.google.internal 62 Metadata-Flavor: Google 63 64 EOF2 65 set -eux 66 67 echo "starting syz-ci" 68 fsck -y /dev/sd1a 69 mount /syzkaller 70 su -c vmd -l syzkaller <<EOF2 71 cd /syzkaller 72 export HOME=/syzkaller 73 set -eux 74 ulimit -n 1024 -d 16000000 75 mkdir -p /syzkaller/go-cache 76 export GOCACHE=/syzkaller/go-cache 77 test -d /syzkaller/gopath/src/github.com/google/syzkaller || ( 78 mkdir -p /syzkaller/gopath/src/github.com/google && \ 79 git clone https://github.com/google/syzkaller.git && \ 80 mv syzkaller /syzkaller/gopath/src/github.com/google) 81 (cd /syzkaller/gopath/src/github.com/google/syzkaller && \ 82 gmake ci && \ 83 install bin/syz-ci /syzkaller) 84 ./syz-ci -config /syzkaller/gopath/src/github.com/google/syzkaller/dashboard/config/openbsd/config.ci 2>&1 | tee /syzkaller/syz-ci.log & 85 EOF2 86 ) 87 EOF 88 chmod +x install.site 89 90 cat >etc/rc.conf.local <<EOF 91 slaacd_flags=NO 92 smtpd_flags=NO 93 sndiod_flags=NO 94 EOF 95 96 cat >etc/sysctl.conf <<EOF 97 hw.smt=1 98 EOF 99 100 tar --owner=root --group=root -zcvf "site${RELNO}.tgz" install.site etc/* 101 102 # Autoinstall script. 103 cat >auto_install.conf <<EOF 104 System hostname = ci-openbsd 105 DNS domain name = syzkaller 106 Which network interface = vio0 107 IPv4 address for vio0 = dhcp 108 IPv6 address for vio0 = none 109 Password for root account = root 110 Public ssh key for root account = ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJeLpmSq+Dgrk01Ht+QtY0GDsY2gcwhT12SqizmacAF67TCa0n8OcpjVOpiiurb01Aa5lcl2WbakUFYmsp1U1l8= 111 Do you expect to run the X Window System = no 112 Change the default console to com0 = yes 113 Which speed should com0 use = 115200 114 Setup a user = syzkaller 115 Full name for user syzkaller = Syz Kaller 116 Password for user syzkaller = syzkaller 117 Public ssh key for user syzkaller = ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJeLpmSq+Dgrk01Ht+QtY0GDsY2gcwhT12SqizmacAF67TCa0n8OcpjVOpiiurb01Aa5lcl2WbakUFYmsp1U1l8= 118 Allow root ssh login = prohibit-password 119 What timezone = US/Pacific 120 Which disk = sd0 121 Use (W)hole disk or (E)dit the MBR = whole 122 Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout = auto 123 URL to autopartitioning template for disklabel = file:/disklabel.template 124 Set name(s) = +* -x* -game* done 125 Directory does not contain SHA256.sig. Continue without verification = yes 126 Location of sets = cd0 127 EOF 128 129 # Disklabel template. 130 cat >disklabel.template <<EOF 131 / 5G-* 95% 132 swap 1G 133 EOF 134 135 # Hack install CD a bit. 136 echo 'set tty com0' > boot.conf 137 dd if=/dev/urandom of=random.seed bs=4096 count=1 138 cp "${ISO}" "${ISO_PATCHED}" 139 growisofs -M "${ISO_PATCHED}" -l -R -graft-points \ 140 "/${VERSION}/${ARCH}/site${RELNO}.tgz=site${RELNO}.tgz" \ 141 /auto_install.conf=auto_install.conf \ 142 /disklabel.template=disklabel.template \ 143 /etc/boot.conf=boot.conf \ 144 /etc/random.seed=random.seed 145 146 # Initialize disk image. 147 rm -f disk.raw 148 qemu-img create -f raw disk.raw 10G 149 150 # Run the installer to create the disk image. 151 expect 2>&1 <<EOF | tee install_log 152 set timeout 1800 153 154 spawn qemu-system-x86_64 -nographic -smp 2 \ 155 -drive if=virtio,file=disk.raw,format=raw -cdrom "${ISO_PATCHED}" \ 156 -net nic,model=virtio -net user -boot once=d -m 4000 -enable-kvm 157 158 expect timeout { exit 1 } "boot>" 159 send "\n" 160 161 # Need to wait for the kernel to boot. 162 expect timeout { exit 1 } "\(I\)nstall, \(U\)pgrade, \(A\)utoinstall or \(S\)hell\?" 163 send "s\n" 164 165 expect timeout { exit 1 } "# " 166 send "mount /dev/cd0c /mnt\n" 167 send "cp /mnt/auto_install.conf /mnt/disklabel.template /\n" 168 send "chmod a+r /disklabel.template\n" 169 send "umount /mnt\n" 170 send "exit\n" 171 172 expect timeout { exit 1 } "CONGRATULATIONS!" 173 174 proc login {} { 175 send "root\n" 176 177 expect "Password:" 178 send "root\n" 179 180 expect "# " 181 send "cat /etc/ssh/ssh_host_*_key.pub\nhalt -p\n" 182 183 expect eof 184 } 185 186 # There is some form of race condition with OpenBSD 6.2 MP 187 # and qemu, which can result in init(1) failing to run /bin/sh 188 # the first time around... 189 expect { 190 timeout { exit 1 } 191 "Enter pathname of shell or RETURN for sh:" { 192 send "\nexit\n" 193 expect "login:" { 194 login 195 } 196 } 197 "login:" { 198 login 199 } 200 } 201 EOF 202 203 grep 'pkg_add OK' install_log > /dev/null \ 204 || { echo Package installation failed. Inspect install_log. 2>&1 ; exit 1; } 205 206 # Create Compute Engine disk image. 207 echo "Archiving disk.raw... (this may take a while)" 208 i="openbsd-${ARCH}-snapshot-gce.tar.gz" 209 tar -Szcf "$i" disk.raw 210 211 cat <<EOF 212 Done. 213 214 To create GCE image run the following commands: 215 216 gsutil cp -a public-read "$i" gs://syzkaller/ 217 gcloud compute images create ci-openbsd-root --source-uri gs://syzkaller/"$i" 218 219 EOF