Take the 2-minute tour ×

Locked pages are sometimes used to store crypto keys like for Luks or for encfs and other sensitive things.

But when doing hibernate (without swap drive encryption) they get stored to disk unencrypted anyway.

Do locked pages get erased from swap file when the system resumes from hibernate or I should cleanse the swap drive somehow manually?

share|improve this question

1 Answer 1

The only way is to use disk encryption on the swap partition. There are some reports of success doing this... Although this adds another layer of security (assuming you use a different password), you also have to enter and remember both passwords (unless you hardcode it into a startup script, eliminating it's purpose in the first place). Alternatively, you could encrypt the entire drive with a LVM. What the person did was use LVM ontop of a LUKS-encrypted partition (that way you only need a single password).

The reason you have to encrypt the swap partition While they get "erased", the data is still recoverable from the hard drive. Nothing gets erased, it just gets marked as "deleted" as in "next time you want to write some files here, go ahead, nothing is here".

AFAIK, because of these caveats, you're not supposed to use hibernation with LUKS unless you encrypt the entire drive. If you don't encrypt the whole drive, your only other option is to scrub the partition every time you shut the computer down (use a program that will overwrite the data with random bits a few times).

share|improve this answer
I expected at lest that it differentiates and does "now I loaded locked pages from swap. It shouldn't be in swap (unless hibernate), so I explicitly write random page on it's place, not just mark it as free space". So hibernated => unsecure. Resumed => more or less secure again. –  Vi. Aug 19 '11 at 11:30
That's a good idea actually. What did you do, make a script that executes when you resume from hibernate, and overwrites the swap space? –  Breakthrough Aug 19 '11 at 13:04
Yes, manual example: swapoff /dev/sda5 && dd if=/dev/frandom > /dev/sda5 && mkswap -U cf2e22a5-d55c-4eac-b3d1-dd388d129efc /dev/sda5 && swapon /dev/sda5. But 0000-Shred-locked-pages-from-swap-on-resume-from-s2ram.patch should be useful, should it? –  Vi. Aug 19 '11 at 13:16
I think calling swapoff pushes all of the pages back into RAM anyways... I haven't seen that patch before, but it might have some performance benefits over scripting it yourself (albeit at the expense of customization). –  Breakthrough Aug 19 '11 at 13:22
Pushes to RAM, but unlikely that shreds from disk. It's not about performance, it's about security when not using disk encryption. –  Vi. Aug 19 '11 at 13:25

Your Answer


