From patchwork Tue Aug 21 15:59:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 10571999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CD04921 for ; Tue, 21 Aug 2018 15:59:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEE032A9B1 for ; Tue, 21 Aug 2018 15:59:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E394A2A9B3; Tue, 21 Aug 2018 15:59:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CE9C2A9AE for ; Tue, 21 Aug 2018 15:59:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728063AbeHUTUD (ORCPT ); Tue, 21 Aug 2018 15:20:03 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53978 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727031AbeHUTUD (ORCPT ); Tue, 21 Aug 2018 15:20:03 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A7898076825; Tue, 21 Aug 2018 15:59:20 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-123-147.rdu2.redhat.com [10.10.123.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29A212026D64; Tue, 21 Aug 2018 15:59:19 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 22/23] TPMLIB: Provide call for TPM_FlushSpecific From: David Howells To: denkenz@gmail.com, jarkko.sakkinen@linux.intel.com, jejb@linux.vnet.ibm.com Cc: keyrings@vger.kernel.org, linux-integrity@vger.kernel.org, tpmdd-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org Date: Tue, 21 Aug 2018 16:59:18 +0100 Message-ID: <153486715863.13066.9507446322086735862.stgit@warthog.procyon.org.uk> In-Reply-To: <153486700916.13066.12870860668352070081.stgit@warthog.procyon.org.uk> References: <153486700916.13066.12870860668352070081.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 21 Aug 2018 15:59:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 21 Aug 2018 15:59:20 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP --- drivers/char/tpm/tpm-library.c | 31 +++++++++++++++++++++++++++++++ include/linux/tpm.h | 17 +++++++++++++++++ include/linux/tpm_command.h | 1 + 3 files changed, 49 insertions(+) diff --git a/drivers/char/tpm/tpm-library.c b/drivers/char/tpm/tpm-library.c index d279243ccc00..27e993f0b0b7 100644 --- a/drivers/char/tpm/tpm-library.c +++ b/drivers/char/tpm/tpm-library.c @@ -1110,6 +1110,37 @@ out: } EXPORT_SYMBOL_GPL(tpm_load_key2); +/** + * tpm_flush_specific - Tell the TPM to discard a handle and associated resources + * @chip: The chip to use + * @handle: The handle to discard + * @handle_type: The type of handle + */ +int tpm_flush_specific(struct tpm_chip *chip, + uint32_t handle, enum tpm_resource_type handle_type) +{ + struct tpm_buf *tb; + int ret; + + /* alloc some work space */ + tb = kmalloc(sizeof(*tb), GFP_KERNEL); + if (!tb) + return -ENOMEM; + + /* build and send the TPM request packet */ + INIT_BUF(tb); + store16(tb, TPM_TAG_RQU_COMMAND); + store32(tb, TPM_DATA_OFFSET + 8); + store32(tb, TPM_ORD_FLUSHSPECIFIC); + store32(tb, handle); + store32(tb, handle_type); + + ret = tpm_send_dump(chip, tb, "flushing handle"); + kfree(tb); + return ret; +} +EXPORT_SYMBOL_GPL(tpm_flush_specific); + /** * tpm_library_use - Tell the TPM library we want to make use of it * diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 2be0decff93b..753ffd3799a1 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -109,6 +109,19 @@ enum tpm_entity_type { TPM_ET_RESERVED_HANDLE = 0x40, }; +enum tpm_resource_type { + TPM_RT_KEY = 0x00000001, + TPM_RT_AUTH = 0x00000002, + TPM_RT_HASH = 0x00000003, + TPM_RT_TRANS = 0x00000004, + TPM_RT_CONTEXT = 0x00000005, + TPM_RT_COUNTER = 0x00000006, + TPM_RT_DELEGATE = 0x00000007, + TPM_RT_DAA_TPM = 0x00000008, + TPM_RT_DAA_V0 = 0x00000009, + TPM_RT_DAA_V1 = 0x0000000a, +}; + struct tpm_buf { unsigned short len; unsigned short offset; @@ -154,4 +167,8 @@ extern int tpm_load_key2(struct tpm_chip *chip, const struct tpm_wrapped_key *wrapped_key, uint32_t *_key_handle); +extern int tpm_flush_specific(struct tpm_chip *chip, + uint32_t handle, + enum tpm_resource_type handle_type); + #endif diff --git a/include/linux/tpm_command.h b/include/linux/tpm_command.h index 211d4ce75f67..8b52447bbee3 100644 --- a/include/linux/tpm_command.h +++ b/include/linux/tpm_command.h @@ -30,6 +30,7 @@ enum tpm_ordinal { TPM_ORD_READPUBEK = 124, TPM_ORD_SAVESTATE = 152, TPM_ORD_STARTUP = 153, + TPM_ORD_FLUSHSPECIFIC = 186, }; /* Other constants */