Skip to contentSkip to conversation

dm-integrity: integrity protection device-mapper target

PATCH Superseded Dmitry Kasatkin 2 participants 6 messages Sep 24, 2012 – Sep 25, 2012

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover dm-integrity: integrity protection device-mapper target

There are two existing offline integrity models: file level integrity (linux-integrity subsystem EVM/IMA-appraisal) and block level integrity (dm-verity, dm-crypt).

This patch provides a new block level method called device-mapper "integrity" target (dm-integrity), which provides transparent cryptographic integrity protection of the underlying read-write block device using hash-based message authentication codes (HMACs). The 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.

EVM/IMA-appraisal provides file level integrity protection. The advantages are that it is policy based, file measurements are available for remote attestation, and files can be digitally signed to provide authenticity.

Both dm-verity and dm-crypt provide block level integrity protection. dm-verity provides block level integrity protection for read-only file systems, while dm-crypt provides block level integrity protection, with minimum penalty, for filesystems requiring full disk encryption.

dm-integrity provides a lighter weight read-write block level integrity protection for file systems not requiring full disk encryption, but which do require writability.

- Dmitry

Dmitry Kasatkin (1):
dm-integrity: integrity protection device-mapper target

 Documentation/device-mapper/dm-integrity.txt |  125 ++++
 drivers/md/Kconfig                           |   12 +
 drivers/md/Makefile                          |    1 +
 drivers/md/dm-integrity.c                    | 1019 ++++++++++++++++++++++++++
 4 files changed, 1157 insertions(+)
 create mode 100644 Documentation/device-mapper/dm-integrity.txt
 create mode 100644 drivers/md/dm-integrity.c
Signature · 1 line
1.7.9.5
#1 lore raw

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 |  125 ++++
 drivers/md/Kconfig                           |   12 +
 drivers/md/Makefile                          |    1 +
 drivers/md/dm-integrity.c                    | 1019 ++++++++++++++++++++++++++
 4 files changed, 1157 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 +125 -0
new file mode 100644
index 0000000..4e7404e
@@ -0,0 +1,125 @@
+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_path> <offset> <hdev_path> <hoffset> <hash_algo> <key_desc> [<opt_params>]
+
+<dev_path>
+    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.
+
+<offset>
+    Starting sector within the device where data begins.
+
+<hdev_path>
+    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.
+
+<hoffset>
+    Starting sector within the device where integrity data begins.
+
+<hash_algo>
+    Hash algorithm (sha1, 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 testing.
+
+    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.
+    
+
+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.
+This target uses HMAC(SHA1), because it takes much less space and it is
+faster to calculate. There is no parameter to change hmac hash algorithm.
+
+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
+dmsetup create dm-int --table "0 $size integrity $bdev 0 $bdev $size sha1 dm-int-key"
+
+# 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
+dmsetup create dm-int --table "0 $dsize integrity $bdev 0 $hdev 0 hmac(sha1) dm-int-key"
+
+# mounting
+mount /dev/mapper/dm-int /mnt
+
+]]
drivers/md/Kconfig +12 -0
index d949b78..078bc91 100644
@@ -380,6 +380,18 @@ 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
+	---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
index 8b2e0df..ee546f3 100644
@@ -40,6 +40,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 +1019 -0

1,019 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw
In reply to Dmitry Kasatkin
Quoted 1 line · Dmitry Kasatkin

Both dm-verity and dm-crypt provide block level integrity protection.

This is not correct. dm-crypt is transparent block encryption target, where always size of plaintext == size of ciphertext.

So it can provide confidentiality but it CANNOT provide integrity protection.

We need extra space to store auth tag which dmcrypt cannot provide currently.

Quoted 3 lines

dm-integrity provides a lighter weight read-write block level integrity protection for file systems not requiring full disk encryption, but which do require writability.

Obvious question: can be dm-verity extended to provide read-write integrity?

I would prefer to use standard mode like GCM to provide both encryption and integrity protection than inventing something new.

Milan

#3 lore raw
Quoted 6 lines · Milan Broz
Quoted 1 line · Dmitry Kasatkin

Both dm-verity and dm-crypt provide block level integrity protection.

This is not correct. dm-crypt is transparent block encryption target, where always size of plaintext == size of ciphertext.

Of course... It is just said in relation to integrity protection. It is said about encryption in following paragraphs...

Quoted 2 lines

So it can provide confidentiality but it CANNOT provide integrity protection.

Yes, it provides confidentiality and via encryption it provides certain level of integrity protection.
Data cannot be modified without being detected. Decryption will result in garbage...

Quoted 8 lines

We need extra space to store auth tag which dmcrypt cannot provide currently.

Quoted 3 lines

dm-integrity provides a lighter weight read-write block level integrity protection for file systems not requiring full disk encryption, but which do require writability.

Obvious question: can be dm-verity extended to provide read-write integrity?

I think re-calculating hash trees all the time and syncing block hashes and tree itself
is heavier operation...

