Skip to contentSkip to conversation

dm: verity target

PATCH New Mandeep Singh Baines 1 participant 1 message Dec 22, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm: verity target

The verity target provides transparent integrity checking of block devices using a cryptographic digest.

dm-verity is meant to be setup as part of a verified boot path. This may be anything ranging from a boot using tboot or trustedgrub to just booting from a known-good device (like a USB drive or CD).

dm-verity is part of ChromeOS's verified boot path. It is used to verify the integrity of the root filesystem on boot. The root filesystem is mounted on a dm-verity partition which transparently verifies each block with a bootloader verified hash passed into the kernel at boot.

---
 Documentation/device-mapper/dm-bht.txt    |   59 ++
 Documentation/device-mapper/dm-verity.txt |   76 +++
 drivers/md/Kconfig                        |   30 +
 drivers/md/Makefile                       |    2 +
 drivers/md/dm-bht.c                       |  559 +++++++++++++++
 drivers/md/dm-verity.c                    | 1043 +++++++++++++++++++++++++++++
 drivers/md/dm-verity.h                    |   45 ++
 include/linux/dm-bht.h                    |  166 +++++
 8 files changed, 1980 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/device-mapper/dm-bht.txt
 create mode 100644 Documentation/device-mapper/dm-verity.txt
 create mode 100644 drivers/md/dm-bht.c
 create mode 100644 drivers/md/dm-verity.c
 create mode 100644 drivers/md/dm-verity.h
 create mode 100644 include/linux/dm-bht.h
Documentation/device-mapper/dm-bht.txt new file +59 -0
new file mode 100644
index 0000000..21d929f
@@ -0,0 +1,59 @@
+dm-bht
+======
+
+dm-bht provides a block hash tree implementation.  The use of dm-bht allows
+for integrity checking of a given block device without reading the entire
+set of blocks into memory before use.
+
+In particular, dm-bht supplies an interface for creating and verifying a tree
+of cryptographic digests with any algorithm supported by the kernel crypto API.
+
+The `verity' target is the motivating example.
+
+
+Theory of operation
+===================
+
+dm-bht is logically comprised of multiple nodes organized in a tree-like
+structure.  Each node in the tree is a cryptographic hash.  If it is a leaf
+node, the hash is of some block data on disk.  If it is an intermediary node,
+then the hash is of a number of child nodes.
+
+dm-bht has a given depth starting at 1 (ignoring the root node).  Each level in
+the tree is concretely made up of dm_bht_entry structs.  Each entry in the tree
+is a collection of neighboring nodes that fit in one page-sized block.  The
+number is determined based on PAGE_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.
+
+The tree looks something like:
+
+alg= sha256, num_blocks = 32767
+                                 [   root    ]
+                                /    . . .    \
+                     [entry_0]                 [entry_1]
+                    /  . . .  \                 . . .   \
+         [entry_0_0]   . . .  [entry_0_127]    . . . .  [entry_1_127]
+           / ... \             /   . . .  \             /           \
+     blk_0 ... blk_127  blk_16256   blk_16383      blk_32640 . . . blk_32767
+
+root is treated independently from the depth and the blocks are expected to
+be hashed and supplied to the dm-bht.  hash blocks that make up the entry
+contents are expected to be read from disk.
+
+dm-bht does not handle I/O directly but instead expects the consumer to
+supply callbacks.  The read callback will always receive a page-align value
+to pass to the block device layer to read in a hash value.
+
+Usage
+=====
+
+The API provides mechanisms for reading and verifying a tree. When reading, all
+required data for the hash tree should be populated for a block before
+attempting a verify.  This can be done by calling dm_bht_populate().  When all
+data is ready, a call to dm_bht_verify_block() with the expected hash value will
+perform both the direct block hash check and the hashes of the parent and
+neighboring nodes where needed to ensure validity up to the root hash.  Note,
+dm_bht_set_root_hexdigest() should be called before any verification attempts
+occur.
Documentation/device-mapper/dm-verity.txt new file +76 -0

76 lines not on this page · raw message

drivers/md/Kconfig +30 -0
index faa4741..3cdf95c 100644
@@ -370,4 +370,34 @@ config DM_FLAKEY
        ---help---
          A target that intermittently fails I/O for debugging purposes.
 
+config DM_BHT
+        tristate "Block hash tree support"
+        select CRYPTO
+        select CRYPTO_HASH
+        ---help---
+          Include support for device-mapper devices to use a block hash
+          tree for managing data integrity checks in a scalable way.
+
+          Targets that use this functionality should include it
+          automatically.
+
+          If unsure, say N.
+
+config DM_VERITY
+        tristate "Verity target support"
+        depends on BLK_DEV_DM
+        select DM_BHT
+        select CRYPTO
+        select CRYPTO_HASH
+        ---help---
+          This device-mapper target allows you to create a device that
+          transparently integrity checks the data on it. You'll need to
+          activate the digests you're going to use in the cryptoapi
+          configuration.
+
+          To compile this code as a module, choose M here: the module will
+          be called dm-verity.
+
+          If unsure, say N.
+
 endif # MD
drivers/md/Makefile +2 -0
index 046860c..c069953 100644
@@ -39,6 +39,8 @@ obj-$(CONFIG_DM_SNAPSHOT)	+= dm-snapshot.o
 obj-$(CONFIG_DM_PERSISTENT_DATA)	+= persistent-data/
 obj-$(CONFIG_DM_MIRROR)		+= dm-mirror.o dm-log.o dm-region-hash.o
 obj-$(CONFIG_DM_LOG_USERSPACE)	+= dm-log-userspace.o
+obj-$(CONFIG_DM_BHT)            += dm-bht.o
+obj-$(CONFIG_DM_VERITY)         += dm-verity.o
 obj-$(CONFIG_DM_ZERO)		+= dm-zero.o
 obj-$(CONFIG_DM_RAID)	+= dm-raid.o
 obj-$(CONFIG_DM_THIN_PROVISIONING)	+= dm-thin-pool.o
drivers/md/dm-bht.c new file +559 -0

559 lines not on this page · raw message

drivers/md/dm-verity.c new file +1043 -0

1,043 lines not on this page · raw message

drivers/md/dm-verity.h new file +45 -0

45 lines not on this page · raw message

include/linux/dm-bht.h new file +166 -0

166 lines not on this page · raw message

Signature · 1 line
1.7.3.1