dm-integrity: integrity protection device-mapper target
Subsystems (5)
cover dm-integrity: integrity protection device-mapper target
Device-mapper "integrity" target provides transparent cryptographic integrity protection of underlying read-write block device using hash-based message authentication codes (HMACs), which can be stored on the same or different block device.
Target uses kernel keyring to obtain a secret key for using in cryptographic operations. It uses encrypted key type. Kernel never exposes those keys in plain form to user space. Encrypted keys are encrypted using master key, which can be either user or trusted type. User key type allows to supply a key from the user space and trusted key uses TPM.
Secret key is usually device specific and binds integrity data to the device. Data blocks and corresponding HMACs cannot be copied over from other systems.
The key advantage over dm-verity is that the target supports read-write and requires less hash calculation operations. The key advantage over dm-crypt is that it does not require encryption when it is not desired by technical or other reasons. HMAC calculation generally requires less resources than encryption.
The main purpose of the dm-integrity is to provide read-write capable local block data integrity protection without encryption.
I addressed all comments I got so far. Can it be now added to the DM tree?
- Dmitry
Dmitry Kasatkin (1):
dm-integrity: integrity protection device-mapper target
Documentation/device-mapper/dm-integrity.txt | 137 ++++ drivers/md/Kconfig | 13 + drivers/md/Makefile | 1 + drivers/md/dm-integrity.c | 1051 ++++++++++++++++++++++++++ 4 files changed, 1202 insertions(+) create mode 100644 Documentation/device-mapper/dm-integrity.txt create mode 100644 drivers/md/dm-integrity.c
Signature · 1 line
1.7.10.4
PATCH 1/1 dm-integrity: integrity protection device-mapper target
Device-mapper "integrity" target provides transparent cryptographic integrity protection of the underlying read-write block device using hash-based message authentication codes (HMACs). HMACs can be stored on the same or different block device.
dm-integrity uses an encrypted key type, stored on the kernel keyring, to obtain a secret key for use in cryptographic operations. Encrypted keys are never exposed in plain text to user space. The encrypted keys are encrypted using master key, which can either be a user defined or trusted key type. The secret key, which is usually device specific, binds integrity data to the device. As a result data blocks and corresponding HMACs cannot simply be copied over from other file systems.
--- Documentation/device-mapper/dm-integrity.txt | 137 ++++ drivers/md/Kconfig | 13 + drivers/md/Makefile | 1 + drivers/md/dm-integrity.c | 1051 ++++++++++++++++++++++++++ 4 files changed, 1202 insertions(+) create mode 100644 Documentation/device-mapper/dm-integrity.txt create mode 100644 drivers/md/dm-integrity.c
Documentation/device-mapper/dm-integrity.txt new file +137 -0
@@ -0,0 +1,137 @@ +dm-integrity +=============== + +Device-mapper "integrity" target provides transparent cryptographic integrity +protection of the underlying read-write block device using hash-based message +authentication codes (HMACs). HMACs can be stored on the same or different +block device. + +dm-integrity uses an encrypted key type, stored on the kernel keyring, to +obtain a secret key for use in cryptographic operations. Encrypted keys are +never exposed in plain text to user space. The encrypted keys are encrypted +using master key, which can either be a user defined or trusted key type. +The secret key, which is usually device specific, binds integrity data to the +device. As a result data blocks and corresponding HMACs cannot simply be +copied over from other file systems. + +Parameters: +<dev> <bs> <start> <hdev> <hbs> <hstart> <hash_algo> <hmac_algo> <key_desc> \ +[<opt_params>] + +<dev> + This is the device that is going to be used to store the data. + You can specify it as a path like /dev/xxx or a device <major>:<minor> + number. + +<bs> + Device block size. + +<start> + Starting sector within the device where data begins. + +<hdev> + This is the device that is going to be used to store integrity data. + You can specify it as a path like /dev/xxx or a device <major>:<minor> + number. + +<hbs> + HMAC device block size. + +<hstart> + Starting sector within the device where integrity data begins. + +<hash_algo> + Hash algorithm (sha1, sha256, etc). + +<hmac_algo> + HMAC algorithm, e.g. hmac(sha1), hmac(sha256), etc. + +<key_desc> + Description is a name of a key in the kernel keyring. + +<opt_params> + fix=1|0 - enable fix mode + In fix mode, incorrect hmacs are replaced with correct ones. + It is used for device initialization and debugging. + + stats=1|0 - turns on collecting additional statistical information. + It is used to find out resource usage to tune memory pool + and queue sizes for particular use case. + + verbose=1|0 - prints block number, collected hmac and stored hmac. + It is used for addition debug output. + + +Determine the size of integrity/hmac device +=============== + +Every block device has corresponding hmac. +While NIST does recommend to use sha256 hash algorithm instead of SHA1, +this does not apply to hmac(sha1), because of keying. It is safe to use +hmac(sha1), because it takes much less space and it is faster to calculate. +hmac(sha1) size is 20 bytes. So every 4k block on the integrity device can +store 204 hmacs. In order to get the required size of the integrity device, +it is necessary to divide data device size by 204. See examples bellow how +to do it from script. + +Example scripts +=============== + +1. Setting up integrity target using data and hmac store on the same block device. + +[[ +#!/bin/sh + +bdev=$1 + +# block device size +dsize=`blockdev --getsize $bdev` +# block size +bs=4096 +# sector to block shift +sbs=3 +# integrity record size (hmac size) +hmac=20 +# hmacs per block +hpb=$((bs/hmac)) +# target device size +size=$((((dsize>>sbs)*hpb/(hpb+1))<<sbs)) + +# load the key - in this example we just use test key +keyctl add user kmk "testing123" @u +keyctl add encrypted dm-int-key "load `cat /etc/keys/dm-int-key`" @u + +# creating the target +table="0 $size integrity $bdev 4096 0 $bdev 4096 $size sha1 hmac(sha1) dm-int-key" +dmsetup create dm-int --table "$table" + +# mounting +mount /dev/mapper/dm-int /mnt + +]] + +2. Setting up integrity target using data and hmac store on different block devices. + +[[ +#!/bin/sh + +bdev=$1 +hdev=$2 + +# get size of the block device +dsize=`blockdev --getsz $bdev` +# round down the size to 4k blocks +dsize=$((dsize & ~7)) + +# load the key - in this example we just use test key +keyctl add user kmk "testing123" @u +keyctl add encrypted dm-int-key "load `cat /etc/keys/dm-int-key`" @u + +# creating the target +table="0 $dsize integrity $bdev 4096 0 $hdev 4096 0 sha1 hmac(sha1) dm-int-key" +dmsetup create dm-int --table "$table" + +# mounting +mount /dev/mapper/dm-int /mnt + +]]
drivers/md/Kconfig +13 -0
@@ -388,6 +388,19 @@ config DM_VERITY To compile this code as a module, choose M here: the module will be called dm-verity. +config DM_INTEGRITY + tristate "Integrity target support" + depends on BLK_DEV_DM + select CRYPTO + select CRYPTO_HMAC + select DM_BUFIO + select KEYS + ---help--- + If you say Y here, then your ... + + To compile this as a module, choose M here: the module + will be called dm-integrity. + If unsure, say N. endif # MD
drivers/md/Makefile +1 -0
@@ -41,6 +41,7 @@ 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_ZERO) += dm-zero.o +obj-$(CONFIG_DM_INTEGRITY) += dm-integrity.o obj-$(CONFIG_DM_RAID) += dm-raid.o obj-$(CONFIG_DM_THIN_PROVISIONING) += dm-thin-pool.o obj-$(CONFIG_DM_VERITY) += dm-verity.o
drivers/md/dm-integrity.c new file +1051 -0
1,051 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Alasdair G Kergon
maintainerQuoted 1 line · Dmitry Kasatkin
I addressed all comments I got so far. Can it be now added to the DM tree?
Mikulas will review the latest version with this in mind.
Alasdair