sexta-feira, 25 de agosto de 2023

Encrypted swap-file

Everyone swaps laptops eventually and forgets one detail: disk encryption doesn't cover swap. You encrypt the whole root partition, sleep fine, then forget the kernel dumps memory pages into an unencrypted file the moment RAM gets tight. If someone grabs your disk after a hibernate, or even after a heavy session that forced swap, that data is sitting there, plain.

Here's how I closed that gap on my own [Gentoo] setup.

Execute:


~ # dd bs=4M count=2560 if=/dev/zero of=swapfile conv=fsync oflag=direct status=progress && chattr +C swapfile && \ lsattr swapfile && chmod 0600 swapfile && ls -l swapfile && cryptsetup luksFormat swapfile ~ # cryptsetup luksOpen swapfile swap_crypt && mkswap /dev/mapper/swap_crypt && swapon /dev/mapper/swap_crypt

How this command works:

on systems with strong privacy requirements, running swap on disk without encryption is a real risk (RAM data exposed on hibernation or physical extraction).

  1. dd bs=4M count=2560 ... → creates a 10GB file (block size × count = total size, adjust count for whatever size you need).
  2. chattr +C swapfile → disables Copy-on-Write. this only does anything on Btrfs — on ext4 the command runs and silently does nothing, so check your filesystem first instead of trusting the flag blindly.
  3. chmod 0600 → strict permissions (rw for the owner only).
  4. cryptsetup luksFormat → creates an encrypted LUKS container.
  5. cryptsetup luksOpen + mkswap + swapon → opens it, formats it as swap, and activates it.

Advantages: protects in-memory data against cold boot attacks and disk forensics — anyone pulling the drive lands on ciphertext instead of raw pages.

Risks: performance overhead from encryption (more noticeable on spinning disks than SSDs) and extra complexity at boot.

To make it persistent: configure it in /etc/crypttab and /etc/fstab (Gentoo/OpenRC) or set up a systemd unit. either way, the LUKS container has to be open before swapon runs — that ordering is the part that actually breaks if you get it wrong.

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.

pass + GPG + git-remote-gcrypt: Encrypted Password Store Sync with GitHub

The idea was simple: keep my passwords in the terminal with pass , version the encrypted files with Git, and maintain an encrypted backu...