LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-25-2013, 06:43 AM   #1
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 268

Rep: Reputation: 25
Encrypting swap - thoughts?


Hello.
I was just curious. Suppose you want to install linux with disk encryption (encrypted root file system as well as encrypted swap), and pre-boot authentication (unencrypted /boot) using the old MBR partitioning. The device names could be improved to use UUID's instead, but that's not the point right now. I got two scenarios here:


Scenario A: The system is set up in a way where the main HDD has two partitions on it. The first one is an unencrypted /boot partition, and the second one is a LUKS-encrypted volume. The LUKS volume uses LVM ontop to further divide the *virtual* disk space into two sub-sections. One of them is the root file system, and the other is a SWAP volume. This means the SWAP resides inside the main LUKS-encrypted partion, next to the root file system.

fstab:
Quote:
#<file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/vg0-lvroot / ext4 defaults 0 1
/dev/mapper/vg0-lvswap none swap sw 0 0
crypttab:
Quote:
# <name> <device> <password> <options>
cryptroot /dev/sda2 none luks


Scenario B: The system is set up in a way where the main HDD has three partitions on it. The first one is an unencrypted /boot partition, the second one is a LUKS-encrypted volume containing the root file system (LVM is optional here), and the third one is used for encrypted swap. This means the swap resides outside LUKS volume, and uses its own encryption scheme.

fstab:
Quote:
#<file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/cryptroot / ext4 defaults 0 1
/dev/mapper/cryptswap none swap sw 0 0
crypttab:
Quote:
# <name> <device> <password> <options>
cryptroot /dev/sda2 none luks
cryptswap /dev/sda3 /dev/urandom swap,cipher=aes-cbc-essiv:sha256,size=256



What are the advantages and drawbacks of each scenario? Suppose you don't plan to use suspend/hibernation.
The only thing I can think of is that if you are forced to decrypt the drive, with scenario B an adversary won't be able to figure out the contents of the swap because the keys are destroyed with each reboot. The swap on acenario A is preserved.

Thoughts?
 
Old 06-25-2013, 10:31 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
I try to avoid the complexity of LVM unless I really need it, and just subdividing a LUKS volume to split off some swap space wouldn't, for me, come anywhere near satisfying that "need" threshold.

I use your 2nd scenario (swap partition randomly encrypted at boot) in combination with /tmp on a tmpfs to ensure that my temporary files cannot be recovered by forensic analysis.
 
Old 06-27-2013, 03:26 AM   #3
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 268

Original Poster
Rep: Reputation: 25
Yeah, I'm setting up btrfs on the root partition, so no need for LVM. Maybe a quick comment for the scenario B, which I decided to use. I encountered a small problem while tinkering with the mount options in crypttab. Hopefully somebody finds this useful. Consider these two entries in crypttab:

(1) cryptswap /dev/disk/by-id/ata-........-part3 /dev/random swap,cipher=aes-xts-plain64:sha512,hash=sha512,size=512
(2) cryptswap /dev/disk/by-id/ata-........-part3 /dev/random swap,cipher=aes-xts-plain64:sha512,size=512

In crypttab do not use an entry like (1)! This will prompt the user to enter a password for the swap partition at boot. The dm-crypt will then fail to set up the swap partition. Clearing the "hash=sha512" option solves this - the line should look like (2).

Regards!
 
Old 06-27-2013, 07:58 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625
Maybe put on a swap file instead of a partition?
Do you really need swap?
 
Old 06-28-2013, 03:38 AM   #5
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 268

Original Poster
Rep: Reputation: 25
Afaik, swap files are a bit slower than swap partitions. Additionally I'm using btrfs, and a lot of articles suggest that using a swapfile on btrfs will corrupt the filesystem, so it's a no-no. I am unsure whether I need swap, but I read somewhere it is generally a good idea to include a swap partition, because linux uses it for caching idle tasks, etc. I have a laptop with 8GB of ram and a stationary PC with 16 GB of ram.

