Skip to content

A hardened Linux desktop, rebuilt from scratch, with your Windows apps built in. Free and open source.

2.1 KB
Raw Blame
#!/bin/sh
# Processor thread and flaw protection choices, applied from the next
# start-up by /etc/default/grub.d/40_wildos.cfg (wildos-base). Runs as root
# through pkexec (org.wildos.settings.cpu-threads).
#
#   on | off        "Use every processor thread" in Settings > System > Power
#                   and battery, also offered by Windows mode setup. Until it
#                   is touched, the kernel runs every thread except on
#                   processors it lists as unsafe for sharing a core.
#   protect on|off  "Extra processor protection" in Settings > Privacy and
#                   security: Kicksecure's full set of processor flaw
#                   protections, forced on whether or not the processor
#                   needs them, with the second thread of every core off.
#
# Strict and Maximum protection always get the full set; 40_wildos.cfg
# reads the level itself.

set -eu

THREADS=/etc/wildos/cpu-threads
PROTECT=/etc/wildos/cpu-protection
LEVEL_FILE=/etc/wildos/protection-level

strict_level() {
    case "$(cat "$LEVEL_FILE" 2>/dev/null || true)" in
    strict | maximum) return 0 ;;
    esac
    return 1
}

case "${1:-}:${2:-}" in
on:)
    # Settings greys the switch out at Strict, Maximum and with extra
    # protection on; this refuses in case anything else asks.
    if strict_level || [ "$(cat "$PROTECT" 2>/dev/null || true)" = extra ]; then
        echo "Extra processor protection keeps hyper-threading off." >&2
        exit 3
    fi
    mkdir -p /etc/wildos
    echo on > "$THREADS"
    ;;
off:)
    mkdir -p /etc/wildos
    echo off > "$THREADS"
    ;;
protect:on)
    mkdir -p /etc/wildos
    echo extra > "$PROTECT"
    ;;
protect:off)
    if strict_level; then
        echo "Strict and Maximum protection keep extra processor protection on." >&2
        exit 3
    fi
    rm -f "$PROTECT"
    ;;
*)
    echo "usage: $0 on|off|protect on|protect off" >&2
    exit 2
    ;;
esac

# The old drop-in from before 40_wildos.cfg read the choice itself.
rm -f /etc/default/grub.d/41_wildos_cpu_threads.cfg

if command -v update-grub >/dev/null 2>&1; then
    update-grub >/dev/null 2>&1
else
    grub-mkconfig -o /boot/grub/grub.cfg >/dev/null 2>&1
fi