From patchwork Fri Jul 3 15:36:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 6716291 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7656B9F1C1 for ; Fri, 3 Jul 2015 15:37:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 817FF207F0 for ; Fri, 3 Jul 2015 15:37:25 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5B531207EC for ; Fri, 3 Jul 2015 15:37:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZB31n-0002Uo-IK; Fri, 03 Jul 2015 15:37:23 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZB31m-0002Uj-Qs for tpmdd-devel@lists.sourceforge.net; Fri, 03 Jul 2015 15:37:22 +0000 X-ACL-Warn: Received: from mga09.intel.com ([134.134.136.24]) by sog-mx-2.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1ZB31k-0007Sl-Pq for tpmdd-devel@lists.sourceforge.net; Fri, 03 Jul 2015 15:37:22 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 03 Jul 2015 08:37:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,400,1432623600"; d="scan'208";a="518457306" Received: from scheller-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.20.4]) by FMSMGA003.fm.intel.com with ESMTP; 03 Jul 2015 08:37:09 -0700 From: Jarkko Sakkinen To: peterhuewe@gmx.de, tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, safford@us.ibm.com Date: Fri, 3 Jul 2015 18:36:36 +0300 Message-Id: <1435937799-28040-5-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435937799-28040-1-git-send-email-jarkko.sakkinen@linux.intel.com> References: <1435937799-28040-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-Spam-Score: -0.6 (/) X-Headers-End: 1ZB31k-0007Sl-Pq Cc: David Howells , "open list:KEYS-TRUSTED" , "open list:KEYS-TRUSTED" , James Morris , "Serge E. Hallyn" Subject: [tpmdd-devel] [PATCH 4/4] keys, trusted: seal/unseal with TPM 2.0 chips X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, HK_RANDOM_ENVFROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Call tpm_seal_trusted() and tpm_unseal_trusted() for TPM 2.0 chips. Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm2-cmd.c | 6 +----- include/linux/tpm_command.h | 1 - security/keys/trusted.c | 18 ++++++++++++++---- security/keys/trusted.h | 7 +++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index d404e5f..d2bcf79 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -406,21 +406,17 @@ static int tpm2_load(struct tpm_chip *chip, if (private_len > (payload->blob_len - 2)) return -E2BIG; - pr_info("private_len=%u\n", private_len); - public_len = be16_to_cpup((__be16 *) &payload->blob[2 + private_len]); blob_len = private_len + public_len + 4; if (blob_len > payload->blob_len) return -E2BIG; - pr_info("public_len=%u\n", public_len); - tpm_buf_init(&buf, TPM2_ST_SESSIONS, TPM2_CC_LOAD); tpm_buf_append_u32(&buf, options->keyhandle); tpm2_buf_append_auth(&buf, TPM2_RS_PW, NULL /* nonce */, 0, 0 /* session_attributes */, NULL /* hmac */, 0); - tpm_buf_append(&buf, payload->blob, payload->blob_len); + tpm_buf_append(&buf, payload->blob, blob_len); rc = tpm_transmit_cmd(chip, buf.data, TPM_BUF_SIZE, "loading blob"); if (!rc) diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h index 727512e..d7b0f82 100644 --- a/include/linux/tpm_command.h +++ b/include/linux/tpm_command.h @@ -22,7 +22,6 @@ #define TPM_ORD_UNSEAL 24 /* Other constants */ -#define SRKHANDLE 0x40000000 #define TPM_NONCE_SIZE 20 #endif diff --git a/security/keys/trusted.c b/security/keys/trusted.c index c0594cb..f6557b1 100644 --- a/security/keys/trusted.c +++ b/security/keys/trusted.c @@ -601,7 +601,7 @@ static int tpm_unseal(struct tpm_buf *tb, } ordinal = htonl(TPM_ORD_UNSEAL); - keyhndl = htonl(SRKHANDLE); + keyhndl = htonl(TPM1_SRKHANDLE); ret = tpm_get_random(TPM_ANY_NUM, nonceodd, TPM_NONCE_SIZE); if (ret != TPM_NONCE_SIZE) { pr_info("trusted_key: tpm_get_random failed (%d)\n", ret); @@ -867,7 +867,11 @@ static struct trusted_key_options *trusted_options_alloc(void) if (options) { /* set any non-zero defaults */ options->keytype = SRK_keytype; - options->keyhandle = SRKHANDLE; + + if (tpm_is_tpm2(TPM_ANY_NUM)) + options->keyhandle = TPM2_SRKHANDLE; + else + options->keyhandle = TPM1_SRKHANDLE; } return options; } @@ -937,7 +941,10 @@ static int trusted_instantiate(struct key *key, switch (key_cmd) { case Opt_load: - ret = key_unseal(payload, options); + if (tpm_is_tpm2(TPM_ANY_NUM)) + ret = tpm_unseal_trusted(TPM_ANY_NUM, payload, options); + else + ret = key_unseal(payload, options); dump_payload(payload); dump_options(options); if (ret < 0) @@ -950,7 +957,10 @@ static int trusted_instantiate(struct key *key, pr_info("trusted_key: key_create failed (%d)\n", ret); goto out; } - ret = key_seal(payload, options); + if (tpm_is_tpm2(TPM_ANY_NUM)) + ret = tpm_seal_trusted(TPM_ANY_NUM, payload, options); + else + ret = key_seal(payload, options); if (ret < 0) pr_info("trusted_key: key_seal failed (%d)\n", ret); break; diff --git a/security/keys/trusted.h b/security/keys/trusted.h index ff001a5..fc32c47 100644 --- a/security/keys/trusted.h +++ b/security/keys/trusted.h @@ -12,6 +12,13 @@ #define TPM_RETURN_OFFSET 6 #define TPM_DATA_OFFSET 10 +/* Transient object handles start from 0x80000000 in TPM 2.0, which makes it + * a sane default. + */ + +#define TPM1_SRKHANDLE 0x40000000 +#define TPM2_SRKHANDLE 0x80000000 + #define LOAD32(buffer, offset) (ntohl(*(uint32_t *)&buffer[offset])) #define LOAD32N(buffer, offset) (*(uint32_t *)&buffer[offset]) #define LOAD16(buffer, offset) (ntohs(*(uint16_t *)&buffer[offset]))