⬢ DragonFlyBSD Kernel Audit
DF-2655 / run_stock_ab.sh
← back to finding ↓ download raw
#!/bin/sh
#
# run_stock_ab.sh - DF-2655 stock-kernel A/B/C demonstration.
#
# A: mount PRISTINE image   -> zfile reads back ORIGINAL content (md5 match)
# B: mount PATCHED (zlib-invalid payload, checks valid) -> read(2) SUCCEEDS
#    but the 64KB block at lbase 0 comes back ALL ZEROS (fabricated by the
#    kernel), block 2 intact.  dmesg shows the "Fatal error during
#    decompression" kprintf.  This is the silent-data-substitution proof.
# C: repeat B two more times on fresh vn devices (determinism).
#
# usage: ./run_stock_ab.sh [workdir]   (default /root/df2655)
D=${1:-/root/df2655}
cd "$D"

report() {
	img="$1"; tag="$2"; out="$3"
	vn=$(vnconfig -c vn "$img") || { echo "vnconfig failed"; exit 1; }
	echo "(unit $vn)"
	if ! mount_hammer2 -o ro "/dev/$vn@LOCAL" /mnt 2>/dev/null; then
		echo "($tag) ro mount failed, trying rw"
		mount_hammer2 "/dev/$vn@LOCAL" /mnt || exit 1
	fi
	{
	  echo "=== $tag: $img mounted (uname: $(uname -v))"
	  echo "--- read zfile (dd full 128KB):"
	  dd if=/mnt/zdir/zfile of="$out" bs=64k count=2 2>&1
	  echo "dd exit: $?"
	  echo "--- md5 read-back vs original:"
	  md5 "$out" "$D/zfile.orig"
	  echo "--- first 32 bytes read back:"
	  od -An -tx1 -N32 "$out"
	  echo "--- first differing byte (orig vs readback):"
	  cmp "$D/zfile.orig" "$out" 2>&1 || true
	  echo "--- zero-run length at start (bytes):"
	  dd if="$out" bs=1 count=65536 2>/dev/null | tr -d '\0' | wc -c
	  echo "--- dmesg tail:"
	  dmesg | tail -8
	} | tee "run.$tag.log"
	umount /mnt || umount -f /mnt
	vnconfig -d "$vn" 2>/dev/null || true
}

echo "===== A: pristine baseline (vn5)"
report "$D/h2z.pristine.img" a "$D/zfile.A.readout"

echo ""
echo "===== B: zlib-patched (vn6)"
report "$D/h2z.img" b "$D/zfile.B.readout"

echo ""
echo "===== C: determinism repeats (vn7, vn8)"
report "$D/h2z.img" b2 "$D/zfile.B2.readout"
report "$D/h2z.img" b3 "$D/zfile.B3.readout"

echo ""
echo "===== summary"
md5 "$D/zfile.orig" "$D"/zfile.*.readout
echo "run_stock_ab done"