Skip to contentSkip to conversation

Add dm verity root hash pkcs7 sig validation.

RFC PATCH Superseded Jaskaran Khurana 2 participants 6 messages Jul 1, 2019 – Jul 17, 2019 1 message not in the archive

Subsystems (6)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover Add dm verity root hash pkcs7 sig validation.

Changes in v6:

Address comments from Milan Broz and Eric Biggers on v5.

-Keep the verification code under config DM_VERITY_VERIFY_ROOTHASH_SIG.

-Change the command line parameter to requires_signatures(bool) which will force root hash to be signed and trusted if specified.

-Fix the signature not being present in verity_status. Merged the
https://git.kernel.org/pub/scm/linux/kernel/git/mbroz/linux.git/commit/?h=dm-cryptsetup&id=a26c10806f5257e255b6a436713127e762935ad3
made by Milan Broz and tested it.

Jaskaran Khurana (1):
Add dm verity root hash pkcs7 sig validation.

 Documentation/device-mapper/verity.txt |   7 ++
 drivers/md/Kconfig                     |  12 +++
 drivers/md/Makefile                    |   5 +
 drivers/md/dm-verity-target.c          |  43 +++++++-
 drivers/md/dm-verity-verify-sig.c      | 133 +++++++++++++++++++++++++
 drivers/md/dm-verity-verify-sig.h      |  60 +++++++++++
 drivers/md/dm-verity.h                 |   2 +
 7 files changed, 257 insertions(+), 5 deletions(-)
 create mode 100644 drivers/md/dm-verity-verify-sig.c
 create mode 100644 drivers/md/dm-verity-verify-sig.h
Signature · 1 line
2.17.1
#1 lore raw

RFC PATCH v6 1/1 Add dm verity root hash pkcs7 sig validation.

The verification is to support cases where the roothash is not secured by Trusted Boot, UEFI Secureboot or similar technologies.
One of the use cases for this is for dm-verity volumes mounted after boot, the root hash provided during the creation of the dm-verity volume has to be secure and thus in-kernel validation implemented here will be used before we trust the root hash and allow the block device to be created.

The signature being provided for verification must verify the root hash and must be trusted by the builtin keyring for verification to succeed.

The hash is added as a key of type "user" and the description is passed to the kernel so it can look it up and use it for verification.

Adds CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG which can be turned on if root hash verification is needed.

Kernel commandline parameter require_signatures will indicate whether to force (for all dm verity volumes) roothash signature verification.

---
 Documentation/device-mapper/verity.txt |   7 ++
 drivers/md/Kconfig                     |  12 +++
 drivers/md/Makefile                    |   5 +
 drivers/md/dm-verity-target.c          |  43 +++++++-
 drivers/md/dm-verity-verify-sig.c      | 133 +++++++++++++++++++++++++
 drivers/md/dm-verity-verify-sig.h      |  60 +++++++++++
 drivers/md/dm-verity.h                 |   2 +
 7 files changed, 257 insertions(+), 5 deletions(-)
 create mode 100644 drivers/md/dm-verity-verify-sig.c
 create mode 100644 drivers/md/dm-verity-verify-sig.h
Documentation/device-mapper/verity.txt +7 -0
index b3d2e4a42255..df7ef1d553cc 100644
@@ -121,6 +121,13 @@ check_at_most_once
     blocks, and a hash block will not be verified any more after all the data
     blocks it covers have been verified anyway.
 
+root_hash_sig_key_desc <key_description>
+    This is the description of the USER_KEY that the kernel will lookup to get
+    the pkcs7 signature of the roothash. The pkcs7 signature is used to validate
+    the root hash during the creation of the device mapper block device.
+    Verification of roothash depends on the config DM_VERITY_VERIFY_ROOTHASH_SIG
+    being set in the kernel.
+
 Theory of operation
 ===================
 
drivers/md/Kconfig +12 -0
index db269a348b20..9d0bc609582c 100644
@@ -489,6 +489,18 @@ config DM_VERITY
 
 	  If unsure, say N.
 
+config DM_VERITY_VERIFY_ROOTHASH_SIG
+	def_bool n
+	bool "Verity data device root hash signature verification support"
+	depends on DM_VERITY
+	select SYSTEM_DATA_VERIFICATION
+	  help
+	  The device mapper target created by DM-VERITY can be validated if the
+	  pre-generated tree of cryptographic checksums passed has a pkcs#7
+	  signature file that can validate the roothash of the tree.
+
+	  If unsure, say N.
+
 config DM_VERITY_FEC
 	bool "Verity forward error correction support"
 	depends on DM_VERITY
drivers/md/Makefile +5 -0
index be7a6eb92abc..fe756c0dca14 100644
@@ -81,3 +81,8 @@ endif
 ifeq ($(CONFIG_DM_VERITY_FEC),y)
 dm-verity-objs			+= dm-verity-fec.o
 endif
+
+ifeq ($(CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG),y)
+dm-verity-objs			+= dm-verity-verify-sig.o
+endif
+
drivers/md/dm-verity-target.c +38 -5

