verity.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. dm-verity
  2. ==========
  3. Device-Mapper's "verity" target provides transparent integrity checking of
  4. block devices using a cryptographic digest provided by the kernel crypto API.
  5. This target is read-only.
  6. Construction Parameters
  7. =======================
  8. <version> <dev> <hash_dev>
  9. <data_block_size> <hash_block_size>
  10. <num_data_blocks> <hash_start_block>
  11. <algorithm> <digest> <salt>
  12. [<#opt_params> <opt_params>]
  13. <version>
  14. This is the type of the on-disk hash format.
  15. 0 is the original format used in the Chromium OS.
  16. The salt is appended when hashing, digests are stored continuously and
  17. the rest of the block is padded with zeros.
  18. 1 is the current format that should be used for new devices.
  19. The salt is prepended when hashing and each digest is
  20. padded with zeros to the power of two.
  21. <dev>
  22. This is the device containing data, the integrity of which needs to be
  23. checked. It may be specified as a path, like /dev/sdaX, or a device number,
  24. <major>:<minor>.
  25. <hash_dev>
  26. This is the device that supplies the hash tree data. It may be
  27. specified similarly to the device path and may be the same device. If the
  28. same device is used, the hash_start should be outside the configured
  29. dm-verity device.
  30. <data_block_size>
  31. The block size on a data device in bytes.
  32. Each block corresponds to one digest on the hash device.
  33. <hash_block_size>
  34. The size of a hash block in bytes.
  35. <num_data_blocks>
  36. The number of data blocks on the data device. Additional blocks are
  37. inaccessible. You can place hashes to the same partition as data, in this
  38. case hashes are placed after <num_data_blocks>.
  39. <hash_start_block>
  40. This is the offset, in <hash_block_size>-blocks, from the start of hash_dev
  41. to the root block of the hash tree.
  42. <algorithm>
  43. The cryptographic hash algorithm used for this device. This should
  44. be the name of the algorithm, like "sha1".
  45. <digest>
  46. The hexadecimal encoding of the cryptographic hash of the root hash block
  47. and the salt. This hash should be trusted as there is no other authenticity
  48. beyond this point.
  49. <salt>
  50. The hexadecimal encoding of the salt value.
  51. <#opt_params>
  52. Number of optional parameters. If there are no optional parameters,
  53. the optional paramaters section can be skipped or #opt_params can be zero.
  54. Otherwise #opt_params is the number of following arguments.
  55. Example of optional parameters section:
  56. 1 ignore_corruption
  57. ignore_corruption
  58. Log corrupted blocks, but allow read operations to proceed normally.
  59. restart_on_corruption
  60. Restart the system when a corrupted block is discovered. This option is
  61. not compatible with ignore_corruption and requires user space support to
  62. avoid restart loops.
  63. Theory of operation
  64. ===================
  65. dm-verity is meant to be set up as part of a verified boot path. This
  66. may be anything ranging from a boot using tboot or trustedgrub to just
  67. booting from a known-good device (like a USB drive or CD).
  68. When a dm-verity device is configured, it is expected that the caller
  69. has been authenticated in some way (cryptographic signatures, etc).
  70. After instantiation, all hashes will be verified on-demand during
  71. disk access. If they cannot be verified up to the root node of the
  72. tree, the root hash, then the I/O will fail. This should detect
  73. tampering with any data on the device and the hash data.
  74. Cryptographic hashes are used to assert the integrity of the device on a
  75. per-block basis. This allows for a lightweight hash computation on first read
  76. into the page cache. Block hashes are stored linearly, aligned to the nearest
  77. block size.
  78. Hash Tree
  79. ---------
  80. Each node in the tree is a cryptographic hash. If it is a leaf node, the hash
  81. of some data block on disk is calculated. If it is an intermediary node,
  82. the hash of a number of child nodes is calculated.
  83. Each entry in the tree is a collection of neighboring nodes that fit in one
  84. block. The number is determined based on block_size and the size of the
  85. selected cryptographic digest algorithm. The hashes are linearly-ordered in
  86. this entry and any unaligned trailing space is ignored but included when
  87. calculating the parent node.
  88. The tree looks something like:
  89. alg = sha256, num_blocks = 32768, block_size = 4096
  90. [ root ]
  91. / . . . \
  92. [entry_0] [entry_1]
  93. / . . . \ . . . \
  94. [entry_0_0] . . . [entry_0_127] . . . . [entry_1_127]
  95. / ... \ / . . . \ / \
  96. blk_0 ... blk_127 blk_16256 blk_16383 blk_32640 . . . blk_32767
  97. On-disk format
  98. ==============
  99. The verity kernel code does not read the verity metadata on-disk header.
  100. It only reads the hash blocks which directly follow the header.
  101. It is expected that a user-space tool will verify the integrity of the
  102. verity header.
  103. Alternatively, the header can be omitted and the dmsetup parameters can
  104. be passed via the kernel command-line in a rooted chain of trust where
  105. the command-line is verified.
  106. Directly following the header (and with sector number padded to the next hash
  107. block boundary) are the hash blocks which are stored a depth at a time
  108. (starting from the root), sorted in order of increasing index.
  109. The full specification of kernel parameters and on-disk metadata format
  110. is available at the cryptsetup project's wiki page
  111. https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity
  112. Status
  113. ======
  114. V (for Valid) is returned if every check performed so far was valid.
  115. If any check failed, C (for Corruption) is returned.
  116. Example
  117. =======
  118. Set up a device:
  119. # dmsetup create vroot --readonly --table \
  120. "0 2097152 verity 1 /dev/sda1 /dev/sda2 4096 4096 262144 1 sha256 "\
  121. "4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 "\
  122. "1234000000000000000000000000000000000000000000000000000000000000"
  123. A command line tool veritysetup is available to compute or verify
  124. the hash tree or activate the kernel device. This is available from
  125. the cryptsetup upstream repository https://gitlab.com/cryptsetup/cryptsetup/
  126. (as a libcryptsetup extension).
  127. Create hash on the device:
  128. # veritysetup format /dev/sda1 /dev/sda2
  129. ...
  130. Root hash: 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076
  131. Activate the device:
  132. # veritysetup create vroot /dev/sda1 /dev/sda2 \
  133. 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076