0001 =========
0002 dm-verity
0003 =========
0004
0005 Device-Mapper's "verity" target provides transparent integrity checking of
0006 block devices using a cryptographic digest provided by the kernel crypto API.
0007 This target is read-only.
0008
0009 Construction Parameters
0010 =======================
0011
0012 ::
0013
0014 <version> <dev> <hash_dev>
0015 <data_block_size> <hash_block_size>
0016 <num_data_blocks> <hash_start_block>
0017 <algorithm> <digest> <salt>
0018 [<#opt_params> <opt_params>]
0019
0020 <version>
0021 This is the type of the on-disk hash format.
0022
0023 0 is the original format used in the Chromium OS.
0024 The salt is appended when hashing, digests are stored continuously and
0025 the rest of the block is padded with zeroes.
0026
0027 1 is the current format that should be used for new devices.
0028 The salt is prepended when hashing and each digest is
0029 padded with zeroes to the power of two.
0030
0031 <dev>
0032 This is the device containing data, the integrity of which needs to be
0033 checked. It may be specified as a path, like /dev/sdaX, or a device number,
0034 <major>:<minor>.
0035
0036 <hash_dev>
0037 This is the device that supplies the hash tree data. It may be
0038 specified similarly to the device path and may be the same device. If the
0039 same device is used, the hash_start should be outside the configured
0040 dm-verity device.
0041
0042 <data_block_size>
0043 The block size on a data device in bytes.
0044 Each block corresponds to one digest on the hash device.
0045
0046 <hash_block_size>
0047 The size of a hash block in bytes.
0048
0049 <num_data_blocks>
0050 The number of data blocks on the data device. Additional blocks are
0051 inaccessible. You can place hashes to the same partition as data, in this
0052 case hashes are placed after <num_data_blocks>.
0053
0054 <hash_start_block>
0055 This is the offset, in <hash_block_size>-blocks, from the start of hash_dev
0056 to the root block of the hash tree.
0057
0058 <algorithm>
0059 The cryptographic hash algorithm used for this device. This should
0060 be the name of the algorithm, like "sha1".
0061
0062 <digest>
0063 The hexadecimal encoding of the cryptographic hash of the root hash block
0064 and the salt. This hash should be trusted as there is no other authenticity
0065 beyond this point.
0066
0067 <salt>
0068 The hexadecimal encoding of the salt value.
0069
0070 <#opt_params>
0071 Number of optional parameters. If there are no optional parameters,
0072 the optional parameters section can be skipped or #opt_params can be zero.
0073 Otherwise #opt_params is the number of following arguments.
0074
0075 Example of optional parameters section:
0076 1 ignore_corruption
0077
0078 ignore_corruption
0079 Log corrupted blocks, but allow read operations to proceed normally.
0080
0081 restart_on_corruption
0082 Restart the system when a corrupted block is discovered. This option is
0083 not compatible with ignore_corruption and requires user space support to
0084 avoid restart loops.
0085
0086 panic_on_corruption
0087 Panic the device when a corrupted block is discovered. This option is
0088 not compatible with ignore_corruption and restart_on_corruption.
0089
0090 ignore_zero_blocks
0091 Do not verify blocks that are expected to contain zeroes and always return
0092 zeroes instead. This may be useful if the partition contains unused blocks
0093 that are not guaranteed to contain zeroes.
0094
0095 use_fec_from_device <fec_dev>
0096 Use forward error correction (FEC) to recover from corruption if hash
0097 verification fails. Use encoding data from the specified device. This
0098 may be the same device where data and hash blocks reside, in which case
0099 fec_start must be outside data and hash areas.
0100
0101 If the encoding data covers additional metadata, it must be accessible
0102 on the hash device after the hash blocks.
0103
0104 Note: block sizes for data and hash devices must match. Also, if the
0105 verity <dev> is encrypted the <fec_dev> should be too.
0106
0107 fec_roots <num>
0108 Number of generator roots. This equals to the number of parity bytes in
0109 the encoding data. For example, in RS(M, N) encoding, the number of roots
0110 is M-N.
0111
0112 fec_blocks <num>
0113 The number of encoding data blocks on the FEC device. The block size for
0114 the FEC device is <data_block_size>.
0115
0116 fec_start <offset>
0117 This is the offset, in <data_block_size> blocks, from the start of the
0118 FEC device to the beginning of the encoding data.
0119
0120 check_at_most_once
0121 Verify data blocks only the first time they are read from the data device,
0122 rather than every time. This reduces the overhead of dm-verity so that it
0123 can be used on systems that are memory and/or CPU constrained. However, it
0124 provides a reduced level of security because only offline tampering of the
0125 data device's content will be detected, not online tampering.
0126
0127 Hash blocks are still verified each time they are read from the hash device,
0128 since verification of hash blocks is less performance critical than data
0129 blocks, and a hash block will not be verified any more after all the data
0130 blocks it covers have been verified anyway.
0131
0132 root_hash_sig_key_desc <key_description>
0133 This is the description of the USER_KEY that the kernel will lookup to get
0134 the pkcs7 signature of the roothash. The pkcs7 signature is used to validate
0135 the root hash during the creation of the device mapper block device.
0136 Verification of roothash depends on the config DM_VERITY_VERIFY_ROOTHASH_SIG
0137 being set in the kernel. The signatures are checked against the builtin
0138 trusted keyring by default, or the secondary trusted keyring if
0139 DM_VERITY_VERIFY_ROOTHASH_SIG_SECONDARY_KEYRING is set. The secondary
0140 trusted keyring includes by default the builtin trusted keyring, and it can
0141 also gain new certificates at run time if they are signed by a certificate
0142 already in the secondary trusted keyring.
0143
0144 Theory of operation
0145 ===================
0146
0147 dm-verity is meant to be set up as part of a verified boot path. This
0148 may be anything ranging from a boot using tboot or trustedgrub to just
0149 booting from a known-good device (like a USB drive or CD).
0150
0151 When a dm-verity device is configured, it is expected that the caller
0152 has been authenticated in some way (cryptographic signatures, etc).
0153 After instantiation, all hashes will be verified on-demand during
0154 disk access. If they cannot be verified up to the root node of the
0155 tree, the root hash, then the I/O will fail. This should detect
0156 tampering with any data on the device and the hash data.
0157
0158 Cryptographic hashes are used to assert the integrity of the device on a
0159 per-block basis. This allows for a lightweight hash computation on first read
0160 into the page cache. Block hashes are stored linearly, aligned to the nearest
0161 block size.
0162
0163 If forward error correction (FEC) support is enabled any recovery of
0164 corrupted data will be verified using the cryptographic hash of the
0165 corresponding data. This is why combining error correction with
0166 integrity checking is essential.
0167
0168 Hash Tree
0169 ---------
0170
0171 Each node in the tree is a cryptographic hash. If it is a leaf node, the hash
0172 of some data block on disk is calculated. If it is an intermediary node,
0173 the hash of a number of child nodes is calculated.
0174
0175 Each entry in the tree is a collection of neighboring nodes that fit in one
0176 block. The number is determined based on block_size and the size of the
0177 selected cryptographic digest algorithm. The hashes are linearly-ordered in
0178 this entry and any unaligned trailing space is ignored but included when
0179 calculating the parent node.
0180
0181 The tree looks something like:
0182
0183 alg = sha256, num_blocks = 32768, block_size = 4096
0184
0185 ::
0186
0187 [ root ]
0188 / . . . \
0189 [entry_0] [entry_1]
0190 / . . . \ . . . \
0191 [entry_0_0] . . . [entry_0_127] . . . . [entry_1_127]
0192 / ... \ / . . . \ / \
0193 blk_0 ... blk_127 blk_16256 blk_16383 blk_32640 . . . blk_32767
0194
0195
0196 On-disk format
0197 ==============
0198
0199 The verity kernel code does not read the verity metadata on-disk header.
0200 It only reads the hash blocks which directly follow the header.
0201 It is expected that a user-space tool will verify the integrity of the
0202 verity header.
0203
0204 Alternatively, the header can be omitted and the dmsetup parameters can
0205 be passed via the kernel command-line in a rooted chain of trust where
0206 the command-line is verified.
0207
0208 Directly following the header (and with sector number padded to the next hash
0209 block boundary) are the hash blocks which are stored a depth at a time
0210 (starting from the root), sorted in order of increasing index.
0211
0212 The full specification of kernel parameters and on-disk metadata format
0213 is available at the cryptsetup project's wiki page
0214
0215 https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity
0216
0217 Status
0218 ======
0219 V (for Valid) is returned if every check performed so far was valid.
0220 If any check failed, C (for Corruption) is returned.
0221
0222 Example
0223 =======
0224 Set up a device::
0225
0226 # dmsetup create vroot --readonly --table \
0227 "0 2097152 verity 1 /dev/sda1 /dev/sda2 4096 4096 262144 1 sha256 "\
0228 "4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 "\
0229 "1234000000000000000000000000000000000000000000000000000000000000"
0230
0231 A command line tool veritysetup is available to compute or verify
0232 the hash tree or activate the kernel device. This is available from
0233 the cryptsetup upstream repository https://gitlab.com/cryptsetup/cryptsetup/
0234 (as a libcryptsetup extension).
0235
0236 Create hash on the device::
0237
0238 # veritysetup format /dev/sda1 /dev/sda2
0239 ...
0240 Root hash: 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076
0241
0242 Activate the device::
0243
0244 # veritysetup create vroot /dev/sda1 /dev/sda2 \
0245 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076