Initial add of FAQ
[platform/upstream/cryptsetup.git] / FAQ
1 Sections 
2
3 1. General Questions
4 2. Setup
5 3. Common Problems
6 4. Security Aspects
7 5. Backup and Data Recovery
8 6. Issues with Specific Versions of cryptsetup
9 A. Contributors
10
11
12 1. General Questions 
13
14
15   * What is this?
16
17   This is the FAQ (Frequently Asked Questions) for cryptsetup. It
18   covers Linux disk encryption with plain dm-crypt (one passphrase,
19   no management, no descriptor on disk) and LUKS (multiple user keys
20   with one master key, anti-forensics, descriptor block at start of
21   device, ...). The latest version should usually be available at
22   http://code.google.com/p/cryptsetup/wiki/FrequentlyAskedQuestions
23
24
25   * Who wrote this?
26
27   Current FAQ maintainer is Arno Wagner <arno@wagner.name>. Wherever
28   contributions are from other people, their name should be included
29   in brackets with the respective article. If you want to contribute,
30   send your article, including a descriptive headline, to the
31   maintainer, or the dm-crypt mailing list with something like "FAQ
32   ..." in the subject. Please note that by contributing to this FAQ,
33   you accept the license described below.
34
35   This work is under the "Attribution-Share Alike 3.0 Unported"
36   license, which means distribution is unlimited, you may create
37   derived works, but attributions to original authors and this
38   license statement must be retained and the derived work must be
39   under the same license. See
40   http://creativecommons.org/licenses/by-sa/3.0/ for more details of
41   the license.
42
43   Side note: I did text license research some time ago and I think
44   this license is best suited for the purpose at hand and creates the
45   least problems.
46
47
48 2. Setup 
49
50
51   * Can I encrypt an already existing, non-empty partition to use
52   LUKS?
53
54   There is no converter, and it is not really needed. The way to do
55   this is to make a backup of the device in question, securely wipe
56   the device (as LUKS device initialization does not clear away old
57   data), do a luksFormat, optionally overwrite the encrypted device,
58   create a new filesystem and restore your backup on the now
59   encrypted device. Also refer to sections "Security Aspects" and
60   "Backup and Data Recovery".
61
62   For backup, plain GNU tar works well and backs up anything likely
63   to be in a filesystem.
64
65
66   * How do I use LUKS with a loop-device?
67
68   Just the same as with any block device. If you want, for example,
69   to use a 100MB file as LUKS container, do something like this:
70
71       head -c 100M /dev/zero > luksfile   # create empty file
72       losetup /dev/loop0 luksfile         # map luksfile to /dev/loop0
73       cryptsetup luksFormat /dev/loop0    # create LUKS on the loop device
74  
75   Afterwards just use /dev/loop0 as a you would use a LUKS partition.
76   To unmap the file when done, use "losetup -d /dev/loop0".
77
78
79   * How do I read a dm-crypt key from file?
80
81   Note that the file will still be hashed first, just like keyboard
82   input. Use the --key-file option, like this:
83
84       cryptsetup create --key-file keyfile e1 /dev/loop0
85  
86
87   * How do I read a LUKS slot key from file?
88
89   What you really do here is to read a passphrase from file, just as
90   you would with manual entry of a passphrase for a key-slot. You can
91   add a new passphrase to a free key-slot, set the passphrase of an
92   specific key-slot or put an already configured passphrase into a
93   file. In the last case make sure no trailing newline (0x0a) is
94   contained in the key file, or the passphrase will not work because
95   the whole file is used as input.
96
97   To add a new passphrase to a free key slot from file, use something
98   like this:
99
100       cryptsetup luksAddKey /dev/loop0 keyfile
101  
102   To add a new passphrase to a specific key-slot, use something like
103   this:
104
105       cryptsetup luksAddKey --key-slot 7 /dev/loop0 keyfile
106  
107   To supply a key from file to any LUKS command, use the --key-file
108   option, e.g. like this:
109
110       cryptsetup luksOpen --key-file keyfile /dev/loop0 e1
111  
112
113   * How do I read the LUKS master key from file?
114
115   The question you should ask yourself first, is why you would want
116   to do this. The only legitimate reason I can think of is if you
117   want to have two LUKS devices with the same master key. Even then,
118   I think it would be preferable to just use key-slots with the same
119   passphrase, or to use plain dm-crypt instead. If you really have a
120   good reason, please tell me. If I am convinced, I will add how to
121   do this here.
122
123
124   * What are the security requirements for a key read from file?
125
126   A file-stored key or passphrase has the same security requirements
127   as one entered interactively, however you can use random bytes and
128   thereby use bytes you cannot type on the keyboard. You can use any
129   file you like as key file, for example a plain text file with a
130   human readable passphrase. To generate a file with random bytes,
131   use something like this:
132
133       head -c 256 /dev/random > keyfile
134  
135
136   * If I map a journaled file system using dm-crypt/LUKS, does it
137   still provide its usual transactional guarantees?
138
139   As far as I know you do (but I may be wrong), but please note that
140   these "guarantees" are far weaker than they appear to be. For
141   example, you not not get a hard flush to disk surface even on a
142   call to fsync. In addition, the HDD itself may do independent
143   write reordering. Some other things can go wrong as well. The
144   filesystem developers are aware of these problems and typically
145   can make it work anyways. That said, dm-crypt/LUKS should not make
146   things worse.
147
148   Personally, I have several instances of ext3 on dm-crypt and have
149   not noticed any specific issues so far.
150
151
152   * Can I use LUKS or cryptsetup with a more secure (external) medium
153   for key storage, e.g. TPM or a smartcard?
154
155   Yes, see the answers on using a file-supplied key. You do have to
156   write the glue-logic yourself though. Basically you can have
157   cryptsetup read the key from STDIN and write it there with your
158   own tool that in turn gets the key from the more secure key
159   storage.
160
161
162   * Can I resize a dm-crypt or LUKS partition?
163
164   Yes, you can, as neither dm-crypt nor LUKS stores partition size.
165   Whether you should is a different question. Personally I recommend
166   backup, recreation of the encrypted partition with new size,
167   recreation of the filesystem and restore. This gets around the
168   tricky business of resizing the filesystem. The backup is really
169   non-optional here, as a lot can go wrong, resulting in partial or
170   complete data loss. Using something like gparted to resize an
171   encrypted partition is slow, but pretty safe and should be fine.
172   This will not change the size of the filesystem hidden under the
173   encryption though.
174
175   You also need to be aware of size-based limitations. The one
176   currently relevant is that aes-xts-plain should not be used for
177   encrypted container sizes larger than 2TB.
178
179
180 3. Common Problems 
181
182
183   * My dm-crypt/LUKS mapping does not work! What general steps are
184   there to investigate the problem?
185
186   If you get a specific error message, investigate what it claims
187   first. If not, you may want to check the following things.
188
189   - Check that "/dev", including "/dev/mapper/control" is there. If it is 
190   missing, you may have a problem with the "/dev" tree itself or you
191   may have broken udev rules.
192
193   - Check that you have the device mapper and the crypt target in your kernel.
194   The output of "dmsetup targets" should list a "crypt" target. If it
195   is not there or the command fails, add device mapper and
196   crypt-target to the kernel.
197
198   - Check that the hash-functions and ciphers you want to use are in the kernel.
199   The output of "cat /proc/crypto" needs to list them.
200
201
202   * My dm-crypt mapping suddenly stopped when upgrading cryptsetup.
203
204   The default cipher, hash or mode may have changed (the mode changed
205   from 1.0.x to 1.1.x). See under "6. Issues With Specific Versions of
206   cryptsetup".
207
208
209   * When I call cryptsetup from cron/CGI, I get errors about unknown
210   features?
211
212   If you get errors about unknown parameters or the like that are not
213   present when cryptsetup is called from the shell, make sure you
214   have no older version of cryptsetup on your system that then gets
215   called by cron/CGI.For example some distributions install
216   cryptsetup into /usr/sbin, while a manual install could go to
217   /usr/local/sbin. As a debugging aid, call "cryptsetup --version"
218   from cron/CGI or the non-shell mechanism to be sure you have the
219   right version.
220
221
222   * Unlocking a LUKS device takes very long. Why?
223
224   The iteration time for every key-slot (iteration is needed to
225   prevent dictionary attacks) is calculated during the luksFormat
226   operation. By default it is 1 second on the machine where the
227   format operation is done. If you format a device on a fast machine
228   and then unlock it on a slow machine, the unlocking time can be
229   much more longer. Also take into account that up to 8 key-slots
230   have to be tried in order to find the right one.
231
232   If this is problem, you can add another key-slot using the slow
233   machine with the same passphrase and then remove the old key-slot.
234   The new key-slot will have an iteration count adjusted to 1 second
235   on the slow machine. Use luksKeyAdd and then luksKillSlot or
236   luksRemoveKey. However, this operation will not change volume key
237   iteration count. In order to change that, you will have to backup
238   the data in the LUKS container, luksFormat on the slow machine and
239   restore the data.
240
241
242   * "blkid" sees a LUKS UUID and an ext2/swap UUID on the same device.
243   What is wrong?
244
245   Some old versions of cryptsetup have a bug where the header does
246   not get completely wiped during LUKS format and an older ext2/swap
247   signature remains on the device. This confuses blkid.
248
249   Fix: Wipe the unused header areas by doing a backup and restore of
250   the header with cryptsetup 1.1.x:
251
252       cryptsetup luksHeaderBackup --header-backup-file <file> <device>
253       cryptsetup luksHeaderRestore --header-backup-file <file> <device>
254  
255   If you cannot use a 1.1.x cryptsetup, you can also do a manual wipe
256   of the area in question with the command below. Be very, VERY,
257   careful and make sure to do a backup of the header before. If you
258   get this wrong, your device may become permanently inaccessible.
259
260       dd if=/dev/zero of=<device> bs=512 seek=2 count=6
261    
262
263   * cryptsetup segfaults on Gentoo amd64 hardened ...
264
265   There seems to be some inteference between the hardening and and
266   the way cryptsetup benchmarks PBKDF2. The solution to this is
267   currently not quite clear for an encrypted root filesystem.     For
268   other uses, you can apparently specify USE="dynamic" as compile
269   flag, see http://bugs.gentoo.org/show_bug.cgi?id=283470
270
271
272 4. Security Aspects 
273
274
275   * Should I initialize (overwrite) a new LUKS/dm-crypt partition?
276
277   If you just create a filesystem on it, most of the old data will
278   still be there. If the old data is sensitive, you should overwrite
279   it before encrypting. In any case, not initializing will leave the
280   old data there until the specific sector gets written. That may
281   enable an attacker to determine how much and where on the
282   partition data was written. If you think this is a risk, you can
283   prevent this by overwriting the encrypted device (here assumed to
284   be named "e1") with zeros like this:
285
286       dd_rescue -w /dev/zero /dev/mapper/e1
287  
288  or alternatively with one of the following more standard commands:
289
290       cat /dev/zero > /dev/mapper/e1
291       dd if=/dev/zero of=/dev/mapper/e1
292        
293
294   * How do I securely erase a LUKS (or other) partition?
295
296   For LUKS, if you are in a desperate hurry, overwrite the first few
297   kilobytes of the LUKS partition. This erases the salts and makes
298   access impossible. However a LUKS header backup or full backup will
299   still grant access to most or all data.
300
301   To do this right, overwrite the whole LUKS partition with a single
302   pass of zeros. This is enough for current HDDs. For SDDs you may
303   want to erase the whole drive several times to be sure data is not
304   retained by wear leveling. This is possibly insecure as SDD
305   technology is not fully understood in this regard. Still, due to
306   the anti-forensic properties of the LUKS key-slots, a single
307   overwrite of an SSD could be enough. If in doubt, use physical
308   destruction in addition. Keep in mind to also erase all backups.
309
310   Example for a zero-overwrite erase of partition sda10 done with
311   dd_rescue:
312
313       dd_rescue -w /dev/zero /dev/sda10   
314  
315
316   * How do I securely erase a backup of a LUKS partition or header?
317
318   That depends on the medium it is stored on. For HDD and SSD, use
319   overwrite with zeros. For an SSD, you may want to overwrite the
320   complete SSD several times and use physical destruction in addition,
321   see last item. Treat USB flash drives the same as SSDs. For
322   re-writable CD/DVD, a single overwrite should also be enough, due
323   to the anti-forensic properties of the LUKS keyslots. For
324   write-once media, use physical destruction. For low security
325   requirements, just cut the CD/DVD into several parts. For high
326   security needs, shred or burn the medium. If your backup is on
327   magnetic tape, I advise physical destruction by shredding or
328   burning. The problem with magnetic tape is that it has a higher
329   dynamic range than HDDs and older data may well be recoverable
330   after overwrites. Also write-head alignment issues can lead to
331   data not actually being deleted at all during overwrites.
332
333
334   * Why was the default aes-cbc-plain replaced with aes-cbc-essiv?
335
336   The problem is that cbc-plain has a fingerprint vulnerability, where
337   a specially crafted file placed into the crypto-container can be
338   recognized from the outside. The issue here is that for cbc-plain
339   the initialization vector (IV) is the sector number. The IV gets
340   XORed to the first data chunk of the sector to be encrypted. If you
341   make sure that the first data block to be stored in a sector
342   contains the sector number as well, the first data block to be
343   encrypted is all zeros and always encrypted to the same ciphertext.
344   This also works if the first data chunk just has a constant XOR
345   with the sector number. By having several shifted patterns you can
346   take care of the case of a non-power-of-two start sector number of
347   the file.
348
349   This mechanism allows you to create a pattern of sectors that have
350   the same first ciphertext block and signal one bit per sector to the
351   outside, allowing you to e.g. mark media files that way for
352   recognition without decryption. For large files this is a
353   practical attack. For small ones, you do not have enough blocks to
354   signal and take care of different file starting offsets.
355
356   In order to prevent this attack, the default was changed to
357   cbc-essiv. ESSIV uses a keyed hash of the sector number, with the
358   encryption key as key. This makes the IV unpredictable without
359   knowing the encryption key and the watermarking attack fails.
360
361
362   * Are there any problems with "plain" IV? What is "plain64"?
363
364   First, "plain" and "plain64" are both not safe to use with CBC, see
365   previous FAQ item.
366
367   However there are modes, like XTS, that are secure with "plain" IV.
368   The next limit is that "plain" is 64 bit, with the upper 32 bit set
369   to zero. This means that on volumes larger than 2TB, the IV
370   repeats, creating a vulnerability that potentially leaks some
371   data. To avoid this, use "plain64", which uses the full sector
372   number up to 64 bit. Note that "plain64" requires a kernel >=
373   2.6.33. Also note that "plain64" is backwards compatible for
374   volume sizes <= 2TB, but not for those > 2TB. Finally, "plain64"
375   does not cause any performance penalty compared to "plain".
376
377
378   * What about XTS mode?
379
380   XTS mode is potentially even more secure than cbc-essiv (but only if
381   cbc-essiv is insecure in your scenario). It is a NIST standard and
382   used, e.g. in Truecrypt. At the moment, if you want to use it, you
383   have to specify it manually as "aes-xts-plain", i.e.
384
385       cryptsetup -c aes-xts-plain luksFormat <device>
386  
387   For volumes >2TB and kernels >= 2.6.33 use "plain64" (see FAQ item
388   on "plain" and "plain64"):
389
390       cryptsetup -c aes-xts-plain64 luksFormat <device>
391  
392
393 5. Backup and Data Recovery 
394
395
396   * *What happens if I overwrite the start of a LUKS partition or
397
398     damage the LUKS header or key-slots?*
399
400   There are two critical components for decryption: The salt values
401   in the header itself and the key-slots. If the salt values are
402   overwritten or changed, nothing (in the cryptographically strong
403   sense) can be done to access the data, unless there is a backup of
404   the LUKS header. If a key-slot is damaged, the data can still be
405   read with a different keys-lot, if one is in use.
406
407
408   * What does the on-disk structure of dm-crypt look like?
409
410   There is none. dm-crypt takes a block device and gives encrypted
411   access to each of its blocks with a key derived from the passphrase
412   given. If you use a cipher different than the default, you have to
413   specify that as a parameter to cryptsetup too. If you want to
414   change the password, you basically have to create a second
415   encrypted device with the new passphrase and copy your data over.
416   On the plus side, if you accidentally overwrite any part of a
417   dm-crypt device, the damage will be limited to the are you
418   overwrote.
419
420
421   * What does the on-disk structure of LUKS look like?
422
423   A LUKS partition consists of a header, followed by 8 key-slot
424   descriptors, followed by 8 key slots, followed by the encrypted
425   data area.
426
427   Header and key-slot descriptors fill the first 592 bytes. The
428   key-slot size depends on the creation parameters, namely on the
429   number of anti-forensic stripes and on key block alignment.
430
431   With 4000 stripes (the default), each key-slot is a bit less than
432   128kB in size. Due to sector alignment of the key-slot start, that
433   means the key block 0 is at offset 0x1000-0x20400, key block 1 at
434   offset 0x21000-0x40400, and key block 7 at offset 0xc1000-0xe0400.
435   The space to the next full sector address is padded with zeros.
436   Never used key-slots are filled with what the disk originally
437   contained there, a key-slot removed with "luksRemoveKey" or
438   "luksKillSlot" gets filled with 0xff. Start of bulk data (with the
439   default 4000 stripes and 8 key-slots) is at 0x101000, i.e. at
440   1'052'672 bytes, i.e. at 1MiB + 4096 bytes from the start of the
441   partition. This is also the value given by command "luksDump" with
442   "Payload offset: 2056", just multiply by the sector size (512
443   bytes). Incidentally, "luksHeaderBackup" dumps exactly the first
444   1'052'672 bytes to file and "luksHeaderRestore" restores them.
445
446   The exact specification of the format is here:
447   http://code.google.com/p/cryptsetup/wiki/Specification
448
449
450   * How do I backup a LUKS header?
451
452   While you could just copy the appropriate number of bytes from the
453   start of the LUKS partition, the best way is to use command option
454   "luksHeaderBackup" of cryptsetup. This protects also against errors
455   when non-standard parameters have been used in LUKS partition
456   creation. Example:
457
458  
459       cryptsetup luksHeaderBackup --header-backup-file h_bak /dev/mapper/c1
460  
461
462   * How do I backup a LUKS partition?
463
464   You do a sector-image of the whole partition. This will contain the
465   LUKS header, the keys-slots and the data ares. It can be done
466   under Linux e.g. with dd_rescue (for a direct image copy) and with
467   "cat" or "dd". Example:
468
469       cat /dev/sda10 > sda10.img
470       dd_rescue /dev/sda10 sda10.img 
471  
472   You can also use any other backup software that is capable of making
473   a sector image of a partition. Note that compression is
474   ineffective for encrypted data, hence it does not sense to use it.
475
476
477   * Do I need a backup of the full partition? Would the header and
478   key-slots not be enough?
479
480   Backup protects you against two things: Disk loss or corruption and
481   user error. By far the most questions on the dm-crypt mailing list
482   about how to recover a damaged LUKS partition are related to user
483   error. For example, if you create a new filesystem on a LUKS
484   partition, chances are good that all data is lost permanently.
485
486   For this case, a header+key-slot backup would often be enough. But
487   keep in mind that a HDD has roughly a failure risk of 5% per year.
488   It is highly advisable to have a complete backup to protect against
489   this case.
490
491
492   * Are there security risks from a backup of the LUKS header or a
493   whole LUKS partition?
494
495   Yes. One risk is that if you remove access rights for specific
496   key-slots by deleting their contents, the data can still be
497   accessed with invalidated passphrase and the backup. The other risk
498   is that if you erase a LUKS partition, a backup could still grant
499   access, especially if you only erased the LUKS header and not the
500   whole partition.
501
502
503   * I think this is overly complicated. Is there an alternative?
504
505   Yes, you can use plain dm-crypt. It does not allow multiple
506   passphrases, but on the plus side, it has zero on disk description
507   and if you overwrite some part of a plain dm-crypt partition,
508   exactly the overwritten parts are lost (rounded up to sector
509   borders).
510
511
512 6. Issues with Specific Versions of cryptsetup 
513
514
515   * When using the create command for plain dm-crypt with cryptsetup
516   1.1.x, the mapping is incompatible and my data is not accessible
517   anymore!
518
519   With cryptsetup 1.1.x, the distro maintainer can define different
520   default encryption modes for LUKS and plain devices. You can check
521   these compiled-in defaults using "cryptsetup --help". Moreover, the
522   plain device default changed because the old IV mode was
523   vulnerable to a watermarking attack.
524
525   If you are using a plain device and you need a compatible mode, just
526   specify cipher, key size and hash algorithm explicitly. For
527   compatibility with cryptsetup 1.0.x defaults, simple use the
528   following:
529
530       cryptsetup create -c aes-cbc-plain -s 256 -h ripemd160 <name> <device>
531  
532    LUKS stores cipher and mode in the metadata on disk, avoiding this
533   problem.
534
535
536   * cryptsetup on SLED 10 has problems...
537
538   SLED 10 is missing an essential kernel patch for dm-crypt, which
539   is broken in its kernel as a result. There may be a very old
540   version of cryptsetup (1.0.x) provided by SLED, which should also
541   not be used anymore as well. My advice would be to drop SLED 10.
542
543  A. Contributors In no particular order:
544
545   - Arno Wagner
546   - Milan Broz