2022-06-29 09:35:08 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-01-06 13:53:28 -05:00
|
|
|
## Copyright (C) 2023 - 2023 ENCRYPTED SUPPORT LP <adrelanos@whonix.org>
|
|
|
|
## Copyright (C) 2023 - 2023 Friedrich Doku <friedrichdoku@gmail.com>
|
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-07-02 19:10:55 -04:00
|
|
|
drop_caches() {
|
|
|
|
sync
|
|
|
|
## https://gitlab.tails.boum.org/tails/tails/-/blob/master/config/chroot_local-includes/usr/local/lib/initramfs-pre-shutdown-hook
|
|
|
|
### Ensure any remaining disk cache is erased by Linux' memory poisoning
|
|
|
|
echo 3 > /proc/sys/vm/drop_caches
|
|
|
|
sync
|
|
|
|
}
|
|
|
|
|
2022-07-02 16:02:28 -04:00
|
|
|
ram_wipe() {
|
2022-06-30 14:47:45 -04:00
|
|
|
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
|
2023-01-07 12:46:21 -05:00
|
|
|
info "wipe-ram.sh: Skip, because wiperam=skip kernel parameter detected, OK."
|
2022-06-30 13:50:18 -04:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2022-06-30 14:47:45 -04:00
|
|
|
if [ "$kernel_wiperam_setting" = "force" ]; then
|
2023-01-07 12:46:21 -05:00
|
|
|
info "wipe-ram.sh: wiperam=force detected, OK."
|
2022-06-30 14:47:45 -04:00
|
|
|
else
|
|
|
|
if systemd-detect-virt &>/dev/null ; then
|
2023-01-07 12:46:21 -05:00
|
|
|
info "wipe-ram.sh: Skip, because VM detected and not using wiperam=force kernel parameter, OK."
|
2022-06-30 14:47:45 -04:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2023-01-07 15:59:52 -05:00
|
|
|
kernel_wiperamexit_setting=$(getarg wiperamexit)
|
|
|
|
if [ "$kernel_wiperamexit_setting" = "yes" ]; then
|
|
|
|
warn "wipe-ram.sh: Skip, because wiperamexit=yes to avoid RAM wipe reboot loop."
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2023-01-07 12:46:21 -05:00
|
|
|
info "wipe-ram.sh: Cold boot attack defense... Starting RAM wipe on shutdown..."
|
2022-06-30 13:56:29 -04:00
|
|
|
|
2022-07-02 19:10:55 -04:00
|
|
|
drop_caches
|
2022-07-02 19:07:06 -04:00
|
|
|
|
2022-06-30 13:56:29 -04:00
|
|
|
## TODO: sdmem settings. One pass only. Secure? Configurable?
|
2022-07-02 17:21:33 -04:00
|
|
|
## TODO: > /dev/kmsg 2> /dev/kmsg
|
2022-06-30 13:56:29 -04:00
|
|
|
sdmem -l -l -v
|
|
|
|
|
2022-07-02 19:10:55 -04:00
|
|
|
drop_caches
|
|
|
|
|
2023-01-07 12:46:21 -05:00
|
|
|
info "wipe-ram.sh: RAM wipe completed, OK."
|
2022-06-30 13:56:29 -04:00
|
|
|
|
|
|
|
## 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.
|
2023-01-07 12:46:21 -05:00
|
|
|
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
|
2023-01-07 12:46:21 -05:00
|
|
|
info "wipe-ram.sh: Success, there are no more mounted encrypted disks, OK."
|
2022-07-28 09:56:24 -04:00
|
|
|
## This should probably be removed in production?
|
2022-07-28 09:55:12 -04:00
|
|
|
sleep 3
|
2022-06-29 15:17:40 -04:00
|
|
|
else
|
2023-01-07 12:46:21 -05:00
|
|
|
warn "\
|
|
|
|
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'
|
2023-01-07 11:31:02 -05:00
|
|
|
dmsetup_actual_output: '$dmsetup_actual_output'"
|
2022-07-28 09:56:24 -04:00
|
|
|
## How else could the user be informed that something is wrong?
|
2022-07-28 09:55:12 -04:00
|
|
|
sleep 5
|
2022-06-29 15:17:40 -04:00
|
|
|
fi
|
|
|
|
|
2023-01-07 15:59:52 -05:00
|
|
|
info "wipe-ram.sh: Now running kexec --exec..."
|
2023-01-07 15:22:58 -05:00
|
|
|
if kexec --exec ; then
|
|
|
|
info "wipe-ram.sh: kexec --exec succeeded."
|
2023-01-07 15:22:25 -05:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2023-01-07 15:22:58 -05:00
|
|
|
warn "wipe-ram.sh: kexec --exec failed!"
|
2023-01-07 15:22:25 -05:00
|
|
|
sleep 5
|
2022-06-29 15:17:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ram_wipe
|