DF-0220 / window_experiment2.sh
#!/bin/sh # DF-0220 manufactured pre-reseed window — corrected experiment (root). # # usched takes a CPU MASK, not an index: ":1"=cpu0, ":2"=cpu1, ":4"=cpu2, # ":3"={cpu0,cpu1} (usage: "usched {scheduler[:cpumask]|:cpumask} prog"). # Earlier attempts with ":2"/":3" hit cpu1/cpu0+cpu1 and never touched the # forced state — verified because state[2].last_reseed stayed 0.000000 and # cipher_ctx stayed ALL-ZERO after the reads (no read = no rekey). # So state[2] is exercised with `usched :4` (cpumask 0x4 = cpu2). # # Sequence: # A. baseline keyed read pinned to cpu2 (csprng mode) -> random bytes # B. force state[2]; ONE 4096-byte /dev/urandom read on cpu2 -> ALL ZERO # C. re-force; 4x32-byte reads -> block1 = 00*32, # then deterministic zero-key chacha (sigma present after first rekey) # D. re-force; repeat C -> identical first block # E. re-force; same read in default mixed mode -> NON-zero (IBAA mask) # F. heal: pool0 is already >= 96; one more pinned read fires ratecheck # {0,0} -> successful reseed; verify reseed_cnt >= 1 and random output again set -e SYM=$(nm /boot/kernel/kernel | awk '/ csprng_pcpu$/ {print $1}') SYM=0x$SYM cd "$(dirname "$0")" echo "== csprng_pcpu = $SYM ==" echo; echo "== [A] baseline keyed read, cpu2 (mask 0x4), rand_mode=csprng (expect random) ==" sysctl kern.rand_mode=csprng >/dev/null usched :4 dd if=/dev/urandom bs=4096 count=1 2>/dev/null | hexdump -C | head -4 usched :4 dd if=/dev/urandom bs=4096 count=1 2>/dev/null | md5 echo; echo "== [B] FORCE state[2]; ONE 4096-byte /dev/urandom read on cpu2 (expect 4096 x 0x00) ==" ./csprng_force_zero $SYM force 2 | tail -1 usched :4 dd if=/dev/urandom bs=4096 count=1 2>/dev/null | tee /tmp/win4096.bin | hexdump -C | head -6 echo "zero_bytes=$(wc -c < /tmp/win4096.bin) allzero=$(cmp -s /tmp/win4096.bin /dev/zero && echo YES || echo NO)" echo; echo "== [C] re-force; 4 x 32-byte reads on cpu2 (expect 00*32 first, then deterministic) ==" ./csprng_force_zero $SYM force 2 | tail -1 usched :4 dd if=/dev/urandom bs=32 count=4 2>/dev/null | tee /tmp/win32.bin | hexdump -C echo; echo "== [D] re-force; repeat [C] exactly (expect identical output) ==" ./csprng_force_zero $SYM force 2 | tail -1 usched :4 dd if=/dev/urandom bs=32 count=4 2>/dev/null > /tmp/win32b.bin cmp /tmp/win32.bin /tmp/win32b.bin && echo "TRIALS IDENTICAL (deterministic)" || { echo "trials differ:"; hexdump -C /tmp/win32b.bin; } echo; echo "== [E] re-force; same read in DEFAULT mixed mode (expect NON-zero: IBAA mask) ==" sysctl kern.rand_mode=mixed >/dev/null ./csprng_force_zero $SYM force 2 | tail -1 usched :4 dd if=/dev/urandom bs=4096 count=1 2>/dev/null | hexdump -C | head -4 sysctl kern.rand_mode=csprng >/dev/null echo; echo "== [F] heal: pool0 already >= 96; one pinned read must reseed state[2] ==" ./csprng_force_zero $SYM check 2 usched :4 dd if=/dev/urandom bs=32 count=1 2>/dev/null | hexdump -C ./csprng_force_zero $SYM check 2 usched :4 dd if=/dev/urandom bs=4096 count=1 2>/dev/null | md5 echo "== restoring default rand_mode ==" sysctl kern.rand_mode=mixed |