blob: d602c801ff5907ae2d882fd924c202feed73b95c [file] [log] [blame]
Mikulas Patockaa4ffc152012-03-28 18:43:38 +01001dm-verity
2==========
3
4Device-Mapper's "verity" target provides transparent integrity checking of
5block devices using a cryptographic digest provided by the kernel crypto API.
6This target is read-only.
7
8Construction Parameters
9=======================
Milan Broz18068bd2012-07-03 12:55:41 +010010 <version> <dev> <hash_dev>
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010011 <data_block_size> <hash_block_size>
12 <num_data_blocks> <hash_start_block>
13 <algorithm> <digest> <salt>
Sami Tolvanen65ff5b72015-03-18 15:52:14 +000014 [<#opt_params> <opt_params>]
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010015
16<version>
Milan Broz18068bd2012-07-03 12:55:41 +010017 This is the type of the on-disk hash format.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010018
19 0 is the original format used in the Chromium OS.
Milan Broz18068bd2012-07-03 12:55:41 +010020 The salt is appended when hashing, digests are stored continuously and
Sami Tolvanena739ff32015-12-03 14:26:30 +000021 the rest of the block is padded with zeroes.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010022
23 1 is the current format that should be used for new devices.
Milan Broz18068bd2012-07-03 12:55:41 +010024 The salt is prepended when hashing and each digest is
Sami Tolvanena739ff32015-12-03 14:26:30 +000025 padded with zeroes to the power of two.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010026
27<dev>
Milan Broz18068bd2012-07-03 12:55:41 +010028 This is the device containing data, the integrity of which needs to be
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010029 checked. It may be specified as a path, like /dev/sdaX, or a device number,
30 <major>:<minor>.
31
32<hash_dev>
Milan Broz18068bd2012-07-03 12:55:41 +010033 This is the device that supplies the hash tree data. It may be
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010034 specified similarly to the device path and may be the same device. If the
Milan Broz18068bd2012-07-03 12:55:41 +010035 same device is used, the hash_start should be outside the configured
36 dm-verity device.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010037
38<data_block_size>
Milan Broz18068bd2012-07-03 12:55:41 +010039 The block size on a data device in bytes.
40 Each block corresponds to one digest on the hash device.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010041
42<hash_block_size>
Milan Broz18068bd2012-07-03 12:55:41 +010043 The size of a hash block in bytes.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +010044
45<num_data_blocks>
46 The number of data blocks on the data device. Additional blocks are
47 inaccessible. You can place hashes to the same partition as data, in this
48 case hashes are placed after <num_data_blocks>.
49
50<hash_start_block>
51 This is the offset, in <hash_block_size>-blocks, from the start of hash_dev
52 to the root block of the hash tree.
53
54<algorithm>
55 The cryptographic hash algorithm used for this device. This should
56 be the name of the algorithm, like "sha1".
57
58<digest>
59 The hexadecimal encoding of the cryptographic hash of the root hash block
60 and the salt. This hash should be trusted as there is no other authenticity
61 beyond this point.
62
63<salt>
64 The hexadecimal encoding of the salt value.
65
Sami Tolvanen65ff5b72015-03-18 15:52:14 +000066<#opt_params>
67 Number of optional parameters. If there are no optional parameters,
68 the optional paramaters section can be skipped or #opt_params can be zero.
69 Otherwise #opt_params is the number of following arguments.
70
71 Example of optional parameters section:
72 1 ignore_corruption
73
74ignore_corruption
75 Log corrupted blocks, but allow read operations to proceed normally.
76
77restart_on_corruption
78 Restart the system when a corrupted block is discovered. This option is
79 not compatible with ignore_corruption and requires user space support to
80 avoid restart loops.
81
Sami Tolvanena739ff32015-12-03 14:26:30 +000082use_fec_from_device <fec_dev>
83 Use forward error correction (FEC) to recover from corruption if hash
84 verification fails. Use encoding data from the specified device. This
85 may be the same device where data and hash blocks reside, in which case
86 fec_start must be outside data and hash areas.
87
88 If the encoding data covers additional metadata, it must be accessible
89 on the hash device after the hash blocks.
90
91 Note: block sizes for data and hash devices must match. Also, if the
92 verity <dev> is encrypted the <fec_dev> should be too.
93
94fec_roots <num>
95 Number of generator roots. This equals to the number of parity bytes in
96 the encoding data. For example, in RS(M, N) encoding, the number of roots
97 is M-N.
98
99fec_blocks <num>
100 The number of encoding data blocks on the FEC device. The block size for
101 the FEC device is <data_block_size>.
102
103fec_start <offset>
104 This is the offset, in <data_block_size> blocks, from the start of the
105 FEC device to the beginning of the encoding data.
106
107
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100108Theory of operation
109===================
110
Milan Broz18068bd2012-07-03 12:55:41 +0100111dm-verity is meant to be set up as part of a verified boot path. This
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100112may be anything ranging from a boot using tboot or trustedgrub to just
113booting from a known-good device (like a USB drive or CD).
114
115When a dm-verity device is configured, it is expected that the caller
116has been authenticated in some way (cryptographic signatures, etc).
117After instantiation, all hashes will be verified on-demand during
118disk access. If they cannot be verified up to the root node of the
Milan Broz18068bd2012-07-03 12:55:41 +0100119tree, the root hash, then the I/O will fail. This should detect
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100120tampering with any data on the device and the hash data.
121
122Cryptographic hashes are used to assert the integrity of the device on a
Milan Broz18068bd2012-07-03 12:55:41 +0100123per-block basis. This allows for a lightweight hash computation on first read
124into the page cache. Block hashes are stored linearly, aligned to the nearest
125block size.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100126
Sami Tolvanena739ff32015-12-03 14:26:30 +0000127If forward error correction (FEC) support is enabled any recovery of
128corrupted data will be verified using the cryptographic hash of the
129corresponding data. This is why combining error correction with
130integrity checking is essential.
131
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100132Hash Tree
133---------
134
135Each node in the tree is a cryptographic hash. If it is a leaf node, the hash
Milan Broz18068bd2012-07-03 12:55:41 +0100136of some data block on disk is calculated. If it is an intermediary node,
137the hash of a number of child nodes is calculated.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100138
139Each entry in the tree is a collection of neighboring nodes that fit in one
140block. The number is determined based on block_size and the size of the
141selected cryptographic digest algorithm. The hashes are linearly-ordered in
142this entry and any unaligned trailing space is ignored but included when
143calculating the parent node.
144
145The tree looks something like:
146
147alg = sha256, num_blocks = 32768, block_size = 4096
148
149 [ root ]
150 / . . . \
151 [entry_0] [entry_1]
152 / . . . \ . . . \
153 [entry_0_0] . . . [entry_0_127] . . . . [entry_1_127]
154 / ... \ / . . . \ / \
155 blk_0 ... blk_127 blk_16256 blk_16383 blk_32640 . . . blk_32767
156
157
158On-disk format
159==============
160
Milan Broz18068bd2012-07-03 12:55:41 +0100161The verity kernel code does not read the verity metadata on-disk header.
162It only reads the hash blocks which directly follow the header.
163It is expected that a user-space tool will verify the integrity of the
164verity header.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100165
Milan Broz18068bd2012-07-03 12:55:41 +0100166Alternatively, the header can be omitted and the dmsetup parameters can
167be passed via the kernel command-line in a rooted chain of trust where
168the command-line is verified.
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100169
170Directly following the header (and with sector number padded to the next hash
171block boundary) are the hash blocks which are stored a depth at a time
172(starting from the root), sorted in order of increasing index.
173
Milan Broz18068bd2012-07-03 12:55:41 +0100174The full specification of kernel parameters and on-disk metadata format
175is available at the cryptsetup project's wiki page
Milan Broze44f23b2015-04-05 18:03:10 +0200176 https://gitlab.com/cryptsetup/cryptsetup/wikis/DMVerity
Milan Broz18068bd2012-07-03 12:55:41 +0100177
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100178Status
179======
180V (for Valid) is returned if every check performed so far was valid.
181If any check failed, C (for Corruption) is returned.
182
183Example
184=======
Milan Broz18068bd2012-07-03 12:55:41 +0100185Set up a device:
186 # dmsetup create vroot --readonly --table \
187 "0 2097152 verity 1 /dev/sda1 /dev/sda2 4096 4096 262144 1 sha256 "\
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100188 "4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076 "\
189 "1234000000000000000000000000000000000000000000000000000000000000"
190
191A command line tool veritysetup is available to compute or verify
Milan Broz18068bd2012-07-03 12:55:41 +0100192the hash tree or activate the kernel device. This is available from
Milan Broze44f23b2015-04-05 18:03:10 +0200193the cryptsetup upstream repository https://gitlab.com/cryptsetup/cryptsetup/
Milan Broz18068bd2012-07-03 12:55:41 +0100194(as a libcryptsetup extension).
Mikulas Patockaa4ffc152012-03-28 18:43:38 +0100195
Milan Broz18068bd2012-07-03 12:55:41 +0100196Create hash on the device:
197 # veritysetup format /dev/sda1 /dev/sda2
198 ...
199 Root hash: 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076
200
201Activate the device:
202 # veritysetup create vroot /dev/sda1 /dev/sda2 \
203 4392712ba01368efdf14b05c76f9e4df0d53664630b5d48632ed17a137f39076