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

59 lines
1.9 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() {
2022-06-29 15:50:20 -04:00
local OLD_DRACUT_QUIET
OLD_DRACUT_QUIET="$DRACUT_QUIET"
2022-06-29 16:23:12 -04:00
## check_quiet should show info in console.
2022-06-29 15:50:20 -04:00
DRACUT_QUIET='no'
2022-06-29 16:24:52 -04:00
info "wipe-ram.sh: START: COLD BOOT ATTACK DEFENSE - RAM WIPE ON SHUTDOWN"
info "wipe-ram.sh: Checking if there are still mounted encrypted disks..."
2022-06-29 15:17:40 -04: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-29 16:24:52 -04:00
info "wipe-ram.sh: Success, there are no more mounted encrypted disks, OK."
2022-06-29 15:17:40 -04:00
else
warn "\
2022-06-29 16:24:52 -04:00
wipe-ram.sh: There are still mounted encrypted disks! RAM wipe failed!
2022-06-29 15:17:40 -04:00
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
2022-06-29 16:24:52 -04:00
info "wipe-ram.sh: Starting RAM wipe..."
2022-06-29 15:17:40 -04:00
2022-06-29 16:23:12 -04:00
## - If DRACUT_QUIET previously was set to '', reset to '' for auto detection by check_quiet.
## - If DRACUT_QUIET previously was set to 'no', reset to 'no' for verbose output.
## - If DRACUT_QUIET previously was set to 'yes', reset to 'yes' to hide sdmem output,
## as well as the oom killing at the end.
DRACUT_QUIET="$OLD_DRACUT_QUIET"
2022-06-29 15:17:40 -04:00
## TODO: sdmem settings. One pass only. Secure? Configurable?
2022-06-29 16:30:31 -04:00
sdmem -l -l -v
2022-06-29 15:17:40 -04:00
2022-06-29 16:23:12 -04:00
## Reset to DRACUT_QUIET='no' so info messages can be shown.
DRACUT_QUIET='no'
2022-06-29 16:24:52 -04:00
info "wipe-ram.sh: RAM wipe completed, OK."
info "wipe-ram.sh: END: COLD BOOT ATTACK DEFENSE - RAM WIPE ON SHUTDOWN"
2022-06-29 15:50:20 -04:00
## Restore to previous value.
DRACUT_QUIET="$OLD_DRACUT_QUIET"
sleep 3
2022-06-29 15:17:40 -04:00
}
ram_wipe