Title: Do locked pages get shredded from disk after resuming from suspend-to-disk?
Tags: linux;security;hibernate;swap
Question: 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?


Here is another answer: 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).
Comment for this answer: 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?
Comment for this answer: 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).
Comment for 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.
Comment for this answer: 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?
Comment for this answer: Pushes to RAM, but unlikely that shreds from disk. It's not about performance, it's about security when not using disk encryption.

{'source': 'StackExchangeDataset', 'subset': 'superuser.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2011:00:08/18/11', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<linux><security><hibernate><swap>', 'Title': 'Do locked pages get shredded from disk after resuming from suspend-to-disk?', 'ViewCount': 111, 'id': 324969, 'user_AboutMe': None, 'user_AccountId': 98569.0, 'user_DisplayName': 'Vi.', 'user_Reputation': 16055.0, 'user_Views': 1019.0, 'user_id': 27264.0}}