Although this topic is not about whether or not I need swap. It is about how to encrypt and secure swap.

Regards!


EDIT: I just found out that distros like Xubuntu are having some problems with swap that is configured under scenario B. Sometimes the OS won't boot, but most of the time you get an annoying message on the splash screen about the swap not being ready. I even got a kernel panic once.

Related bug report:
https://bugs.launchpad.net/ubuntu/+s...ux/+bug/798086

Last edited by displace; 07-01-2013 at 02:31 PM.
 
Old 07-01-2013, 05:25 PM   #6
NyteOwl
Member
 
Registered: Aug 2008
Location: Nova Scotia, Canada
Distribution: Slackware, OpenBSD, others periodically
Posts: 512

Rep: Reputation: 139Reputation: 139
I also avoid the extra layer of LVM unless it is absolutely needed. I use the second scenario, indeed, being a bit "paranoid", I usually recommend people encrypt their swap file even if they don't use encryption otherwise as it can potentially hold sensitive data that isn't otherwise stored on the system.

Scenario two should theoretically be faster though for most average users just looking for a little security they're not likely to notice the difference. There should however be no problem with an encrypted swap under scenario two.
 
Old 07-01-2013, 06:41 PM   #7
Z038
Member
 
Registered: Jan 2006
Location: Dallas
Distribution: Slackware
Posts: 910

Rep: Reputation: 174Reputation: 174
LVM does not add complexity. It simplifies disk management.

I suggest scenario A. That is what I have done for years, and I've never had a problem. In fact, I have two different LUKs-encrypted volume groups and I put a logical swap partition on each with priority set in fstab to favor the swap file that is on the volume group that is least active. Also, /home in a different logical volume from /.

I'm curious about this statement:

Quote:
Originally Posted by displace View Post
Yeah, I'm setting up btrfs on the root partition, so no need for LVM.
I have no experience with btrfs. Does it provide it's own logical volume management scheme similar to LVM, or is there something about btrfs that obviates the advantages of using LVM?
 
Old 07-01-2013, 07:41 PM   #8
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625
I am beginning to wonder if any common encryption is really secure at all. A search the other day for ways to break encryption left me kind of sad. One product claimed to break maybe 23 of the 25 common ones in use by brute force if needed using gpu and cpu and sse. While the key it's self is secure, the brute force attempt doesn't suffer that.
If you can't break it locally they offer supercomputers for such a task at some penny per millions of attempts. Might end up costing you $12.54 to break into NSA.
 
Old 07-02-2013, 01:39 PM   #9
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 268

Original Poster
Rep: Reputation: 25
Quote:
Originally Posted by Z038 View Post
I have no experience with btrfs. Does it provide it's own logical volume management scheme similar to LVM, or is there something about btrfs that obviates the advantages of using LVM?
Subvolumes.


Quote:
Originally Posted by jefro View Post
I am beginning to wonder if any common encryption is really secure at all. A search the other day for ways to break encryption left me kind of sad. One product claimed to break maybe 23 of the 25 common ones in use by brute force if needed using gpu and cpu and sse. While the key it's self is secure, the brute force attempt doesn't suffer that.
If you can't break it locally they offer supercomputers for such a task at some penny per millions of attempts. Might end up costing you $12.54 to break into NSA.
Every encryption can be broken. Eventually.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Encrypting ryankirk Linux - Newbie 2 11-30-2012 07:13 PM
Gparted says swap has 5 Gb, grep SwapTotal /proc/meminfo says swap has 800 Mb rickrandall Red Hat 3 02-24-2010 12:09 PM
encrypting tariq07 Linux - Security 1 03-13-2007 01:35 AM
LXer: Encrypting /home and swap over RAID with dm-crypt LXer Syndicated Linux News 0 05-24-2006 04:54 AM
encrypting im1crazyassmofo Linux - General 1 04-20-2003 09:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration