brintos

brintos / linux-shallow public Read only

0
0
Text · 1.3 KiB · f43aa4b Raw
79 lines · bash
1#!/usr/bin/env bash2 3set -euo pipefail4 5TIMEOUT=106 7function do_one8{9    local mitigation="$1"10    local orig11    local start12    local now13 14    orig=$(cat "$mitigation")15 16    start=$(date +%s)17    now=$start18 19    while [[ $((now-start)) -lt "$TIMEOUT" ]]20    do21        echo 0 > "$mitigation"22        echo 1 > "$mitigation"23 24        now=$(date +%s)25    done26 27    echo "$orig" > "$mitigation"28}29 30rc=031cd /sys/kernel/debug/powerpc || rc=132if [[ "$rc" -ne 0 ]]; then33    echo "Error: couldn't cd to /sys/kernel/debug/powerpc" >&234    exit 135fi36 37tainted=$(cat /proc/sys/kernel/tainted)38if [[ "$tainted" -ne 0 ]]; then39    echo "Error: kernel already tainted!" >&240    exit 141fi42 43mitigations="barrier_nospec stf_barrier count_cache_flush rfi_flush entry_flush uaccess_flush"44 45for m in $mitigations46do47    if [[ -f /sys/kernel/debug/powerpc/$m ]]48    then49        do_one "$m" &50    fi51done52 53echo "Spawned threads enabling/disabling mitigations ..."54 55if stress-ng > /dev/null 2>&1; then56    stress="stress-ng"57elif stress > /dev/null 2>&1; then58    stress="stress"59else60    stress=""61fi62 63if [[ -n "$stress" ]]; then64    "$stress" -m "$(nproc)" -t "$TIMEOUT" &65    echo "Spawned VM stressors ..."66fi67 68echo "Waiting for timeout ..."69wait70 71tainted=$(cat /proc/sys/kernel/tainted)72if [[ "$tainted" -ne 0 ]]; then73    echo "Error: kernel became tainted!" >&274    exit 175fi76 77echo "OK"78exit 079