verity.txt 5.8 KB

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