All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v11 0/5] TPM 2.0 trusted key rework
@ 2020-09-12 17:26 ` James Bottomley
  0 siblings, 0 replies; 39+ messages in thread
From: James Bottomley @ 2020-09-12 17:26 UTC (permalink / raw)
  To: linux-integrity
  Cc: Mimi Zohar, Jarkko Sakkinen, David Woodhouse, keyrings,
	David Howells

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

-- 
2.26.2

^ permalink raw reply	[flat|nested] 39+ messages in thread
* Re: [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs
@ 2020-09-13  9:35 kernel test robot
  0 siblings, 0 replies; 39+ messages in thread
From: kernel test robot @ 2020-09-13  9:35 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 6886 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20200912172643.9063-5-James.Bottomley@HansenPartnership.com>
References: <20200912172643.9063-5-James.Bottomley@HansenPartnership.com>
TO: James Bottomley <James.Bottomley@HansenPartnership.com>
TO: linux-integrity(a)vger.kernel.org
CC: Mimi Zohar <zohar@linux.ibm.com>
CC: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
CC: David Woodhouse <dwmw2@infradead.org>
CC: keyrings(a)vger.kernel.org
CC: David Howells <dhowells@redhat.com>

Hi James,

I love your patch! Perhaps something to improve:

[auto build test WARNING on integrity/next-integrity]
[also build test WARNING 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
:::::: branch date: 16 hours ago
:::::: commit date: 16 hours ago
compiler: microblaze-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


cppcheck warnings: (new ones prefixed by >>)

>> security/keys/trusted-keys/trusted_tpm2.c:38:25: warning: Either the condition '!scratch' is redundant or there is pointer arithmetic with NULL pointer. [nullPointerArithmeticRedundantCheck]
    u8 *end_work = scratch + SCRATCH_SIZE;
                           ^
   security/keys/trusted-keys/trusted_tpm2.c:50:6: note: Assuming that condition '!scratch' is not redundant
    if (!scratch)
        ^
   security/keys/trusted-keys/trusted_tpm2.c:38:25: note: Null pointer addition
    u8 *end_work = scratch + SCRATCH_SIZE;
                           ^

# 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 +38 security/keys/trusted-keys/trusted_tpm2.c

ce13d03d29ab9e James Bottomley 2020-09-12  30  
ce13d03d29ab9e James Bottomley 2020-09-12  31  static int tpm2_key_encode(struct trusted_key_payload *payload,
ce13d03d29ab9e James Bottomley 2020-09-12  32  			   struct trusted_key_options *options,
ce13d03d29ab9e James Bottomley 2020-09-12  33  			   u8 *src, u32 len)
ce13d03d29ab9e James Bottomley 2020-09-12  34  {
ce13d03d29ab9e James Bottomley 2020-09-12  35  	const int SCRATCH_SIZE = PAGE_SIZE;
ce13d03d29ab9e James Bottomley 2020-09-12  36  	u8 *scratch = kmalloc(SCRATCH_SIZE, GFP_KERNEL);
ce13d03d29ab9e James Bottomley 2020-09-12  37  	u8 *work = scratch, *work1;
ce13d03d29ab9e James Bottomley 2020-09-12 @38  	u8 *end_work = scratch + SCRATCH_SIZE;
ce13d03d29ab9e James Bottomley 2020-09-12  39  	u8 *priv, *pub;
ce13d03d29ab9e James Bottomley 2020-09-12  40  	u16 priv_len, pub_len;
ce13d03d29ab9e James Bottomley 2020-09-12  41  
ce13d03d29ab9e James Bottomley 2020-09-12  42  	priv_len = get_unaligned_be16(src) + 2;
ce13d03d29ab9e James Bottomley 2020-09-12  43  	priv = src;
ce13d03d29ab9e James Bottomley 2020-09-12  44  
ce13d03d29ab9e James Bottomley 2020-09-12  45  	src += priv_len;
ce13d03d29ab9e James Bottomley 2020-09-12  46  
ce13d03d29ab9e James Bottomley 2020-09-12  47  	pub_len = get_unaligned_be16(src) + 2;
ce13d03d29ab9e James Bottomley 2020-09-12  48  	pub = src;
ce13d03d29ab9e James Bottomley 2020-09-12  49  
ce13d03d29ab9e James Bottomley 2020-09-12  50  	if (!scratch)
ce13d03d29ab9e James Bottomley 2020-09-12  51  		return -ENOMEM;
ce13d03d29ab9e James Bottomley 2020-09-12  52  
ce13d03d29ab9e James Bottomley 2020-09-12  53  	work = asn1_encode_oid(work, end_work, tpm2key_oid,
ce13d03d29ab9e James Bottomley 2020-09-12  54  			       asn1_oid_len(tpm2key_oid));
ce13d03d29ab9e James Bottomley 2020-09-12  55  
ce13d03d29ab9e James Bottomley 2020-09-12  56  	if (options->blobauth_len == 0) {
ce13d03d29ab9e James Bottomley 2020-09-12  57  		unsigned char bool[3], *w = bool;
ce13d03d29ab9e James Bottomley 2020-09-12  58  		/* tag 0 is emptyAuth */
ce13d03d29ab9e James Bottomley 2020-09-12  59  		w = asn1_encode_boolean(w, w + sizeof(bool), true);
ce13d03d29ab9e James Bottomley 2020-09-12  60  		if (WARN(IS_ERR(w), "BUG: Boolean failed to encode"))
ce13d03d29ab9e James Bottomley 2020-09-12  61  			return PTR_ERR(w);
ce13d03d29ab9e James Bottomley 2020-09-12  62  		work = asn1_encode_tag(work, end_work, 0, bool, w - bool);
ce13d03d29ab9e James Bottomley 2020-09-12  63  	}
ce13d03d29ab9e James Bottomley 2020-09-12  64  
ce13d03d29ab9e James Bottomley 2020-09-12  65  	/*
ce13d03d29ab9e James Bottomley 2020-09-12  66  	 * Assume both octet strings will encode to a 2 byte definite length
ce13d03d29ab9e James Bottomley 2020-09-12  67  	 *
ce13d03d29ab9e James Bottomley 2020-09-12  68  	 * Note: For a well behaved TPM, this warning should never
ce13d03d29ab9e James Bottomley 2020-09-12  69  	 * trigger, so if it does there's something nefarious going on
ce13d03d29ab9e James Bottomley 2020-09-12  70  	 */
ce13d03d29ab9e James Bottomley 2020-09-12  71  	if (WARN(work - scratch + pub_len + priv_len + 14 > SCRATCH_SIZE,
ce13d03d29ab9e James Bottomley 2020-09-12  72  		 "BUG: scratch buffer is too small"))
ce13d03d29ab9e James Bottomley 2020-09-12  73  		return -EINVAL;
ce13d03d29ab9e James Bottomley 2020-09-12  74  
ce13d03d29ab9e James Bottomley 2020-09-12  75  	work = asn1_encode_integer(work, end_work, options->keyhandle);
ce13d03d29ab9e James Bottomley 2020-09-12  76  	work = asn1_encode_octet_string(work, end_work, pub, pub_len);
ce13d03d29ab9e James Bottomley 2020-09-12  77  	work = asn1_encode_octet_string(work, end_work, priv, priv_len);
ce13d03d29ab9e James Bottomley 2020-09-12  78  
ce13d03d29ab9e James Bottomley 2020-09-12  79  	work1 = payload->blob;
ce13d03d29ab9e James Bottomley 2020-09-12  80  	work1 = asn1_encode_sequence(work1, work1 + sizeof(payload->blob),
ce13d03d29ab9e James Bottomley 2020-09-12  81  				     scratch, work - scratch);
ce13d03d29ab9e James Bottomley 2020-09-12  82  	if (WARN(IS_ERR(work1), "BUG: ASN.1 encoder failed"))
ce13d03d29ab9e James Bottomley 2020-09-12  83  		return PTR_ERR(work1);
ce13d03d29ab9e James Bottomley 2020-09-12  84  
ce13d03d29ab9e James Bottomley 2020-09-12  85  	return work1 - payload->blob;
ce13d03d29ab9e James Bottomley 2020-09-12  86  }
ce13d03d29ab9e James Bottomley 2020-09-12  87  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2020-09-17 15:31 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-12 17:26 [PATCH v11 0/5] TPM 2.0 trusted key rework James Bottomley
2020-09-12 17:26 ` James Bottomley
2020-09-12 17:26 ` [PATCH v11 1/5] lib: add ASN.1 encoder James Bottomley
2020-09-12 17:26   ` James Bottomley
2020-09-12 17:26 ` [PATCH v11 2/5] oid_registry: Add TCG defined OIDS for TPM keys James Bottomley
2020-09-12 17:26   ` James Bottomley
2020-09-12 17:26 ` [PATCH v11 3/5] security: keys: trusted: fix TPM2 authorizations James Bottomley
2020-09-12 17:26   ` James Bottomley
2020-09-15  9:09   ` Jarkko Sakkinen
2020-09-15  9:09     ` Jarkko Sakkinen
2020-09-16 19:52     ` James Bottomley
2020-09-16 19:52       ` James Bottomley
2020-09-17 15:21       ` Jarkko Sakkinen
2020-09-17 15:21         ` Jarkko Sakkinen
2020-09-12 17:26 ` [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs James Bottomley
2020-09-12 17:26   ` James Bottomley
2020-09-13  6:26   ` kernel test robot
2020-09-13  6:26     ` kernel test robot
2020-09-13  6:26     ` kernel test robot
2020-09-13 17:02     ` James Bottomley
2020-09-13 17:02       ` James Bottomley
2020-09-15  9:11       ` Jarkko Sakkinen
2020-09-15 20:20         ` Nick Desaulniers
2020-09-15 20:20           ` Nick Desaulniers
2020-09-15 20:20           ` Nick Desaulniers
2020-09-16 16:27           ` Jarkko Sakkinen
2020-09-16 16:27             ` Jarkko Sakkinen
2020-09-16 16:27             ` Jarkko Sakkinen
2020-09-16 18:04             ` Nick Desaulniers
2020-09-16 18:04               ` Nick Desaulniers
2020-09-16 18:04               ` Nick Desaulniers
2020-09-17 15:17               ` Jarkko Sakkinen
2020-09-17 15:17                 ` Jarkko Sakkinen
2020-09-17 15:17                 ` Jarkko Sakkinen
2020-09-13  7:07   ` kernel test robot
2020-09-13  7:29   ` kernel test robot
2020-09-12 17:26 ` [PATCH v11 5/5] security: keys: trusted: Make sealed key properly interoperable James Bottomley
2020-09-12 17:26   ` James Bottomley
  -- strict thread matches above, loose matches on Subject: below --
2020-09-13  9:35 [PATCH v11 4/5] security: keys: trusted: use ASN.1 TPM2 key format for the blobs kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.