TPM 2.0 trusted key rework
Subsystems (7)
James Bottomley
maintainerv11 cover TPM 2.0 trusted key rework
As requested this is the patch set to make the TPM 2.0 trusted key infrastructure use the same ASN.1 format as the external key tools. The addition of the policy use cases has been broken out into a separate patch. The new code here is adding a description of the ASN.1 key format to trusted-encrypted.rst.
General cover letter minus policy bit:
This patch updates the trusted key code to export keys in the ASN.1 format used by current TPM key tools (openssl_tpm2_engine and openconnect). The current code will try to load keys containing policy, but being unable to formulate the policy commands necessary to load them, the unseal will always fail unless the policy is executed in user space and a pre-formed policy session passed in.
The key format is designed to be compatible with our two openssl engine implementations as well as with the format used by openconnect. I've added seal/unseal to my engine so I can use it for interoperability testing and I'll later use this for sealed symmetric keys via engine:
https://git.kernel.org/pub/scm/linux/kernel/git/jejb/openssl_tpm2_engine.git/
James
---
James Bottomley (5):
lib: add ASN.1 encoder
oid_registry: Add TCG defined OIDS for TPM keys
security: keys: trusted: fix TPM2 authorizations
security: keys: trusted: use ASN.1 TPM2 key format for the blobs
security: keys: trusted: Make sealed key properly interoperable
.../security/keys/trusted-encrypted.rst | 58 +++ include/keys/trusted-type.h | 2 + include/linux/asn1_encoder.h | 32 ++ include/linux/oid_registry.h | 5 + include/linux/tpm.h | 2 + lib/Kconfig | 3 + lib/Makefile | 1 + lib/asn1_encoder.c | 454 ++++++++++++++++++ security/keys/Kconfig | 1 + security/keys/trusted-keys/Makefile | 2 +- security/keys/trusted-keys/tpm2key.asn1 | 11 + security/keys/trusted-keys/trusted_tpm1.c | 34 +- security/keys/trusted-keys/trusted_tpm2.c | 266 +++++++++- 13 files changed, 840 insertions(+), 31 deletions(-) create mode 100644 include/linux/asn1_encoder.h create mode 100644 lib/asn1_encoder.c create mode 100644 security/keys/trusted-keys/tpm2key.asn1
Signature · 1 line
2.26.2
James Bottomley
maintainerPATCH v11 1/5 lib: add ASN.1 encoder
We have a need in the TPM2 trusted keys to return the ASN.1 form of the TPM key blob so it can be operated on by tools outside of the kernel. The specific tools are the openssl_tpm2_engine, openconnect and the Intel tpm2-tss-engine. To do that, we have to be able to read and write the same binary key format the tools use. The current ASN.1 decoder does fine for reading, but we need pieces of an ASN.1 encoder to write the key blob in binary compatible form.
For backwards compatibility, the trusted key reader code will still accept the two TPM2B quantities that it uses today, but the writer will only output the ASN.1 form.
The current implementation only encodes the ASN.1 bits we actually need.
---
v2: updated API to use indefinite length, and made symbol exports gpl
v3: add data length error handling
v4: use end_data instead of data_len pointer
v5: mention tools and space out code
v7: reverse christmas tree variable definitions and better spacing
v9: update comments, remove indefinite length, make encoder config dependent
--- include/linux/asn1_encoder.h | 32 +++ lib/Kconfig | 3 + lib/Makefile | 1 + lib/asn1_encoder.c | 454 +++++++++++++++++++++++++++++++++++ 4 files changed, 490 insertions(+) create mode 100644 include/linux/asn1_encoder.h create mode 100644 lib/asn1_encoder.c
include/linux/asn1_encoder.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _LINUX_ASN1_ENCODER_H +#define _LINUX_ASN1_ENCODER_H + +#include <linux/types.h> +#include <linux/asn1.h> +#include <linux/asn1_ber_bytecode.h> +#include <linux/bug.h> + +#define asn1_oid_len (oid) (sizeof(oid)/sizeof(u32)) +unsigned char * +asn1_encode_integer (unsigned char *data,const unsigned char *end_data, +s64 integer); +unsigned char * +asn1_encode_oid (unsigned char *data,const unsigned char *end_data, +u32 oid[],int oid_len); +unsigned char * +asn1_encode_tag (unsigned char *data,const unsigned char *end_data, +u32 tag,const unsigned char *string,int len); +unsigned char * +asn1_encode_octet_string (unsigned char *data, +const unsigned char *end_data, +const unsigned char *string,u32 len); +unsigned char * +asn1_encode_sequence (unsigned char *data,const unsigned char *end_data, +const unsigned char *seq,int len); +unsigned char * +asn1_encode_boolean (unsigned char *data,const unsigned char *end_data, +bool val); + +#endif
lib/Kconfig +3 -0
@@ -684,3 +684,6 @@ config GENERIC_LIB_UCMPDI2 config PLDMFW bool default n + +config ASN1_ENCODER + tristate
lib/Makefile +1 -0
@@ -278,6 +278,7 @@ obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o obj-$(CONFIG_PERCPU_TEST) += percpu_test.o obj-$(CONFIG_ASN1) += asn1_decoder.o +obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o obj-$(CONFIG_FONT_SUPPORT) += fonts/
lib/asn1_encoder.c new file +454 -0
454 lines not on this page · raw message
Signature · 1 line
2.26.2
James Bottomley
maintainerPATCH v11 2/5 oid_registry: Add TCG defined OIDS for TPM keys
In reply to James BottomleyThe TCG has defined an OID prefix "2.23.133.10.1" for the various TPM key uses. We've defined three of the available numbers:
2.23.133.10.1.3 TPM Loadable key. This is an asymmetric key (Usually
RSA2048 or Elliptic Curve) which can be imported by a TPM2_Load() operation.
2.23.133.10.1.4 TPM Importable Key. This is an asymmetric key (Usually
RSA2048 or Elliptic Curve) which can be imported by a TPM2_Import() operation.
Both loadable and importable keys are specific to a given TPM, the difference is that a loadable key is wrapped with the symmetric secret, so must have been created by the TPM itself. An importable key is wrapped with a DH shared secret, and may be created without access to the TPM provided you know the public part of the parent key.
2.23.133.10.1.5 TPM Sealed Data. This is a set of data (up to 128
bytes) which is sealed by the TPM. It usually represents a symmetric key and must be unsealed before use.
The ASN.1 binary key form starts of with this OID as the first element of a sequence, giving the binary form a unique recognizable identity marker regardless of encoding.
---
v3: correct OID_TPMImportableKey name
v7: add ack
v9: add review
--- include/linux/oid_registry.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/oid_registry.h +5 -0
@@ -107,6 +107,11 @@ enum OID { OID_gostTC26Sign512B,/* 1.2.643.7.1.2.1.2.2 */ OID_gostTC26Sign512C,/* 1.2.643.7.1.2.1.2.3 */ +/* TCG defined OIDS for TPM based keys */ + OID_TPMLoadableKey,/* 2.23.133.10.1.3 */ + OID_TPMImportableKey,/* 2.23.133.10.1.4 */ + OID_TPMSealedData,/* 2.23.133.10.1.5 */ + OID__NR };
Signature · 1 line
2.26.2
James Bottomley
maintainerPATCH v11 3/5 security: keys: trusted: fix TPM2 authorizations
In reply to James BottomleyIn TPM 1.2 an authorization was a 20 byte number. The spec actually recommended you to hash variable length passwords and use the sha1 hash as the authorization. Because the spec doesn't require this hashing, the current authorization for trusted keys is a 40 digit hex number. For TPM 2.0 the spec allows the passing in of variable length passwords and passphrases directly, so we should allow that in trusted keys for ease of use. Update the 'blobauth' parameter to take this into account, so we can now use plain text passwords for the keys.
so before
keyctl add trusted kmk "new 32 blobauthõ72d396fae9206628714fb2ce00f72e94f2258f"
after we will accept both the old hex sha1 form as well as a new directly supplied password:
keyctl add trusted kmk "new 32 blobauth=hello keyhandle�000001"
Since a sha1 hex code must be exactly 40 bytes long and a direct password must be 20 or less, we use the length as the discriminator for which form is input.
Note this is both and enhancement and a potential bug fix. The TPM 2.0 spec requires us to strip leading zeros, meaning empyty authorization is a zero length HMAC whereas we're currently passing in 20 bytes of zeros. A lot of TPMs simply accept this as OK, but the Microsoft TPM emulator rejects it with TPM_RC_BAD_AUTH, so this patch makes the Microsoft TPM emulator work with trusted keys.
---
v6: change comment, eliminate else clauses and add fixes tag
v7: fixes before signoff
--- include/keys/trusted-type.h | 1 + security/keys/trusted-keys/trusted_tpm1.c | 32 ++++++++++++++++++----- security/keys/trusted-keys/trusted_tpm2.c | 10 ++++--- 3 files changed, 33 insertions(+), 10 deletions(-)
include/keys/trusted-type.h +1 -0
@@ -30,6 +30,7 @@ struct trusted_key_options {uint16_t keytype;uint32_t keyhandle;unsigned char keyauth[TPM_DIGEST_SIZE ]; +uint32_t blobauth_len;unsigned char blobauth[TPM_DIGEST_SIZE ];uint32_t pcrinfo_len;unsigned char pcrinfo[MAX_PCRINFO_SIZE ];
security/keys/trusted-keys/trusted_tpm1.c +26 -6
@@ -781,13 +781,33 @@ static int getoptions(char *c, struct trusted_key_payload *pay,return -EINVAL ;break ;case Opt_blobauth: -if (strlen (args[0 ].from) !=2 *SHA1_DIGEST_SIZE ) -return -EINVAL ; - res =hex2bin (opt->blobauth, args[0 ].from, -SHA1_DIGEST_SIZE ); -if (res <0 ) -return -EINVAL ; +/* +* TPM 1.2 authorizations are sha1 hashes passed in as +* hex strings. TPM 2.0 authorizations are simple +* passwords (although it can take a hash as well) +*/ + opt->blobauth_len =strlen (args[0 ].from); + +if (opt->blobauth_len =2 *TPM_DIGEST_SIZE ) { + res =hex2bin (opt->blobauth, args[0 ].from, +TPM_DIGEST_SIZE ); +if (res <0 ) +return -EINVAL ; + + opt->blobauth_len =TPM_DIGEST_SIZE ; +return 0 ; + } + +if (tpm2 && opt->blobauth_len <=sizeof (opt->blobauth)) { +memcpy (opt->blobauth, args[0 ].from, + opt->blobauth_len); +return 0 ; + } + +return -EINVAL ; +break ; +case Opt_migratable:if (*args[0 ].from ='0' ) pay->migratable =0 ;
security/keys/trusted-keys/trusted_tpm2.c +6 -4
@@ -91,10 +91,12 @@ int tpm2_seal_trusted(struct tpm_chip *chip, TPM_DIGEST_SIZE);/* sensitive */ -tpm_buf_append_u16 (&buf,4 +TPM_DIGEST_SIZE + payload->key_len +1 ); +tpm_buf_append_u16 (&buf,4 + options->blobauth_len + payload->key_len +1 ); + +tpm_buf_append_u16 (&buf, options->blobauth_len); +if (options->blobauth_len) +tpm_buf_append (&buf, options->blobauth, options->blobauth_len); -tpm_buf_append_u16 (&buf,TPM_DIGEST_SIZE ); -tpm_buf_append (&buf, options->blobauth,TPM_DIGEST_SIZE );tpm_buf_append_u16 (&buf, payload->key_len +1 );tpm_buf_append (&buf, payload->key, payload->key_len);tpm_buf_append_u8 (&buf, payload->migratable);
@@ -258,7 +260,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,NULL /* nonce */ ,0 ,TPM2_SA_CONTINUE_SESSION , options->blobauth/* hmac */ , - TPM_DIGEST_SIZE); + options->blobauth_len); rc =tpm_send (chip, buf.data,tpm_buf_length (&buf));if (rc >0 )
Signature · 1 line
2.26.2
Re: [PATCH v11 3/5] security: keys: trusted: fix TPM2 authorizations
Quoted 29 lines · James Bottomley
In TPM 1.2 an authorization was a 20 byte number. The spec actually recommended you to hash variable length passwords and use the sha1 hash as the authorization. Because the spec doesn't require this hashing, the current authorization for trusted keys is a 40 digit hex number. For TPM 2.0 the spec allows the passing in of variable length passwords and passphrases directly, so we should allow that in trusted keys for ease of use. Update the 'blobauth' parameter to take this into account, so we can now use plain text passwords for the keys.
so before
keyctl add trusted kmk "new 32 blobauthõ72d396fae9206628714fb2ce00f72e94f2258f"
after we will accept both the old hex sha1 form as well as a new directly supplied password:
keyctl add trusted kmk "new 32 blobauth=hello keyhandle�000001"
Since a sha1 hex code must be exactly 40 bytes long and a direct password must be 20 or less, we use the length as the discriminator for which form is input.
Note this is both and enhancement and a potential bug fix. The TPM 2.0 spec requires us to strip leading zeros, meaning empyty authorization is a zero length HMAC whereas we're currently passing in 20 bytes of zeros. A lot of TPMs simply accept this as OK, but the Microsoft TPM emulator rejects it with
TPM_RC_BAD_AUTH, so this patch makes the Microsoft TPM emulator work with trusted keys.
Quoted 3 lines
Fixes 0fe5480303a1 ("keys, trusted: seal/unseal with TPM 2.0 chips")Signed-off-by James Bottomley <[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>
I created a key:
$ sudo ./tpm2-root-key 0x80000000 $ sudo ./tpm2-list-handles 0x80000000 $ keyctl add trusted kmk "new 32 blobauth=hello keyhandle=0x80000000" <keyctl usage> $ lsmod Module Size Used by sha1_generic 16384 2 trusted 32768 0 asn1_encoder 16384 1 trusted x86_pkg_temp_thermal 20480 0 iwlmvm 356352 0 iwlwifi 315392 1 iwlmvm tpm_crb 16384 0 tpm_tis 16384 0 tpm_tis_core 24576 1 tpm_tis tpm 61440 4 tpm_tis,trusted,tpm_crb,tpm_tis_core efivarfs 16384 1
What could be wrong? Have the full seris applied on a test kernel.
The root key creation is contained in create_root_key():
https://github.com/jsakkine-intel/tpm2-scripts/blob/master/tpm2.py
/Jarkko
James Bottomley
maintainerRe: [PATCH v11 3/5] security: keys: trusted: fix TPM2 authorizations
Quoted 38 lines · Jarkko Sakkinen
Quoted 31 lines · James Bottomley
In TPM 1.2 an authorization was a 20 byte number. The spec actually recommended you to hash variable length passwords and use the sha1 hash as the authorization. Because the spec doesn't require this hashing, the current authorization for trusted keys is a 40 digit hex number. For TPM 2.0 the spec allows the passing in of variable length passwords and passphrases directly, so we should allow that in trusted keys for ease of use. Update the 'blobauth' parameter to take this into account, so we can now use plain text passwords for the keys.
so before
keyctl add trusted kmk "new 32
blobauthõ72d396fae9206628714fb2ce00f72e94f2258f"after we will accept both the old hex sha1 form as well as a new directly supplied password:
keyctl add trusted kmk "new 32 blobauth=hello keyhandle�000001"
Since a sha1 hex code must be exactly 40 bytes long and a direct password must be 20 or less, we use the length as the discriminator for which form is input.
Note this is both and enhancement and a potential bug fix. The TPM 2.0 spec requires us to strip leading zeros, meaning empyty authorization is a zero length HMAC whereas we're currently passing in 20 bytes of zeros. A lot of TPMs simply accept this as OK, but the Microsoft TPM emulator rejects it with
TPM_RC_BAD_AUTH, so this patch makes the Microsoft TPM emulator work with trusted keys.Quoted 5 lines
Fixes 0fe5480303a1 ("keys, trusted: seal/unseal with TPM 2.0chips")
Signed-off-by: James Bottomley
<[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>
Quoted 8 lines
I created a key:
$ sudo ./tpm2-root-key 0x80000000 $ sudo ./tpm2-list-handles 0x80000000 $ keyctl add trusted kmk "new 32 blobauth=hello keyhandle=0x80000000" <keyctl usage>
Well, you're getting that because the command isn't complete ... you need a keyring specifier at the end, like @u. However, even with that there's a bug in the code that would cause this to return EINVAL: the blobauth handler has a return 0 where it should have a break ... I think that happened as a result of the v6 rework which split up the if ... else if ... else chain. The result is the processing of options terminates at blobauth, so if it's last, as I've been testing with, everything is fine. If it's first as you specify, none of the options following the blobauth get processed. I'll fix this up and add an @u to the commit message.
James
Re: [PATCH v11 3/5] security: keys: trusted: fix TPM2 authorizations
Quoted 48 lines · James Bottomley
Quoted 38 lines · Jarkko Sakkinen
Quoted 31 lines · James Bottomley
In TPM 1.2 an authorization was a 20 byte number. The spec actually recommended you to hash variable length passwords and use the sha1 hash as the authorization. Because the spec doesn't require this hashing, the current authorization for trusted keys is a 40 digit hex number. For TPM 2.0 the spec allows the passing in of variable length passwords and passphrases directly, so we should allow that in trusted keys for ease of use. Update the 'blobauth' parameter to take this into account, so we can now use plain text passwords for the keys.
so before
keyctl add trusted kmk "new 32
blobauthõ72d396fae9206628714fb2ce00f72e94f2258f"after we will accept both the old hex sha1 form as well as a new directly supplied password:
keyctl add trusted kmk "new 32 blobauth=hello keyhandle�000001"
Since a sha1 hex code must be exactly 40 bytes long and a direct password must be 20 or less, we use the length as the discriminator for which form is input.
Note this is both and enhancement and a potential bug fix. The TPM 2.0 spec requires us to strip leading zeros, meaning empyty authorization is a zero length HMAC whereas we're currently passing in 20 bytes of zeros. A lot of TPMs simply accept this as OK, but the Microsoft TPM emulator rejects it with
TPM_RC_BAD_AUTH, so this patch makes the Microsoft TPM emulator work with trusted keys.Quoted 5 lines
Fixes 0fe5480303a1 ("keys, trusted: seal/unseal with TPM 2.0chips")
Signed-off-by: James Bottomley
<[email protected]>Reviewed-by Jarkko Sakkinen <[email protected]>Quoted 8 lines
I created a key:
$ sudo ./tpm2-root-key 0x80000000 $ sudo ./tpm2-list-handles 0x80000000 $ keyctl add trusted kmk "new 32 blobauth=hello keyhandle=0x80000000" <keyctl usage>
Quoted 10 lines
Well, you're getting that because the command isn't complete ... you need a keyring specifier at the end, like @u. However, even with that there's a bug in the code that would cause this to return EINVAL: the blobauth handler has a return 0 where it should have a break ... I think that happened as a result of the v6 rework which split up the if ... else if ... else chain. The result is the processing of options terminates at blobauth, so if it's last, as I've been testing with, everything is fine. If it's first as you specify, none of the options following the blobauth get processed. I'll fix this up and add an @u to the commit message.
Ugh, it's true, missing @u from the tail :-) And I was looking for a long time old test script and this and wondering where is the difference...
Fix those so that we can finally merge this :-)
Quoted 3 lines
James
/Jarkko
James Bottomley
maintainerPATCH v11 4/5 security: keys: trusted: use ASN.1 TPM2 key format for the blobs
In reply to James BottomleyModify the TPM2 key format blob output to export and import in the ASN.1 form for TPM2 sealed object keys. For compatibility with prior trusted keys, the importer will also accept two TPM2B quantities representing the public and private parts of the key. However, the export via keyctl pipe will only output the ASN.1 format.
The benefit of the ASN.1 format is that it's a standard and thus the exported key can be used by userspace tools (openssl_tpm2_engine, openconnect and tpm2-tss-engine). The format includes policy specifications, thus it gets us out of having to construct policy handles in userspace and the format includes the parent meaning you don't have to keep passing it in each time.
This patch only implements basic handling for the ASN.1 format, so keys with passwords but no policy.
---
v2: Updated encode API, added length checks
v5: correct export format after doing interoperability checks
v7: use prefix tpm2_key_ instead of tpmkey_ for functions
v8: resplit commit
v9: select ASN1_ENCODER
v11: add ASN.1 format description
--- .../security/keys/trusted-encrypted.rst | 58 +++++ include/keys/trusted-type.h | 1 + security/keys/Kconfig | 1 + security/keys/trusted-keys/Makefile | 2 +- security/keys/trusted-keys/tpm2key.asn1 | 11 + security/keys/trusted-keys/trusted_tpm1.c | 2 +- security/keys/trusted-keys/trusted_tpm2.c | 207 +++++++++++++++++- 7 files changed, 274 insertions(+), 8 deletions(-) create mode 100644 security/keys/trusted-keys/tpm2key.asn1
Documentation/security/keys/trusted-encrypted.rst +58 -0
@@ -208,3 +208,61 @@ about the usage can be found in the file Another new format 'enc32' has been defined in order to support encrypted keys with payload size of 32 bytes. This will initially be used for nvdimm security but may expand to other usages that require 32 bytes payload. + + +TPM 2.0 ASN.1 Key Format +------------------------ + +The TPM 2.0 ASN.1 key format is designed to be easily recognisable, +even in binary form (fixing a problem we had with the TPM 1.2 ASN.1 +format) and to be extensible for additions like importable keys and +policy:: + + TPMKey ::= SEQUENCE { + type OBJECT IDENTIFIER + emptyAuth [0] EXPLICIT BOOLEAN OPTIONAL + parent INTEGER + pubkey OCTET STRING + privkey OCTET STRING + } + +type is what distinguishes the key even in binary form since the OID +is provided by the TCG to be unique and thus forms a recognizable +binary pattern at offset 3 in the key. The OIDs currently made +available are:: + + 2.23.133.10.1.3 TPM Loadable key. This is an asymmetric key (Usually + RSA2048 or Elliptic Curve) which can be imported by a + TPM2_Load() operation. + + 2.23.133.10.1.4 TPM Importable Key. This is an asymmetric key (Usually + RSA2048 or Elliptic Curve) which can be imported by a + TPM2_Import() operation. + + 2.23.133.10.1.5 TPM Sealed Data. This is a set of data (up to 128 + bytes) which is sealed by the TPM. It usually + represents a symmetric key and must be unsealed before + use. + +The trusted key code only uses the TPM Sealed Data OID. + +emptyAuth is true if the key has well known authorization "". If it +is false or not present, the key requires an explicit authorization +phrase. This is used by most user space consumers to decide whether +to prompt for a password. + +parent represents the parent key handle, either in the 0x81 MSO space, +like 0x81000001 for the RSA primary storage key. Userspace programmes +also support specifying the primary handle in the 0x40 MSO space. If +this happens the Elliptic Curve variant of the primary key using the +TCG defined template will be generated on the fly into a volatile +object and used as the parent. The current kernel code only supports +the 0x81 MSO form. + +pubkey is the binary representation of TPM2B_PRIVATE excluding the +initial TPM2B header, which can be reconstructed from the ASN.1 octet +string length. + +privkey is the binary representation of TPM2B_PUBLIC excluding the +initial TPM2B header which can be reconstructed from the ASN.1 octed +string length.
include/keys/trusted-type.h +1 -0
@@ -22,6 +22,7 @@ struct trusted_key_payload {unsigned int key_len;unsigned int blob_len;unsigned char migratable; +unsigned char old_format;unsigned char key[MAX_KEY_SIZE +1 ];unsigned char blob[MAX_BLOB_SIZE ]; };
security/keys/Kconfig +1 -0
@@ -75,6 +75,7 @@ config TRUSTED_KEYS select CRYPTO_HMAC select CRYPTO_SHA1 select CRYPTO_HASH_INFO + select ASN1_ENCODER help This option provides support for creating, sealing, and unsealing keys in the kernel. Trusted keys are random number symmetric keys,
security/keys/trusted-keys/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_TRUSTED_KEYS) += trusted.o trusted-y += trusted_tpm1.o -trusted-y += trusted_tpm2.o +trusted-y += trusted_tpm2.o tpm2key.asn1.o
security/keys/trusted-keys/tpm2key.asn1 new file +11 -0
@@ -0,0 +1,11 @@ +--- +--- ASN.1 for for TPM 2.0 keys +--- + +TPMKey ::= SEQUENCE { + type OBJECT IDENTIFIER ({tpm2_key_type}), + emptyAuth [0] EXPLICIT BOOLEAN OPTIONAL, + parent INTEGER ({tpm2_key_parent}), + pubkey OCTET STRING ({tpm2_key_pub}), + privkey OCTET STRING ({tpm2_key_priv}) + }
security/keys/trusted-keys/trusted_tpm1.c +1 -1
@@ -1011,7 +1011,7 @@ static int trusted_instantiate(struct key *key, goto out; } -if (!options->keyhandle) { +if (!options->keyhandle && !tpm2) { ret = -EINVAL ; goto out; }
security/keys/trusted-keys/trusted_tpm2.c +200 -6
264 lines not on this page · raw message
Signature · 1 line
2.26.2
kernel test robot
build botRe: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
I love your patch! Yet something to improve:
Hi James,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity]
[also build test ERROR on linus/master v5.9-rc4 next-20200911] [cannot apply to security/next-testing dhowells-fs/fscache-next] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/James-Bottomley/TPM-2-0-trusted-key-rework/20200913-013201 base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git next-integrity config: arm-randconfig-r013-20200913 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 3170d54842655d6d936aae32b7d0bc92fce7f22e)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> security/keys/trusted-keys/trusted_tpm2.c:19:10: fatal error: 'tpm2key.asn1.h' file not found
#include "tpm2key.asn1.h"
^~~~~~~~~~~~~~~~1 error generated.
# https://github.com/0day-ci/linux/commit/ce13d03d29ab9ef7c6236ddfbd25ef4ea78dccff
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review James-Bottomley/TPM-2-0-trusted-key-rework/20200913-013201 git checkout ce13d03d29ab9ef7c6236ddfbd25ef4ea78dccff
vim +19 security/keys/trusted-keys/trusted_tpm2.c
18
> 19 #include "tpm2key.asn1.h"
20 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
James Bottomley
maintainerRe: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
Quoted 33 lines · kernel test robot
Hi James,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity] [also build test ERROR on linus/master v5.9-rc4 next-20200911] [cannot apply to
security/next-testingdhowells-fs/fscache-next] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/James-Bottomley/TPM-
2-0-trusted-key-rework/20200913-013201
base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-i
ntegrity.git next-integrity
config: arm-randconfig-r013-20200913 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project3170d54842655d6d936aae32b7d0bc92fce7f22e)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross-O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build # apt-get install binutils-arm-linux-gnueabi
# save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross
ARCH=armIf you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>
Quoted 8 lines
All errors (new ones prefixed by >>):
Quoted 2 lines
Quoted 2 lines
security/keys/trusted-keys/trusted_tpm2.c:19:10: fatal error:
'tpm2key.asn1.h' file not found#include "tpm2key.asn1.h" ^~~~~~~~~~~~~~~~ 1 error generated.
Do you have the actual build log for this? On x86 the build process builds any precursors first, which is the tpm2key.asn1.o, which generates that header file, so we see:
ASN.1 security/keys/trusted-keys/tpm2key.asn1.[ch] CC [M] security/keys/trusted-keys/trusted_tpm2.o CC [M] security/keys/trusted-keys/tpm2-policy.o CC [M] security/keys/trusted-keys/tpm2key.asn1.o LD [M] security/keys/trusted-keys/trusted.o
Is ARM doing a lazier version of that? In which case the fix might be to move trusted_tpm2.o to after tpm2key.asn1.o in the Makefile, this line:
trusted-y += trusted_tpm2.o tpm2key.asn1.o
James
Re: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
Quoted 53 lines · James Bottomley
Quoted 33 lines · kernel test robot
Hi James,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity] [also build test ERROR on linus/master v5.9-rc4 next-20200911] [cannot apply to
security/next-testingdhowells-fs/fscache-next] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/James-Bottomley/TPM-
2-0-trusted-key-rework/20200913-013201
base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-i
ntegrity.git next-integrity
config: arm-randconfig-r013-20200913 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project3170d54842655d6d936aae32b7d0bc92fce7f22e)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross-O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build # apt-get install binutils-arm-linux-gnueabi
# save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross
ARCH=armIf you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>Quoted 8 lines
All errors (new ones prefixed by >>):
Quoted 2 lines
Quoted 2 lines
security/keys/trusted-keys/trusted_tpm2.c:19:10: fatal error:
'tpm2key.asn1.h' file not found#include "tpm2key.asn1.h" ^~~~~~~~~~~~~~~~ 1 error generated.Do you have the actual build log for this? On x86 the build process builds any precursors first, which is the tpm2key.asn1.o, which generates that header file, so we see:
ASN.1 security/keys/trusted-keys/tpm2key.asn1.[ch] CC [M] security/keys/trusted-keys/trusted_tpm2.o CC [M] security/keys/trusted-keys/tpm2-policy.o CC [M] security/keys/trusted-keys/tpm2key.asn1.o LD [M] security/keys/trusted-keys/trusted.o
Quoted 7 lines
Is ARM doing a lazier version of that? In which case the fix might be to move trusted_tpm2.o to after tpm2key.asn1.o in the
Makefile, this line:trusted-y += trusted_tpm2.o tpm2key.asn1.o
James
You can try to reproduce the arm build with BuildRoot. That's what I usually do when bumping something like this with arm.
/Jarkko
Re: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
Quoted 16 lines · Jarkko Sakkinen
Quoted 14 lines · James Bottomley
Quoted 13 lines · kernel test robot
Hi James,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity] [also build test ERROR on linus/master v5.9-rc4 next-20200911] [cannot apply to
security/next-testingdhowells-fs/fscache-next] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
url: https://github.com/0day-ci/linux/commits/James-Bottomley/TPM-
2-0-trusted-key-rework/20200913-013201
base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-i
ntegrity.git next-integrity
config: arm-randconfig-r013-20200913 (attached as .config)
arm-randconfig ^ You'll need to download and gunzip then use the config file.
Quoted 38 lines
Quoted 38 lines
Quoted 15 lines
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project
3170d54842655d6d936aae32b7d0bc92fce7f22e)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross-O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build # apt-get install binutils-arm-linux-gnueabi
# save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross
ARCH=armIf you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>Quoted 8 lines
All errors (new ones prefixed by >>):
Quoted 2 lines
Quoted 2 lines
security/keys/trusted-keys/trusted_tpm2.c:19:10: fatal error:
'tpm2key.asn1.h' file not found#include "tpm2key.asn1.h" ^~~~~~~~~~~~~~~~ 1 error generated.Do you have the actual build log for this? On x86 the build process builds any precursors first, which is the tpm2key.asn1.o, which generates that header file, so we see:
ASN.1 security/keys/trusted-keys/tpm2key.asn1.[ch] CC [M] security/keys/trusted-keys/trusted_tpm2.o CC [M] security/keys/trusted-keys/tpm2-policy.o CC [M] security/keys/trusted-keys/tpm2key.asn1.o LD [M] security/keys/trusted-keys/trusted.oIs ARM doing a lazier version of that? In which case the fix might be to move trusted_tpm2.o to after tpm2key.asn1.o in the
Makefile, this line:
Quoted 6 lines
Quoted 3 lines
trusted-y += trusted_tpm2.o tpm2key.asn1.o
James
You can try to reproduce the arm build with BuildRoot. That's what I usually do when bumping something like this with arm.
You shouldn't need buildroot for build failures (we use buildroot, for boot testing).
For an arm build, you should be able to cross compile with:
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make CC=clang -j
(You can try without CC=clang first, may not be clang specific) (You should install arm-linux-gnueabihf-gcc and the same for binutils. Some distros have separate target triples without hf in them; either should be fine for the kernel as long as your invocation of make matches what you have installed).
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
Quoted 74 lines · Nick Desaulniers
Quoted 16 lines · Jarkko Sakkinen
Quoted 14 lines · James Bottomley
Quoted 13 lines · kernel test robot
Hi James,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity] [also build test ERROR on linus/master v5.9-rc4 next-20200911] [cannot apply to
security/next-testingdhowells-fs/fscache-next] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
url: https://github.com/0day-ci/linux/commits/James-Bottomley/TPM-
2-0-trusted-key-rework/20200913-013201
base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-i
ntegrity.git next-integrity
config: arm-randconfig-r013-20200913 (attached as .config)arm-randconfig ^ You'll need to download and gunzip then use the config file.
Quoted 38 lines
Quoted 38 lines
Quoted 15 lines
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project
3170d54842655d6d936aae32b7d0bc92fce7f22e)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross-O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build # apt-get install binutils-arm-linux-gnueabi
# save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross
ARCH=armIf you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>Quoted 8 lines
All errors (new ones prefixed by >>):
Quoted 2 lines
Quoted 2 lines
security/keys/trusted-keys/trusted_tpm2.c:19:10: fatal error:
'tpm2key.asn1.h' file not found#include "tpm2key.asn1.h" ^~~~~~~~~~~~~~~~ 1 error generated.Do you have the actual build log for this? On x86 the build process builds any precursors first, which is the tpm2key.asn1.o, which generates that header file, so we see:
ASN.1 security/keys/trusted-keys/tpm2key.asn1.[ch] CC [M] security/keys/trusted-keys/trusted_tpm2.o CC [M] security/keys/trusted-keys/tpm2-policy.o CC [M] security/keys/trusted-keys/tpm2key.asn1.o LD [M] security/keys/trusted-keys/trusted.oIs ARM doing a lazier version of that? In which case the fix might be to move trusted_tpm2.o to after tpm2key.asn1.o in the
Makefile, this line:Quoted 6 lines
Quoted 3 lines
trusted-y += trusted_tpm2.o tpm2key.asn1.o
James
You can try to reproduce the arm build with BuildRoot. That's what I usually do when bumping something like this with arm.
You shouldn't need buildroot for build failures (we use buildroot, for boot testing).
Quoted 11 lines
For an arm build, you should be able to cross compile with:
$ ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make CC=clang -j(You can try without CC=clang first, may not be clang specific) (You should install arm-linux-gnueabihf-gcc and the same for binutils. Some distros have separate target triples without
hfin them; either should be fine for the kernel as long as your invocation of make matches what you have installed).Signature · 2 lines
Thanks, ~Nick Desaulniers
Hmm... How do I get a cross compiler in the first place for ARM? I use BuildRoot just to get the cross compile chain.
The compiler that you use in your example is unfortunately not preincluded to my Ubuntu installation...
/Jarkko
Re: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
Quoted 3 lines · Jarkko Sakkinen
The compiler that you use in your example is unfortunately not preincluded to my Ubuntu installation...
$ sudo apt install gcc-arm-linux-gnueabihf binutils-arm-linux-gnueabihf
Signature · 2 lines
Thanks, ~Nick Desaulniers
Re: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
Quoted 10 lines · Nick Desaulniers
Quoted 3 lines · Jarkko Sakkinen
The compiler that you use in your example is unfortunately not preincluded to my Ubuntu installation...
$ sudo apt install gcc-arm-linux-gnueabihf binutils-arm-linux-gnueabihfSignature · 2 lines
Thanks, ~Nick Desaulniers
Thanks, installed for the future. A bit more convenient than compile your own chain :-)
/Jarkko
kernel test robot
build botRe: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
In reply to James BottomleyI love your patch! Yet something to improve:
Hi James,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity]
[also build test ERROR on linus/master v5.9-rc4 next-20200911] [cannot apply to security/next-testing dhowells-fs/fscache-next] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/James-Bottomley/TPM-2-0-trusted-key-rework/20200913-013201 base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git next-integrity config: x86_64-randconfig-s022-20200913 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.2-191-g10164920-dirty # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> security/keys/trusted-keys/trusted_tpm2.c:19:10: fatal error: tpm2key.asn1.h: No such file or directory
19 | #include "tpm2key.asn1.h"
| ^~~~~~~~~~~~~~~~compilation terminated.
# https://github.com/0day-ci/linux/commit/ce13d03d29ab9ef7c6236ddfbd25ef4ea78dccff
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review James-Bottomley/TPM-2-0-trusted-key-rework/20200913-013201 git checkout ce13d03d29ab9ef7c6236ddfbd25ef4ea78dccff
vim +19 security/keys/trusted-keys/trusted_tpm2.c
18
> 19 #include "tpm2key.asn1.h"
20 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
In reply to James BottomleyI love your patch! Yet something to improve:
Hi James,
I love your patch! Yet something to improve:
[auto build test ERROR on integrity/next-integrity]
[also build test ERROR on linus/master v5.9-rc4 next-20200911] [cannot apply to security/next-testing dhowells-fs/fscache-next] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/James-Bottomley/TPM-2-0-trusted-key-rework/20200913-013201 base: https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git next-integrity config: i386-randconfig-a014-20200912 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # save the attached .config to linux build tree make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> make[4]: *** No rule to make target 'security/keys/trusted-keys/tpm2key.asn1.o', needed by 'security/keys/trusted-keys/built-in.a'.
make[4]: *** [scripts/Makefile.build:283: security/keys/trusted-keys/trusted_tpm2.o] Error 1 make[4]: Target '__build' not remade because of errors.
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
James Bottomley
maintainerPATCH v11 5/5 security: keys: trusted: Make sealed key properly interoperable
In reply to James BottomleyThe current implementation appends a migratable flag to the end of a key, meaning the format isn't exactly interoperable because the using party needs to know to strip this extra byte. However, all other consumers of TPM sealed blobs expect the unseal to return exactly the key. Since TPM2 keys have a key property flag that corresponds to migratable, use that flag instead and make the actual key the only sealed quantity. This is secure because the key properties are bound to a hash in the private part, so if they're altered the key won't load.
Backwards compatibility is implemented by detecting whether we're loading a new format key or not and correctly setting migratable from the last byte of old format keys.
---
v2: added length checks to untrusted payload
v8: recover patch
--- include/linux/tpm.h | 2 + security/keys/trusted-keys/trusted_tpm2.c | 53 ++++++++++++++++------- 2 files changed, 40 insertions(+), 15 deletions(-)
include/linux/tpm.h +2 -0
@@ -305,6 +305,8 @@ struct tpm_buf { };enum tpm2_object_attributes { +TPM2_OA_FIXED_TPM =BIT (1 ), +TPM2_OA_FIXED_PARENT =BIT (4 ),TPM2_OA_USER_WITH_AUTH =BIT (6 ), };
security/keys/trusted-keys/trusted_tpm2.c +38 -15
105 lines not on this page · raw message
Signature · 1 line
2.26.2