0 is the original format used in the Chromium OS.
The salt is appended when hashing, digests are stored continuously and
the rest of the block is padded with zeroes.
1 is the current format that should be used for new devices.
The salt is prepended when hashing and each digest is
padded with zeroes to the power of two.
data_dev: device containing the data the integrity of which needs to be checked.
It may be specified as a path, like /dev/sdaX, or a device number, major:minor.
hash_dev: device that that supplies the hash tree data.
It may be specified similarly to the data device path and may be the same device.
If the same device is used, the hash_start should be outside of the dm-verity configured device size.
data_blk_size: The block size in bytes on a data device. Each block corresponds to one digest on the hash device.
hash_blk_size: The size of a hash block in bytes.
#blocks: The number of data blocks on the data device. Additional blocks are inaccessible.
hash_start: offset, in hash_blk_size blocks, from the start of hash_device to the root block of the hash tree.
alg: The cryptographic hash algorithm used for this device. This should be the name of the algorithm, like "sha256".
digest: The hexadecimal encoding of the cryptographic hash of the root hash block and the salt.
This hash should be trusted.
salt: The hexadecimal encoding of the salt value.
#opt_params: Number of optional parameters.
If there are no optional parameters, the optional parameters section can be skipped or it can be zero.
Otherwise it is the number of following arguments. Available since: 1.2.0 (no proper version set) (kernel 4.1)
ignore_corruption: Log corrupted blocks, but allow read operations to proceed normally. Available since: 1.2.0 (no proper version set) (kernel 4.1)
restart_on_corruption: Restart the system when a corrupted block is discovered.
This option is not compatible with ignore_corruption and requires user space support to avoid restart loops. Available since: 1.2.0 (no proper version set) (kernel 4.1)
ignore_zero_blocks: Do not verify blocks that are expected to contain zeroes and always return zeroes instead.
This may be useful if the partition contains unused blocks that are not guaranteed to contain zeroes. Available since: 1.3.0 (kernel 4.5)
check_at_most_once: Verify data blocks only the first time they are read from the data device, rather than every time.
It provides a reduced level of security because only offline tampering of the data device's content will be detected, not online tampering. Available since: 1.4.0 (kernel 4.17)
root_hash_sig_key_desc <key_description>: The PKCS7 signature to validate the root hash during the creation of the device.
The key must be in trusted kernel keyring.
Verification of roothash depends on the config DM_VERITY_VERIFY_ROOTHASH_SIG being set. Available since: 1.5.0 (kernel 5.4)
use_fec_from_device <fec_dev>: Use forward error correction (FEC) to recover from corruption if hash verification fails.
Use encoding data from the specified device. This may be the same device where data and hash blocks reside,
in which case fec_start must be outside data and hash areas.
If the encoding data covers additional metadata, it must be accessible on the hash device after the hash blocks.
Note: block sizes for data and hash devices must match. Also, if the verity <dev> is encrypted the <fec_dev> should be too. Available since: 1.3.0 (kernel 4.5)
fec_roots <num>: Number of generator roots. This equals to the number of parity bytes in the encoding data.
For example, in RS(M, N) encoding, the number of roots is M-N.
M is 255 and M-N is between 2 and 24 (including).
RS decoder can correct up to <num>/2 bytes that contains error and <num> errasures in each codeword.
Erasures are identified by hash information on hash_device. Available since: 1.3.0 (kernel 4.5)
fec_blocks <num>: The number of encoding data blocks on the FEC device.
The block size for the FEC device is <data_block_size>.
FEC is computed over: data blocks | hash blocks | metadata (optional).
We allow metadata after hash blocks to support a use case where all data is stored on the same device and FEC covers the entire area. Available since: 1.3.0 (kernel 4.5)
fec_start <offset>: This is the offset, in <data_block_size> blocks, from the start of the FEC device to the beginning of the encoding data. Available since: 1.3.0 (kernel 4.5)
You can check the full mapping table using dmsetup table.
Note that for all device-mapper operations is required root privilege (CAP_SYSADMIN).
The newly created device then appears as /dev/mapper/name.
Configuration using veritysetup
Preparing hash device (formatting) veritysetup format /dev/sdb /dev/sdc
Activation of verity data device veritysetup create name /dev/sdb /dev/sdc <root_digest>
Theory of operation
Dm-verity is meant to be setup as part of a verified boot path.
When a dm-verity device is configured, it is expected that the caller
has been authenticated in some way. After instantiation, all hashes
will be verified on-demand during disk access. If they cannot be verified
up to the root node of the tree, the root hash, then the I/O will fail.
This should identify tampering with any data on the device and the hash data.
Cryptographic hashes are used to assert the integrity of the device
on a per-block basis. This allows for a lightweight hash computation
on first read into the page cache. Block hashes are stored linearly,
aligned to the nearest block size.
Each node in the tree is a cryptographic hash. If it is a leaf node,
the hash is calculated of some data block on disk. If it is
an intermediary node, the hash is calculated of a number of child nodes.
Each entry in the tree is a collection of neighboring nodes that fit
in one block. The number is determined based on block_size and the size
of the selected cryptographic digest algorithm. The hashes are
linearly-ordered in this entry and any unaligned trailing space
is ignored but included when calculating the parent node.