⬢ DragonFlyBSD Kernel Audit
DF-2303 / prep_guest.sh
← back to finding ↓ download raw
#!/bin/sh
# prep_guest.sh -- one-time guest preparation for the fwohci.c rig
# (DF-2300..DF-2303).  Files are pushed to /root/fwo from the host.
set -e
cd /root/fwo

# 1. install the harness into the kernel source tree (guest /usr/src is
#    the build scratch; the host-side sys/ tree is never modified).
#    fwohci_harness.c #includes the UNMODIFIED fwohci.c into its TU, so
#    the stock fwohci.c + fwohci_pci.c units must be dropped from the
#    FWO build to avoid duplicate symbols (conf/files: fwohci.c is
#    `optional firewire`, i.e. present in every stock firewire kernel).
install -m 644 fwohci_harness.c fwohci_harness.h /usr/src/sys/bus/firewire/
sed -i 's|^bus/firewire/fwohci.c[[:space:]].*|bus/firewire/fwohci.c\toptional fwohci_stock_disabled|' /usr/src/sys/conf/files
sed -i 's|^bus/firewire/fwohci_pci.c[[:space:]].*|bus/firewire/fwohci_pci.c\toptional fwohci_stock_disabled|' /usr/src/sys/conf/files
grep -q fwohci_harness.c /usr/src/sys/conf/files || \
    printf 'bus/firewire/fwohci_harness.c\toptional fwohci_harness\n' \
        >> /usr/src/sys/conf/files
grep -n 'firewire' /usr/src/sys/conf/files
if [ ! -f /usr/src/sys/config/FWO ]; then
    cp /usr/src/sys/config/X86_64_GENERIC /usr/src/sys/config/FWO
    printf '\n# fwohci.c audit rig (DF-2300..DF-2303)\ndevice\t\tfwohci_harness\n' \
        >> /usr/src/sys/config/FWO
fi

# 2. panic behavior: no ddb
grep -q debugger_on_panic /etc/sysctl.conf || \
    echo 'debug.debugger_on_panic=0' >> /etc/sysctl.conf
sysctl debug.debugger_on_panic=0

# 3. operator-group test user
pw useradd -n opuser -m -G operator -w none 2>/dev/null || true
id opuser

# 4. build the userland trigger
install -m 644 fwohci_harness.h /root/fwo/
cc -O -Wall -o fwpoc fwpoc.c
cp fwpoc /home/opuser/fwpoc 2>/dev/null || true
chmod 755 /home/opuser/fwpoc 2>/dev/null || true
ls -l fwpoc
echo PREP_OK