⬢ DragonFlyBSD Kernel Audit
DF-5696 / guest_build.sh
← back to finding ↓ download raw
#!/bin/sh
# guest_build.sh — build the qsort pass-2 rig ON THE DragonFly GUEST.
# Uses the guest's OWN compiler and the guest's /usr/src copy of the audited
# file (identity-pinned: must equal the audit tree's sha256).
set -e
cd /tmp/qr

PIN=18620ff1b212f95ac1e6dedecbdef1df59ce7a7cae5a5f69e0268ca425e10eed

# 1. verbatim extraction of the audited file from the guest kernel source
cp /usr/src/sys/libkern/qsort.c qsort_v.c
echo "qsort_v.c sha256 (pin $PIN):"
sha256 -q qsort_v.c
[ "$(sha256 -q qsort_v.c)" = "$PIN" ] || { echo "SHA MISMATCH vs audit tree"; exit 1; }

# 2. kqsort_r translation unit (the real wrapper: sys/libkern/qsort_r.c
#    is exactly '#define I_AM_KQSORT_R + #include "libkern/qsort.c"')
printf '#define I_AM_KQSORT_R\n#include "qsort_v.c"\n' > qsort_rv.c

CFLAGS="-O1 -std=gnu99 -Wall -fno-strict-aliasing -I shim"

# 3. variants
cc $CFLAGS -Dkqsort=bq_kqsort_v     -c qsort_v.c       -o qsort_v.o
cc $CFLAGS -Dkqsort=bq_kqsort_f6    -c qsort_fixed6.c  -o qsort_fixed6.o
cc $CFLAGS -Dkqsort=bq_kqsort_f67   -c qsort_fixed67.c -o qsort_fixed67.o
cc $CFLAGS -Dkqsort_r=bq_kqsort_rv  -c qsort_rv.c      -o qsort_rv.o

# 4. rig
cc $CFLAGS qsort_rig.c qsort_v.o qsort_fixed6.o qsort_fixed67.o qsort_rv.o \
    -o qsort_rig

echo BUILD_RC=0