Warm Boot Attack Defense - RAM Wipe Design Documentation

From Kicksecure
< Dev
Jump to navigation Jump to search
Design Previous page: Dev/coding style Index page: Design Next page: Dev/nonfree Warm Boot Attack Defense - RAM Wipe Design Documentation
ram-wipe logo (development)

ram-wipe wipes the RAM during poweroff/reboot, utilizing the kernel's init_on_free mechanism.

Design

[edit]

ram-wipe

[edit]

Implemented by dracut module ram-wipeGitHub Logo (by ram-wipe).

  1. /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh runs need_shutdown.
  2. dracut-ng dm-shutdown.sh runs cryptsetup close to release the full disk encryption key during the shutdown process.archive.org iconarchive.today icon
  3. A dracut cleanup hook is declared in /usr/lib/dracut/modules.d/40ram-wipe/module-setup.shGitHub Logo (by ram-wipe): inst_hook cleanup 80 "$moddir/wipe-ram-needshutdown.sh". Priority is 80.
  4. During boot, that dracut cleanup hook /usr/lib/dracut/modules.d/40ram-wipe/wipe-ram-needshutdown.shGitHub Logo (by ram-wipe) is calling dracut API function need_shutdown which results in file /run/initramfs/.need_shutdown being created.
  5. As a result, at shutdown time when /lib/systemd/system/dracut-shutdown.service (by dracut) runs, /usr/lib/dracut/dracut-initramfs-restore (by dracut) will restore the initramfs and pivot into it.
  6. During shutdown, dracut will run its usual cleanup tasks such as unmounting the root (main) drive.
  7. The shutdown module (by dracut) will source and execute other shutdown hooks set up by other dracut modules.
  8. At the time of writing, there were no other dracut modules using the dracut shutdown hook known to the author of this website.
  9. wipe-ram.shGitHub Logo (by ram-wipe) is the dracut shutdown hook.
  10. An alternative description of the mechanism of dropping back to the initramfs during shutdown can be found under The initrd Interface of systemdarchive.org iconarchive.today icon.
  11. At a very late stage during the shutdown process, when all disks have already been unmounted by dracut, the wipe-ram.sh dracut shutdown hook is executed.
  12. The shutdown hook runs:
  • echo 3 > /proc/sys/vm/drop_caches
    • To ensure any remaining disk cache is erased by Linux's memory poisoning. [1]
  • dmsetup ls --target crypt: To check if all encrypted disks are unmounted.
    • Only if all encrypted disks are unmounted will it be possible for the kernel to wipe the Full Disk Encryption (FDE) key from the kernel.
    • Deletion of the FDE key is considered among the most crucial pieces of information to be wiped from RAM because if the FDE key can be recovered from RAM, then FDE can be compromised.
    • Informs the user if all encrypted disks are unmounted in console output. Otherwise, it shows a warning.

Quote Tails' Memory erasurearchive.org iconarchive.today icon:

First, most memory is erased at the end of a normal shutdown/reboot sequence. This is implemented by the Linux kernel's freed memory poisoning featurearchive.org iconarchive.today icon, more specifically init_on_free=1.

Additional kernel parameters shared with the Tails kernel hardening setuparchive.org iconarchive.today icon are implemented in the security-misc file /etc/default/grub.d/40_kernel_hardening.cfgGitHub Logo:

  • disabling merging of slabs with similar size (slab_nomerge)
  • passing FZ to slab_debug
  • enabling the kernel page allocator to randomize free lists (page_alloc.shuffle=1)
  • disabling vsyscalls (superseded by vDSO) (vsyscall=none)
  • causing kernel panic on unhandled exceptions (mce=0)

The kernel parameter wiperam=skip is available to disable RAM wiping at shutdown, which can be useful to speed up shutdown or in case any issues arise.

For potential limitations, the same limitations described under the "Limitations" chapter of Tails' Memory erasurearchive.org iconarchive.today icon apply.

ram-wipe-exit

[edit]

dracut module ram-wipe-exit:

  • The other dracut module ram-wipe is independent.
    • The ram-wipe module, in its main source code file wipe-ram.sh, relies on dropping the remaining disk caches, ensuring that encrypted disks have been unmounted and using the kernel's init_on_free mechanism.

Differences of ram-wipe versus Tails Memory Erasure

[edit]

Tails memory erasure:

ram-wipe:

Debugging

[edit]

(This file would be shipped out commented by default. Only useful for development / debugging.)

Maybe useful during development:

  • grep -r pre-udev --color /usr/lib/dracut

