DragonFlyBSD Kernel Audit
DF-2846 / check.sh
← back to finding ↓ download raw
#!/bin/sh
# DF-2846 trigger: CPU-topology sysctl strings are rendered at
# SI_BOOT2_CPU_TOPOLOGY while ncpus == 1 (APs not yet started), so every
# eagerly-rendered string only ever contains cpu 0 (or nothing).
#
# Expected on a healthy kernel: members / physical_siblings / core_siblings
# list all online cpus (here 0-5). Bug: they show "cpus(0)" or "cpus()".
# The lazily-rendered hw.cpu_topology.tree is rendered at read time
# (ncpus already final) and shows the full, correct mask.
echo "== uname =="
uname -a
echo "== hw.ncpu =="
sysctl hw.ncpu
echo "== eagerly-rendered strings (built at SI_BOOT2_CPU_TOPOLOGY, ncpus==1) =="
sysctl hw.cpu_topology.members
i=0
n=$(sysctl -n hw.ncpu)
while [ $i -lt $n ]; do
    sysctl hw.cpu_topology.cpu$i.physical_siblings \
           hw.cpu_topology.cpu$i.core_siblings 2>/dev/null
    i=$((i+1))
done
echo "== lazily-rendered tree (rendered at read time, ncpus final) =="
sysctl -n hw.cpu_topology.tree
echo "== verdict =="
m=$(sysctl -n hw.cpu_topology.members)
if [ "$m" = "cpus(0-5)" ]; then
    echo "PASS: members lists all cpus"
else
    echo "BUG REPRODUCED: hw.cpu_topology.members='$m' but hw.ncpu=$n"
fi