dm-integrity.txt 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. The dm-integrity target emulates a block device that has additional
  2. per-sector tags that can be used for storing integrity information.
  3. A general problem with storing integrity tags with every sector is that
  4. writing the sector and the integrity tag must be atomic - i.e. in case of
  5. crash, either both sector and integrity tag or none of them is written.
  6. To guarantee write atomicity, the dm-integrity target uses journal, it
  7. writes sector data and integrity tags into a journal, commits the journal
  8. and then copies the data and integrity tags to their respective location.
  9. The dm-integrity target can be used with the dm-crypt target - in this
  10. situation the dm-crypt target creates the integrity data and passes them
  11. to the dm-integrity target via bio_integrity_payload attached to the bio.
  12. In this mode, the dm-crypt and dm-integrity targets provide authenticated
  13. disk encryption - if the attacker modifies the encrypted device, an I/O
  14. error is returned instead of random data.
  15. The dm-integrity target can also be used as a standalone target, in this
  16. mode it calculates and verifies the integrity tag internally. In this
  17. mode, the dm-integrity target can be used to detect silent data
  18. corruption on the disk or in the I/O path.
  19. When loading the target for the first time, the kernel driver will format
  20. the device. But it will only format the device if the superblock contains
  21. zeroes. If the superblock is neither valid nor zeroed, the dm-integrity
  22. target can't be loaded.
  23. To use the target for the first time:
  24. 1. overwrite the superblock with zeroes
  25. 2. load the dm-integrity target with one-sector size, the kernel driver
  26. will format the device
  27. 3. unload the dm-integrity target
  28. 4. read the "provided_data_sectors" value from the superblock
  29. 5. load the dm-integrity target with the the target size
  30. "provided_data_sectors"
  31. 6. if you want to use dm-integrity with dm-crypt, load the dm-crypt target
  32. with the size "provided_data_sectors"
  33. Target arguments:
  34. 1. the underlying block device
  35. 2. the number of reserved sector at the beginning of the device - the
  36. dm-integrity won't read of write these sectors
  37. 3. the size of the integrity tag (if "-" is used, the size is taken from
  38. the internal-hash algorithm)
  39. 4. mode:
  40. D - direct writes (without journal) - in this mode, journaling is
  41. not used and data sectors and integrity tags are written
  42. separately. In case of crash, it is possible that the data
  43. and integrity tag doesn't match.
  44. J - journaled writes - data and integrity tags are written to the
  45. journal and atomicity is guaranteed. In case of crash,
  46. either both data and tag or none of them are written. The
  47. journaled mode degrades write throughput twice because the
  48. data have to be written twice.
  49. R - recovery mode - in this mode, journal is not replayed,
  50. checksums are not checked and writes to the device are not
  51. allowed. This mode is useful for data recovery if the
  52. device cannot be activated in any of the other standard
  53. modes.
  54. 5. the number of additional arguments
  55. Additional arguments:
  56. journal_sectors:number
  57. The size of journal, this argument is used only if formatting the
  58. device. If the device is already formatted, the value from the
  59. superblock is used.
  60. interleave_sectors:number
  61. The number of interleaved sectors. This values is rounded down to
  62. a power of two. If the device is already formatted, the value from
  63. the superblock is used.
  64. buffer_sectors:number
  65. The number of sectors in one buffer. The value is rounded down to
  66. a power of two.
  67. The tag area is accessed using buffers, the buffer size is
  68. configurable. The large buffer size means that the I/O size will
  69. be larger, but there could be less I/Os issued.
  70. journal_watermark:number
  71. The journal watermark in percents. When the size of the journal
  72. exceeds this watermark, the thread that flushes the journal will
  73. be started.
  74. commit_time:number
  75. Commit time in milliseconds. When this time passes, the journal is
  76. written. The journal is also written immediatelly if the FLUSH
  77. request is received.
  78. internal_hash:algorithm(:key) (the key is optional)
  79. Use internal hash or crc.
  80. When this argument is used, the dm-integrity target won't accept
  81. integrity tags from the upper target, but it will automatically
  82. generate and verify the integrity tags.
  83. You can use a crc algorithm (such as crc32), then integrity target
  84. will protect the data against accidental corruption.
  85. You can also use a hmac algorithm (for example
  86. "hmac(sha256):0123456789abcdef"), in this mode it will provide
  87. cryptographic authentication of the data without encryption.
  88. When this argument is not used, the integrity tags are accepted
  89. from an upper layer target, such as dm-crypt. The upper layer
  90. target should check the validity of the integrity tags.
  91. recalculate
  92. Recalculate the integrity tags automatically. It is only valid
  93. when using internal hash.
  94. journal_crypt:algorithm(:key) (the key is optional)
  95. Encrypt the journal using given algorithm to make sure that the
  96. attacker can't read the journal. You can use a block cipher here
  97. (such as "cbc(aes)") or a stream cipher (for example "chacha20",
  98. "salsa20", "ctr(aes)" or "ecb(arc4)").
  99. The journal contains history of last writes to the block device,
  100. an attacker reading the journal could see the last sector nubmers
  101. that were written. From the sector numbers, the attacker can infer
  102. the size of files that were written. To protect against this
  103. situation, you can encrypt the journal.
  104. journal_mac:algorithm(:key) (the key is optional)
  105. Protect sector numbers in the journal from accidental or malicious
  106. modification. To protect against accidental modification, use a
  107. crc algorithm, to protect against malicious modification, use a
  108. hmac algorithm with a key.
  109. This option is not needed when using internal-hash because in this
  110. mode, the integrity of journal entries is checked when replaying
  111. the journal. Thus, modified sector number would be detected at
  112. this stage.
  113. block_size:number
  114. The size of a data block in bytes. The larger the block size the
  115. less overhead there is for per-block integrity metadata.
  116. Supported values are 512, 1024, 2048 and 4096 bytes. If not
  117. specified the default block size is 512 bytes.
  118. legacy_recalculate
  119. Allow recalculating of volumes with HMAC keys. This is disabled by
  120. default for security reasons - an attacker could modify the volume,
  121. set recalc_sector to zero, and the kernel would not detect the
  122. modification.
  123. The journal mode (D/J), buffer_sectors, journal_watermark, commit_time can
  124. be changed when reloading the target (load an inactive table and swap the
  125. tables with suspend and resume). The other arguments should not be changed
  126. when reloading the target because the layout of disk data depend on them
  127. and the reloaded target would be non-functional.
  128. The layout of the formatted block device:
  129. * reserved sectors (they are not used by this target, they can be used for
  130. storing LUKS metadata or for other purpose), the size of the reserved
  131. area is specified in the target arguments
  132. * superblock (4kiB)
  133. * magic string - identifies that the device was formatted
  134. * version
  135. * log2(interleave sectors)
  136. * integrity tag size
  137. * the number of journal sections
  138. * provided data sectors - the number of sectors that this target
  139. provides (i.e. the size of the device minus the size of all
  140. metadata and padding). The user of this target should not send
  141. bios that access data beyond the "provided data sectors" limit.
  142. * flags - a flag is set if journal_mac is used
  143. * journal
  144. The journal is divided into sections, each section contains:
  145. * metadata area (4kiB), it contains journal entries
  146. every journal entry contains:
  147. * logical sector (specifies where the data and tag should
  148. be written)
  149. * last 8 bytes of data
  150. * integrity tag (the size is specified in the superblock)
  151. every metadata sector ends with
  152. * mac (8-bytes), all the macs in 8 metadata sectors form a
  153. 64-byte value. It is used to store hmac of sector
  154. numbers in the journal section, to protect against a
  155. possibility that the attacker tampers with sector
  156. numbers in the journal.
  157. * commit id
  158. * data area (the size is variable; it depends on how many journal
  159. entries fit into the metadata area)
  160. every sector in the data area contains:
  161. * data (504 bytes of data, the last 8 bytes are stored in
  162. the journal entry)
  163. * commit id
  164. To test if the whole journal section was written correctly, every
  165. 512-byte sector of the journal ends with 8-byte commit id. If the
  166. commit id matches on all sectors in a journal section, then it is
  167. assumed that the section was written correctly. If the commit id
  168. doesn't match, the section was written partially and it should not
  169. be replayed.
  170. * one or more runs of interleaved tags and data. Each run contains:
  171. * tag area - it contains integrity tags. There is one tag for each
  172. sector in the data area
  173. * data area - it contains data sectors. The number of data sectors
  174. in one run must be a power of two. log2 of this value is stored
  175. in the superblock.