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

51 lines
1.3 KiB
Bash
Raw Normal View History

#!/bin/sh
2022-06-29 15:24:27 -04:00
## Copyright (C) 2022 - 2022 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
2022-06-29 15:19:56 -04:00
## See the file COPYING for copying conditions.
2022-06-29 16:02:05 -04:00
## Credits:
## First version by @friedy10.
## https://github.com/friedy10/dracut/blob/master/modules.d/40sdmem/wipe.sh
2022-06-29 15:17:40 -04:00
ram_wipe() {
info "$0: START: COLD BOOT ATTACK DEFENSE - RAM WIPE ON SHUTDOWN"
2022-06-29 15:50:20 -04:00
local OLD_DRACUT_QUIET
OLD_DRACUT_QUIET="$DRACUT_QUIET"
DRACUT_QUIET='no'
2022-06-29 15:17:40 -04:00
info "$0: Checking if there are still mounted encrypted disks..."
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
info "$0: Success, there are no more mounted encrypted disks, OK."
else
warn "\
$0: There are still mounted encrypted disks! RAM wipe failed!
debugging information:
dmsetup_expected_output: '$dmsetup_expected_output'
dmsetup_actual_output: '$dmsetup_actual_output'"
2022-06-29 15:50:20 -04:00
sleep 5
2022-06-29 15:17:40 -04:00
return 0
fi
info "$0: Starting RAM wipe..."
## TODO: sdmem settings. One pass only. Secure? Configurable?
sdmem -l -l -f
info "$0: RAM wipe completed, OK."
2022-06-29 15:50:20 -04:00
## Restore to previous value.
DRACUT_QUIET="$OLD_DRACUT_QUIET"
info "$0: END: COLD BOOT ATTACK DEFENSE - RAM WIPE ON SHUTDOWN"
sleep 3
2022-06-29 15:17:40 -04:00
}
ram_wipe