security-misc/usr/lib/dracut/modules.d/40cold-boot-attack-defense/wipe-ram.sh

71 lines
2.3 KiB
Bash
Raw Normal View History

#!/bin/sh
2022-06-30 02:24:27 +07:00
## Copyright (C) 2022 - 2022 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
2022-06-30 02:19:56 +07:00
## See the file COPYING for copying conditions.
2022-06-30 03:02:05 +07:00
## Credits:
## First version by @friedy10.
## https://github.com/friedy10/dracut/blob/master/modules.d/40sdmem/wipe.sh
2022-06-30 02:17:40 +07:00
ram_wipe() {
2022-06-30 02:50:20 +07:00
local OLD_DRACUT_QUIET
OLD_DRACUT_QUIET="$DRACUT_QUIET"
2022-06-30 03:23:12 +07:00
## check_quiet should show info in console.
2022-06-30 02:50:20 +07:00
DRACUT_QUIET='no'
local kernel_wiperam_setting
## getarg returns the last parameter only.
## if /proc/cmdline contains 'wiperam=skip wiperam=force' the last one wins.
kernel_wiperam_setting=$(getarg wiperam)
if [ "$kernel_wiperam_setting" = "skip" ]; then
info "wipe-ram.sh: Skip, because wiperam=skip kernel parameter detected, OK."
DRACUT_QUIET="$OLD_DRACUT_QUIET"
return 0
fi
if [ "$kernel_wiperam_setting" = "force" ]; then
info "wipe-ram.sh: wiperam=force detected, OK."
else
if systemd-detect-virt &>/dev/null ; then
info "wipe-ram.sh: Skip, because VM detected and not using wiperam=force kernel parameter, OK."
DRACUT_QUIET="$OLD_DRACUT_QUIET"
return 0
fi
fi
2022-07-01 00:56:29 +07:00
info "wipe-ram.sh: Cold boot attack defense... Starting RAM wipe on shutdown..."
## TODO: sdmem settings. One pass only. Secure? Configurable?
sdmem -l -l -v
info "wipe-ram.sh: RAM wipe completed, OK."
## In theory might be better to check this beforehand, but the test is
## really fast. The user has no chance of reading the console output
## without introducing an artificial delay because the sdmem which runs
## after this, results in much more console output.
2022-06-30 03:24:52 +07:00
info "wipe-ram.sh: Checking if there are still mounted encrypted disks..."
2022-06-30 02:17:40 +07:00
local dmsetup_actual_output dmsetup_expected_output
dmsetup_actual_output="$(dmsetup ls --target crypt)"
dmsetup_expected_output="No devices found"
if [ "$dmsetup_actual_output" = "$dmsetup_expected_output" ]; then
2022-06-30 03:24:52 +07:00
info "wipe-ram.sh: Success, there are no more mounted encrypted disks, OK."
2022-06-30 02:17:40 +07:00
else
warn "\
2022-06-30 03:24:52 +07:00
wipe-ram.sh: There are still mounted encrypted disks! RAM wipe failed!
2022-06-30 02:17:40 +07:00
debugging information:
dmsetup_expected_output: '$dmsetup_expected_output'
dmsetup_actual_output: '$dmsetup_actual_output'"
fi
2022-06-30 02:50:20 +07:00
## Restore to previous value.
DRACUT_QUIET="$OLD_DRACUT_QUIET"
sleep 3
2022-06-30 02:17:40 +07:00
}
ram_wipe