Bug 714467 - Cannot use /dev/urandom for random keys, despite what man crypttab says
Summary: Cannot use /dev/urandom for random keys, despite what man crypttab says
Keywords:
Status: CLOSED INSUFFICIENT_DATA
Alias: None
Product: Fedora
Classification: Fedora
Component: cryptsetup-luks
Version: 15
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Milan Broz
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-06-19 13:09 UTC by Paul Johnson
Modified: 2013-03-01 04:10 UTC (History)
9 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2011-08-11 13:59:52 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Paul Johnson 2011-06-19 13:09:17 UTC
Description of problem:

When cryptsetup is given a key file it will read the file to completion.  Hence using /dev/urandom as a keyfile is not supported because the key generator will never terminate.  However crypttab(5) specifically says you can use /dev/urandom as a key file.  If you do this then booting fails.

This makes it hard to create a random encryption for /tmp and swap.

Version-Release number of selected component (if applicable):
1.2.0

How reproducible:
Always

Steps to Reproduce:
1.  Set up a /etc/crypttab file with the contents:
   crypt-tmp    <tmp-partition>   /dev/urandom   tmp
   crypt-swap   <swap-partition>  /dev/urandom   swap
where "<tmp-partition>" and "<swap-partition>" are block devices.

2.  Set up /fstab to include
   /dev/mapper/crypt-tmp        /tmp       ext2    defaults   0 0
   /dev/mapper/crypt-swap       swap       swap    defaults   0 0

3. Reboot
  
Actual results:
Boot fails when trying to mount /tmp with a timeout message.

Expected results:
Boot completes as normal.  /dev/mapper/crypt-tmp mounted and swap activated.

Additional info:

Comment 1 Paul Johnson 2011-06-19 13:31:05 UTC
After a bit more reading, I see that there is a distinction between the password and the key files.  The problem is that crypttab treats field 3 as a password file, when really a random key file is required for random encryption of swap and tmp.  There does not seem to be any way to pass a random key file via crypttab.

Comment 2 Milan Broz 2011-06-19 15:09:43 UTC
crypttab processing is quite tricky. If you use keyfile in plain-mode (non-LUKS),
it will use keyfile as key directly.

But using urandom for key should be possible for plain mode.
This one crypttab entry should work:
crypt-swap <swap-partition> /dev/urandom swap

It is in fact systemd cryptsetup wrapper problem, but I thought I sent fix for this... swap encrypted by key read from urandom was one of the tested scenario.

I'll check it once I have access to some F15 system again.

Comment 3 Milan Broz 2011-06-21 12:07:53 UTC
For me, crypttab is processed correctly - device mapper maps device, swap is created - using this line

swap-plain-keyf /dev/sdb1 /dev/urandom swap

But there seems problem when I add it to fstab with activation...

Comment 4 Milan Broz 2011-06-21 12:31:08 UTC
ok, this is another problem. I'll comment it on duplicate bug.

*** This bug has been marked as a duplicate of bug 711394 ***

Comment 5 Paul Johnson 2011-06-22 20:23:27 UTC
I do not believe that this bug is a duplicate of 711394, so I'm reopening it.  That bug is about swap partitions.  This one is primarily about /tmp.  When I set my /etc/crypttab to

   crypt-tmp    <tmp-partition>   /keyfile   tmp
   crypt-swap   <swap-partition>  /keyfile   swap

then everything works (apart of course from being insecure because the /keyfile is stored on the root partition).  The problem is that the file referred to in /etc/crypttab is passed as a password not a key, and cryptsetup reads password files to completion.

What I think is needed is some way to tell the crypttab processing to use /dev/urandom as a key file rather than a password file.  Or is there some other workaround?

Comment 6 Milan Broz 2011-06-22 20:53:50 UTC
Does it finish boot somehow? If so, please paste lsblk output and crypttab entry after system boots (after timeout).
crypttab is processed correctly on my system with urandom, and even swap was activated whan I removed that udev rule exception.

Comment 7 Milan Broz 2011-06-22 21:05:56 UTC
You can easily verify if it is clone of  bug 711394:

try edit /lib/udev/rules.d/60-persistent-storage.rules this way (remove dm-*):

# skip rules for inappropriate block devices
#KERNEL=="fd*|mtd*|nbd*|gnbd*|btibm*|dm-*|md*", GOTO="persistent_storage_end"
KERNEL=="fd*|mtd*|nbd*|gnbd*|btibm*|md*", GOTO="persistent_storage_end"

Does it help?

Comment 8 Paul Johnson 2011-06-22 21:14:52 UTC
The problem is with tmp, not swap.  I currently have my /etc/crypttab as

   crypt-tmp    /dev/mapper/vg_eiffel-lv_tmp   /tstkey   tmp
   crypt-swap   /dev/mapper/vg_eiffel-lv_swap  /dev/urandom   swap

This boots fine.  But if I set the tmp line to /dev/urandom then boot fails when the initialisation of /tmp times out.

I think this is a bug in /etc/functions in the init_crypto function.  There is a line:

   if [ -z "$makeswap" ] && cryptsetup isLuks "$src" 2>/dev/null ; then


The "else" part passes the "-d" parameter to cryptsetup (i.e. use key file).  I think that if this line was changed to

   if [ -z "$makeswap" ] && [ -z "$mke2fs" ] && cryptsetup isLuks "$src" 2>/dev/null ; then

then the tmp encryption would work in the same way as the swap.

Comment 9 Milan Broz 2011-06-22 22:01:50 UTC
uff. systemd should do the job, /etc/functions should not be used here (and -d /dev/urandom works).

But there seems to be another bug. Can you remove tmp mount from /etc/fstab, add urandom to crypttab, reboot and paste "lsblk -f" output?

It works for me - urandom is used, fs is there. Just it is not mounted for some reason. (but I have no clear F15 system, it is partially updated from rawhide)

Comment 10 Paul Johnson 2011-06-23 20:27:19 UTC
Here it is:

NAME                            FSTYPE LABEL MOUNTPOINT
sda                                          
├─sda1                                       /boot
└─sda2                                       
  ├─vg_eiffel-lv_root (dm-0)                 /
  ├─vg_eiffel-lv_swap (dm-1)                 
  │ └─crypt-swap (dm-7)                      [SWAP]
  ├─vg_eiffel-lg_var (dm-2)                  /var
  ├─vg_eiffel-lv_home (dm-3)                 /home
  ├─vg_eiffel-lv_tmp (dm-4)                  
  │ └─crypt-tmp (dm-6)                       /tmp
  └─vg_eiffel-lv_scratch (dm-5)              /scratch
sr0                                          
sr1                                          
sdb                                          
└─sdb1                     

So, if /etc/functions isn't being used, what does the crypttab processing?

Comment 11 Milan Broz 2011-06-29 10:56:44 UTC
crypttab is now parsed inside systemd and it calls libcryptsetup directly

Comment 12 Milan Broz 2011-06-29 11:00:27 UTC
so from the lsblk output you can see that crypt-tmp is mounted on /tmp, and crypt-swap is used as swap.

So this is correct. How the wrong config looks like?

Comment 13 Milan Broz 2011-08-11 13:59:52 UTC
No info provided here, closing.

I think that cryptsetup part works but there are still some issues in systemd regarding LUKS volumes anyway.


Note You need to log in before you can comment on or make changes to this bug.