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