Quoted 2 lines

I would prefer to use standard mode like GCM to provide both encryption and integrity protection than inventing something new.

As said, if encryption is considered heavy operation in term of CPU and battery usage
and also if encryption is not desired for some reasons that would be an option.

- Dmitry

Quoted 2 lines

Milan

#4 lore raw
Quoted 6 lines · Dmitry
Quoted 2 lines

So it can provide confidentiality but it CANNOT provide integrity protection.

Yes, it provides confidentiality and via encryption it provides certain level of integrity protection.
Data cannot be modified without being detected. Decryption will result in garbage...

It should, but it is not cryptographic integrity protection. Moreover, you can revert ciphertext sector content.

Btw I think dm-integrity doesn't solve the reply problem as well.

(IOW can you replace/revert both data and hash, still using the same key in keyring, without dm-integrity able to detect it?)

In dm-verity, root hash will change after such data tampering.

Quoted 5 lines
Quoted 2 lines

Obvious question: can be dm-verity extended to provide read-write integrity?

I think re-calculating hash trees all the time and syncing block hashes and tree itself is heavier operation...

Then why not extend dm-verity to use you hash format? There are options for that and we can redefine table line if necessary.

(You are duplicating a lot of code here otherwise, not counting userspace yet.)

Whatever, I shortly read the code and have some notes.

First, device-mapper is variable system, you can stack devices in arbitrary order.

Unfortunately, this is something what can be dangerous in crypto, here you can e.g.
- do mac (integrity) then encrypt
- do encrypt, then check integrity

In many implementations mac-then-encrypt system was not secure. Are we sure that it cannot provide side channels here?

Note read-only integrity target (like dm-verity) is specific case, you should not be able to run any chosen ciphertext attacks here, it is read-only device.

In fact, I am not sure if we should provide separate read-write block integrity (wihtout encryption) target at all.

Either it should use standard mode of authenticated encryption (like GCM) or data integrity should be upper layer business (which knows better which data really need integrity checking and which areas are just unused garbage. If you consider hashing and encryption as "heavy operation" you should minimize it to only really used area - and only upper layer know about real used data content.)

(Again, this is different for read-only target, where it usually uses compressed RO fs image which uses all available space.)

1) discards
It seems the dm-integrity target doesn't solve problem with discards.

If you send discard request to underlying device, data content of discarded area is undefined (or zeroed if discards zeroes data) but is is definitely "invalid" form the dm-integrity point of view. And you are allowing discard IOs there.

I am not sure what should happen, but the behaviour should be documented (at least) or disabled.

2)
All used hash algorithms must be configurable.

From your doc:

+While NIST does recommend to use SHA256 hash algorithm instead of SHA1, +this does not apply to HMAC(SHA1), because of keying.
+This target uses HMAC(SHA1), because it takes much less space and it is +faster to calculate. There is no parameter to change hmac hash algorithm.

While this is technically true, http://csrc.nist.gov/groups/ST/hash/policy.html
disallowing use of another hash algorithm is wrong, and in fact it is regression in comparison with dm-verity (which already implements all needed calculations and uses hash name as table line option).

+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.

Why are you hardcoding block and hash sizes?
Again, dm-verity have this configurable with some good default.

ditto for kernel keyring:
+ const char *hmac_algo = "hmac(sha1)"; /* uncompromized yet */

3)
I like that this target can use kernel keyring, in fact, we should implement similar option to dm crypt/verity. But the target should not be limited to use TPM keys only.
(And key is stored directly in kernel memory later for hash calculation anyway allowing hw attacks reading it from RAM.)

4)
reboot notifier cannot be used this way in generic storage stacking IMHO, but I think there was discussion with Mikulas already
http://www.redhat.com/archives/dm-devel/2012-March/msg00164.html

5)
output target table should not translate device to device symbolic names

Anyway, code can be changed. But the high level questions remains...

Milan

#5 lore raw
Quoted 10 lines · Milan Broz
Quoted 6 lines · Dmitry
Quoted 2 lines

So it can provide confidentiality but it CANNOT provide integrity protection.

Yes, it provides confidentiality and via encryption it provides certain level of integrity protection.
Data cannot be modified without being detected. Decryption will result in garbage...

Quoted 7 lines

It should, but it is not cryptographic integrity protection. Moreover, you can revert ciphertext sector content.

Btw I think dm-integrity doesn't solve the reply problem as well.

(IOW can you replace/revert both data and hash, still using the same key in keyring, without dm-integrity able to detect it?)

Yes, reply problem is the same. It is context free.

Quoted 3 lines

In dm-verity, root hash will change after such data tampering.

yes, I know.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Obvious question: can be dm-verity extended to provide read-write integrity?

I think re-calculating hash trees all the time and syncing block hashes and tree itself is heavier operation...

Then why not extend dm-verity to use you hash format? There are options for that and we can redefine table line if necessary.

dm-integrity does not use hash tree.
switching tree to hmac needs to recalculating everything. It simply does not make sense.