128 lines not on this page · raw message

drivers/md/dm-verity-verify-sig.c new file +133 -0

133 lines not on this page · raw message

drivers/md/dm-verity-verify-sig.h new file +60 -0

60 lines not on this page · raw message

drivers/md/dm-verity.h +2 -0
index 3441c10b840c..42183a3903ae 100644
@@ -64,6 +64,8 @@ struct dm_verity {
 
 	struct dm_verity_fec *fec;	/* forward error correction */
 	unsigned long *validated_blocks; /* bitset blocks validated */
+
+	char *signature_key_desc; /* signature keyring reference */
 };
 
 struct dm_verity_io {
Signature · 1 line
2.17.1

A message that is not in the archive (sent off-list or not yet received): MN2PR21MB12008A962D4DD8662B3614508AF20@MN2PR21MB1200.namprd21.prod.outlook.com

#3 lore raw

Hello Milan,

Quoted 9 lines

Changes in v6:

Address comments from Milan Broz and Eric Biggers on v5.

(quoted diff) +0 -2
-Keep the verification code under config DM_VERITY_VERIFY_ROOTHASH_SIG.
 
-Change the command line parameter to requires_signatures(bool) which will

force root hash to be signed and trusted if specified.

Quoted 5 lines

-Fix the signature not being present in verity_status. Merged the
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fmbroz%2Flinux.git%2Fcommit%2F%3Fh%3Ddm-cryptsetup%26id%3Da26c10806f5257e255b6a436713127e762935ad3&amp;data=02%7C01%7CJaskaran.Khurana%40microsoft.com%7C18f92445e46940aeebb008d6fe50c610%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636976020210890638&amp;sdata=aY0V9%2FBz2RHryIvoftGKUGnyPp9Fsc1JY4FZbHfW4hg%3D&amp;reserved=0
made by Milan Broz and tested it.

Could you please provide feedback on this v6 version.

Regards,
Jaskaran

#4 lore raw
Quoted 12 lines · Jaskaran Singh Khurana

Hello Milan,

Quoted 9 lines

Changes in v6:

Address comments from Milan Broz and Eric Biggers on v5.

(quoted diff) +0 -2
-Keep the verification code under config DM_VERITY_VERIFY_ROOTHASH_SIG.
 
-Change the command line parameter to requires_signatures(bool) which will

force root hash to be signed and trusted if specified.

Quoted 7 lines
Quoted 5 lines

-Fix the signature not being present in verity_status. Merged the
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fmbroz%2Flinux.git%2Fcommit%2F%3Fh%3Ddm-cryptsetup%26id%3Da26c10806f5257e255b6a436713127e762935ad3&amp;data=02%7C01%7CJaskaran.Khurana%40microsoft.com%7C18f92445e46940aeebb008d6fe50c610%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636976020210890638&amp;sdata=aY0V9%2FBz2RHryIvoftGKUGnyPp9Fsc1JY4FZbHfW4hg%3D&amp;reserved=0
made by Milan Broz and tested it.

Could you please provide feedback on this v6 version.

Hi,

I am ok with the v6 patch; I think Mike will return to it in 5.4 reviews.

But the documentation is very brief. I spent quite a long time to configure the system properly.
I think you should add more description (at least to patch header) how to use this feature in combination with system keyring.

Do I understand correctly that these steps need to be done?

- user configures a certificate and adds it in kernel builtin keyring (I used CONFIG_SYSTEM_TRUSTED_KEYS option).
- the dm-verity device root hash is signed directly by a key of this cert
- the signature is uploaded to the user keyring
- reference to signature in keyring is added as an optional dm-verity table parameter root_hash_sig_key_desc
- optionally, require_signatures dm-verity module is set to enforce signatures.

For reference, below is the bash script I used (with unpatched veritysetup to generate working DM table), is the expected workflow here?

#!/bin/bash

NAME=test
DEV=/dev/sdc
DEV_HASH=/dev/sdd ROOT_HASH=778fccab393842688c9af89cfd0c5cde69377cbe21ed439109ec856f2aa8a423 SIGN=sign.txt
SIGN_NAME=verity:$NAME

# get unsigned device-mapper table using unpatched veritysetup
veritysetup open $DEV $NAME $DEV_HASH $ROOT_HASH
TABLE=$(dmsetup table $NAME)
veritysetup close $NAME

# Generate self-signed CA key, must be in .config as CONFIG_SYSTEM_TRUSTED_KEYS="path/ca.pem" #openssl req -x509 -newkey rsa:1024 -keyout ca_key.pem -out ca.pem -nodes -days 365 -set_serial 01 -subj /CN=example.com

# sign root hash directly by CA cert
echo -n $ROOT_HASH | openssl smime -sign -nocerts -noattr -binary -inkey ca_key.pem -signer ca.pem -outform der -out $SIGN
# load signature to keyring
keyctl padd user $SIGN_NAME @u <$SIGN
# add device-mapper table, now with sighed root hash optional argument
dmsetup create -r $NAME --table "$TABLE 2 root_hash_sig_key_desc $SIGN_NAME"
dmsetup table $NAME
# cleanup
dmsetup remove $NAME
keyctl clear @u

Milan

#5 lore raw

Hello Milan,

Quoted 21 lines · Milan Broz
Quoted 12 lines · Jaskaran Singh Khurana

Hello Milan,

Quoted 9 lines

Changes in v6:

Address comments from Milan Broz and Eric Biggers on v5.

(quoted diff) +0 -2
-Keep the verification code under config DM_VERITY_VERIFY_ROOTHASH_SIG.
 
-Change the command line parameter to requires_signatures(bool) which will

force root hash to be signed and trusted if specified.

Quoted 7 lines
Quoted 5 lines

-Fix the signature not being present in verity_status. Merged the
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fmbroz%2Flinux.git%2Fcommit%2F%3Fh%3Ddm-cryptsetup%26id%3Da26c10806f5257e255b6a436713127e762935ad3&amp;data=02%7C01%7CJaskaran.Khurana%40microsoft.com%7C18f92445e46940aeebb008d6fe50c610%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636976020210890638&amp;sdata=aY0V9%2FBz2RHryIvoftGKUGnyPp9Fsc1JY4FZbHfW4hg%3D&amp;reserved=0
made by Milan Broz and tested it.

Could you please provide feedback on this v6 version.

Quoted 4 lines

Hi,

I am ok with the v6 patch; I think Mike will return to it in 5.4 reviews.

Thanks for the help and also for reviewing this patch. Could you please add Reviewed-by/Tested-by tag to the patch.

Quoted 3 lines

But the documentation is very brief. I spent quite a long time to configure the system properly.
I think you should add more description (at least to patch header) how to use this feature in combination with system keyring.

I will add more documentation to the patch header describing the steps required for setup.

Quoted 9 lines

Do I understand correctly that these steps need to be done?

- user configures a certificate and adds it in kernel builtin keyring (I used CONFIG_SYSTEM_TRUSTED_KEYS option).
- the dm-verity device root hash is signed directly by a key of this cert
- the signature is uploaded to the user keyring
- reference to signature in keyring is added as an optional dm-verity table parameter root_hash_sig_key_desc
- optionally, require_signatures dm-verity module is set to enforce signatures.

For reference, below is the bash script I used (with unpatched veritysetup to generate working DM table), is the expected workflow here?

The steps and workflow is correct. I will send the cryptsetup changes for review.

Quoted 24 lines

#!/bin/bash

NAME=test
DEV=/dev/sdc
DEV_HASH=/dev/sdd ROOT_HASH=778fccab393842688c9af89cfd0c5cde69377cbe21ed439109ec856f2aa8a423 SIGN=sign.txt
SIGN_NAME=verity:$NAME

# get unsigned device-mapper table using unpatched veritysetup
veritysetup open $DEV $NAME $DEV_HASH $ROOT_HASH
TABLE=$(dmsetup table $NAME)
veritysetup close $NAME

# Generate self-signed CA key, must be in .config as CONFIG_SYSTEM_TRUSTED_KEYS="path/ca.pem" #openssl req -x509 -newkey rsa:1024 -keyout ca_key.pem -out ca.pem -nodes -days 365 -set_serial 01 -subj /CN=example.com

# sign root hash directly by CA cert
echo -n $ROOT_HASH | openssl smime -sign -nocerts -noattr -binary -inkey ca_key.pem -signer ca.pem -outform der -out $SIGN
# load signature to keyring
keyctl padd user $SIGN_NAME @u <$SIGN
Quoted 9 lines
# add device-mapper table, now with sighed root hash optional argument
dmsetup create -r $NAME --table "$TABLE 2 root_hash_sig_key_desc $SIGN_NAME"
dmsetup table $NAME
# cleanup
dmsetup remove $NAME
keyctl clear @u

Thanks for testing the changes and all the guidance here.

Quoted 2 lines

Milan

Regards,
Jaskaran.

#6 lore raw

Hi,

Quoted 9 lines · Jaskaran Singh Khurana
Quoted 6 lines
Quoted 1 line

Could you please provide feedback on this v6 version.

Hi,

I am ok with the v6 patch; I think Mike will return to it in 5.4 reviews.

Thanks for the help and also for reviewing this patch. Could you please add Reviewed-by/Tested-by tag to the patch.

ok, you can add

Tested-and-Reviewed-by Milan Broz <[email protected]>

or just use the version on my git, I already updated few lines because of recent kernel changes, mainly the revert of keyring changes, tested patch is here

https://git.kernel.org/pub/scm/linux/kernel/git/mbroz/linux.git/commit/?h=dm-cryptsetup&id=266f7c9c74b23e4cb2e67ceb813dd707061c1641
...

Quoted 2 lines

The steps and workflow is correct. I will send the cryptsetup changes for review.

ok, I'll probably try to use our existing userspace libcryptsetup API to avoid introducing new calls, but that is not important for now - the kernel bits must be in the mainline kernel first.

Thanks,
Milan