| 1 | |
| 2 |
|
| 3 | set -euo pipefail
|
| 4 |
|
| 5 | TIMEOUT=10
|
| 6 |
|
| 7 | function do_one
|
| 8 | {
|
| 9 | local mitigation="$1"
|
| 10 | local orig
|
| 11 | local start
|
| 12 | local now
|
| 13 |
|
| 14 | orig=$(cat "$mitigation")
|
| 15 |
|
| 16 | start=$(date +%s)
|
| 17 | now=$start
|
| 18 |
|
| 19 | while [[ $((now-start)) -lt "$TIMEOUT" ]]
|
| 20 | do
|
| 21 | echo 0 > "$mitigation"
|
| 22 | echo 1 > "$mitigation"
|
| 23 |
|
| 24 | now=$(date +%s)
|
| 25 | done
|
| 26 |
|
| 27 | echo "$orig" > "$mitigation"
|
| 28 | }
|
| 29 |
|
| 30 | rc=0
|
| 31 | cd /sys/kernel/debug/powerpc || rc=1
|
| 32 | if [[ "$rc" -ne 0 ]]; then
|
| 33 | echo "Error: couldn't cd to /sys/kernel/debug/powerpc" >&2
|
| 34 | exit 1
|
| 35 | fi
|
| 36 |
|
| 37 | tainted=$(cat /proc/sys/kernel/tainted)
|
| 38 | if [[ "$tainted" -ne 0 ]]; then
|
| 39 | echo "Warning: kernel already tainted! ($tainted)" >&2
|
| 40 | fi
|
| 41 |
|
| 42 | mitigations="barrier_nospec stf_barrier count_cache_flush rfi_flush entry_flush uaccess_flush"
|
| 43 |
|
| 44 | for m in $mitigations
|
| 45 | do
|
| 46 | if [[ -f /sys/kernel/debug/powerpc/$m ]]
|
| 47 | then
|
| 48 | do_one "$m" &
|
| 49 | fi
|
| 50 | done
|
| 51 |
|
| 52 | echo "Spawned threads enabling/disabling mitigations ..."
|
| 53 |
|
| 54 | if stress-ng > /dev/null 2>&1; then
|
| 55 | stress="stress-ng"
|
| 56 | elif stress > /dev/null 2>&1; then
|
| 57 | stress="stress"
|
| 58 | else
|
| 59 | stress=""
|
| 60 | fi
|
| 61 |
|
| 62 | if [[ -n "$stress" ]]; then
|
| 63 | "$stress" -m "$(nproc)" -t "$TIMEOUT" &
|
| 64 | echo "Spawned VM stressors ..."
|
| 65 | fi
|
| 66 |
|
| 67 | echo "Waiting for timeout ..."
|
| 68 | wait
|
| 69 |
|
| 70 | orig_tainted=$tainted
|
| 71 | tainted=$(cat /proc/sys/kernel/tainted)
|
| 72 | if [[ "$tainted" != "$orig_tainted" ]]; then
|
| 73 | echo "Error: kernel newly tainted, before ($orig_tainted) after ($tainted)" >&2
|
| 74 | exit 1
|
| 75 | fi
|
| 76 |
|
| 77 | echo "OK"
|
| 78 | exit 0
|