A panic button / panic shutdown / USB kill cord for your laptoparchive.org iconarchive.today icon feature is not integrated with this feature. It should be implemented separately as a standalone feature.

Status of initramfs-tools Support

[edit]

Support for initramfs-tools is not planned by the authors of ram-wipe. No progress on initramfs-tools support should be expected.

The problem with initramfs-tools support is that, in contrast to dracut, while initramfs-tools supports initrd (initial ramdisk), it does not support exitrd (exit ramdisk).

dracut supports both initrd (initial ramdisk at boot time) as well as exitrd (dropping back to the initial ramdisk at shutdown time). A feature request has been posted against the Debian initramfs-toolsarchive.org iconarchive.today icon package: Support restoring initrd on shutdown and pivoting into itarchive.org iconarchive.today icon.

Contributors wishing to add initramfs-tools support to ram-wipe should first add exitrd support to upstream, original initramfs-tools.

As a starting point, Tails has implemented initramfs-restorearchive.org iconarchive.today icon, which might be helpful to examine and use as inspiration when developing exitrd functionality for initramfs-tools. The Tails initramfs-tools exitrd implementation would have to be made generic - meaning not specific to Tails (i.e., no code references to other Tails-specific code) - and made acceptable for the initramfs-tools developers for inclusion into the upstream source code. However, using the Tails implementation as a starting point is not a strict requirement.

Once initramfs-tools gains exitrd support, it might then be straightforward to add initramfs-tools support to ram-wipe.

Development TODO

[edit]

ram-wipe Testing inside a VM

[edit]

1. Platform-specific notice.

  • Kicksecure: No special notice.
  • Qubes OS: ram-wipe is unavailable for Qubes OS. [2]

2. Install ram-wipe.

ram-wipe is not installed by default in VMs because it is usually not needed there, except for testing.

Install package(s) ram-wipe following these instructions

1 Platform specific notice.

2 Update the package lists and upgrade the system.

sudo apt update && sudo apt full-upgrade

3 Install the ram-wipe package(s).

Using apt command line --no-install-recommends option is in most cases optional.

sudo apt install --no-install-recommends ram-wipe

4 Platform specific notice.

  • Kicksecure: No special notice.
  • Kicksecure-Qubes: Shut down Template and restart App Qubes based on it as per Qubes Template Modification.

5 Done.

The procedure of installing package(s) ram-wipe is complete.

3. Reboot

sudo reboot

4. Set up a virtual serial console.

A virtual serial console helps to read all journal and kernel messages during early boot and shutdown.

Can be set up as per the serial console documentation. Only a read-only serial console was somewhat recently tested and should suffice. An interactive serial console might not be required.

5. Status.

Now a serial console should clearly show the output during boot and shutdown of ram-wipe.

ram-wipe Functionality Testing

[edit]

Done.

ram-wipe improvements

[edit]
  • sdmem is problematic: it is unmaintained upstream, and there has been at least one case where shutdown was blocked due to a "kernel locked up" error. Writing to RAM until it fills up and sdmem gets OOM-killed is not a robust design. We should either replace sdmem or drop it entirely. It seems feasible to drop it. Done. sdmem no longer required. Removed: https://github.com/Kicksecure/ram-wipe/pull/4archive.org iconarchive.today icon
  • Review how Tails handles memory erasure: Tails memory erasure designarchive.org iconarchive.today icon. They primarily rely on the kernel parameter init_on_free=1. Done. Testing was done by 3MDEB: https://beta.blog.3mdeb.com/2025/2025-08-12-ram-wipe-further-analysis/archive.org iconarchive.today icon
  • The second RAM wipe pass might be completely unnecessary. It can cause issues with graphics initialization during the second run due to buggy drivers. This makes reboot or shutdown slower and potentially glitchy. Done. (No longer necessary. Removed.)
  • All we might need to do is: Done.
    • Set init_on_free=1 (currently only set in security-misc, but it should be set in ram-wipe to make it standalone). Done.
    • Drop caches (already implemented). Done.
    • Properly unmount all encrypted disks (already done due to fixes in dracut in Debian Trixie). Done.
    • Drop back to initrd (already implemented). Done.
    • Re-test. Done.

Forum Discussion

[edit]

https://forums.whonix.org/t/is-ram-wipe-possible-inside-whonix-cold-boot-attack-defense/5596archive.org iconarchive.today icon

See Also

[edit]

Footnotes

[edit]

Design Previous page: Dev/coding style Index page: Design Next page: Dev/nonfree

Notification image

We believe security software like Kicksecure needs to remain Open Source and independent. Would you help sustain and grow the project? Learn more about our 13 year success story and maybe DONATE!