Quoted 2 lines

(You are duplicating a lot of code here otherwise, not counting userspace yet.)

All targets have similarities here and there.
At the end they work in different way.
From source code point of it is clearer to keep them separately as they do things in different way.

It does not require any user space tools.

Quoted 17 lines

Whatever, I shortly read the code and have some notes.

First, device-mapper is variable system, you can stack devices in arbitrary order.

Unfortunately, this is something what can be dangerous in crypto, here you can e.g.
- do mac (integrity) then encrypt
- do encrypt, then check integrity

In many implementations mac-then-encrypt system was not secure. Are we sure that it cannot provide side channels here?

Note read-only integrity target (like dm-verity) is specific case, you should not be able to run any chosen ciphertext attacks here, it is read-only device.

In fact, I am not sure if we should provide separate read-write block integrity (wihtout encryption) target at all.

Quoted 9 lines

Either it should use standard mode of authenticated encryption (like GCM) or data integrity should be upper layer business (which knows better which data really need integrity checking and which areas are just unused garbage. If you consider hashing and encryption as "heavy operation" you should minimize it to only really used area - and only upper layer know about real used data content.)

(Again, this is different for read-only target, where it usually uses compressed RO fs image which uses all available space.)

Again, as it is written in cover letter.
It can be used for certain use cases, which does not want encryption for performance
or data transforming reasons...

Quoted 8 lines

1) discards
It seems the dm-integrity target doesn't solve problem with discards.

If you send discard request to underlying device, data content of discarded area is undefined (or zeroed if discards zeroes data) but is is definitely "invalid" form the dm-integrity point of view. And you are allowing discard IOs there.

I will check about it.

Quoted 6 lines

I am not sure what should happen, but the behaviour should be documented (at least) or disabled.

2)
All used hash algorithms must be configurable.

dm-integrity uses HASH and HMAC together for HW enabling reasons... Hash is calculated using async API and HMAC is sync.

Hash algorithm is configurable. There is a target parameter for that

<dev_path> <offset> <hdev_path> <hoffset> <hash_algo> <key_desc> [<opt_params>]

HMAC is different...
Because of using key, hmac(sha1) is not vulnerable to attacks as sha1... There is currently absolutely no reason to use hmac(sha256) or other. hmac(sha1) is absolutely enough...

Before I used only sync API and it was a parameter for hmac only. Now there is hash only parameter..

But this is not an issue. I could easily have a parameter for hmac..

Quoted 13 lines

From your doc:

(quoted diff) +4 -0
+While NIST does recommend to use SHA256 hash algorithm instead of SHA1,
+this does not apply to HMAC(SHA1), because of keying.
+This target uses HMAC(SHA1), because it takes much less space and it is
+faster to calculate. There is no parameter to change hmac hash algorithm.

While this is technically true, http://csrc.nist.gov/groups/ST/hash/policy.html
disallowing use of another hash algorithm is wrong, and in fact it is regression in comparison with dm-verity (which already implements all needed calculations and uses hash name as table line option).

Review

Quoted 3 lines
(quoted diff) +3 -0
+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.

This is just an example to understand space requirements Documentation/device-mapper/dm-integrity.txt has scripts examples how to enable target.
No user space tools are required...

Quoted 3 lines

Why are you hardcoding block and hash sizes?
Again, dm-verity have this configurable with some good default.

I do not hard-code hash sized...
there are:
crypto_shash_digestsize(dmi->hmac);
crypto_ahash_digestsize(dmi->ahash)

Yes... block size is hard coded..
Did not use other then 4k.

Quoted 3 lines

ditto for kernel keyring:
+ const char *hmac_algo = "hmac(sha1)"; /* uncompromized yet */

Explained above...

Quoted 6 lines

3)
I like that this target can use kernel keyring, in fact, we should implement similar option to dm crypt/verity. But the target should not be limited to use TPM keys only.
(And key is stored directly in kernel memory later for hash calculation anyway allowing hw attacks reading it from RAM.)

No... It is not limited to TPM....
Encrypted keys use either user master key or TPM to encrypt the key...

Kernel keyring keeps keys in the memory..
And dm-crypt also keeps key in the memory. Right?

Quoted 6 lines

4)
reboot notifier cannot be used this way in generic storage stacking IMHO, but I think there was discussion with Mikulas already
http://www.redhat.com/archives/dm-devel/2012-March/msg00164.html

Yes. I had a question..

reboot norifier is a last resort here...
file system first is remount "RO"... and flushed..
And then dm-integrity will also need to write buffers to the storage...

Are there better way?

Quoted 2 lines

5)
output target table should not translate device to device symbolic names

I thought so as well when last time looked to that.

Quoted 3 lines

Anyway, code can be changed. But the high level questions remains...

Block size parameter might be easily added. Just did not use other then page size.

Based on my clarifications about hash and hmac do you still think that hmac(sha1) should also be configurable?

Thanks,
Dmitry

Quoted 1 line

Milan