Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp5046724imm; Fri, 18 May 2018 15:40:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqcdtxqZkyTyAhKpV7ynfHJxSti+Yci3jbJ9vakuMKKoOWnmqVKVxGtUTDdtqCkv8gvAv1Z X-Received: by 2002:a65:40c5:: with SMTP id u5-v6mr8842910pgp.372.1526683215972; Fri, 18 May 2018 15:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526683215; cv=none; d=google.com; s=arc-20160816; b=JH9kQ6HyfI4XYnR9CQr7dHyz9RnEgceFqp6mJmSZND5Gp/oh/6E3aXXA3+s5ebZmgv 5UJyDwGkbBa/u4bWOZknwzdbGpazJEGTIobqi/rgX+jbG9RZHP8MWzYy7V1ptsFQgh// wfz1w0+RqSh33KFB3WhxwJ+Dc2sUlSkQFINYEXME0lHLxhWn3v4ug4ObxWBQvygFal6Q BKu8OiVFkl72bzDKZIiaZksBGulWN/UqwLTw3ICcuhAxsksKl2phKwZdqeo+CoILcXRm zqQwhoDb6Dffux8ns7KStgLbwGDB8jg9h0fISsBgEyiQDVOmEu9HqbqmhK6RMCcEgwMP KA6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=uUQihmfrFQuKx8V+nsPb0YCOLIHaSEy6dGENoTkAgw8=; b=LLT1UYbYNj3efrI3nlJYUJ2m2Hw+hpIxk/krK7l2LnhN3WhWvEh2KpjOMu842vH+wa QZXWdGrItFHGWZmJG9xv0cOQQOmRimShMx0Ei3H8dD4C4+DOZy8XN8P3k9/r9vRZVvvb sDC+1CcnkuGfNw2K+YGbV4HHN+S6IF8kOT4qu33GqrR7eunVVv8ook8YeY1XHhwSZ8yB fWpuFAWNMerKJAv+3s78ulhfFosoY4wbsU5MBaRs8e4aPugCug3r+ed+wYBL1HJ0dP0+ CEBCfgYvIQSvZKYRkq3RaO+5PwN0W/+2t57OenF6Er5oSUPWo7SbGtMlRh7z1O4Uhhxo Km3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5-v6si8196935plt.357.2018.05.18.15.40.01; Fri, 18 May 2018 15:40:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752214AbeERWjv (ORCPT + 99 others); Fri, 18 May 2018 18:39:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47470 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751747AbeERWjr (ORCPT ); Fri, 18 May 2018 18:39:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 824523003ACF; Fri, 18 May 2018 22:39:47 +0000 (UTC) Received: from localhost (ovpn-116-99.phx2.redhat.com [10.3.116.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BDBA5D6B5; Fri, 18 May 2018 22:39:47 +0000 (UTC) Date: Fri, 18 May 2018 15:39:47 -0700 From: Jerry Snitselaar To: Jarkko Sakkinen Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, Peter Huewe , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , open list Subject: Re: [PATCH v4 3/4] tpm: migrate tpm2_get_tpm_pt() to use struct tpm_buf Message-ID: <20180518223947.s3x2lkexyjemcnfa@cantor> Reply-To: Jerry Snitselaar Mail-Followup-To: Jarkko Sakkinen , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, Peter Huewe , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , open list References: <20180326121406.14548-1-jarkko.sakkinen@linux.intel.com> <20180326121406.14548-4-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20180326121406.14548-4-jarkko.sakkinen@linux.intel.com> User-Agent: NeoMutt/20180512 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 18 May 2018 22:39:47 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon Mar 26 18, Jarkko Sakkinen wrote: >In order to make struct tpm_buf the first class object for constructing TPM >commands, migrate tpm2_get_tpm_pt() to use it. > >Signed-off-by: Jarkko Sakkinen Reviewed-by: Jerry Snitselaar >--- > drivers/char/tpm/tpm2-cmd.c | 63 +++++++++++++++++---------------------------- > 1 file changed, 23 insertions(+), 40 deletions(-) > >diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c >index 7bffd0fd1dca..b3b52f9eb65f 100644 >--- a/drivers/char/tpm/tpm2-cmd.c >+++ b/drivers/char/tpm/tpm2-cmd.c >@@ -27,20 +27,6 @@ enum tpm2_session_attributes { > TPM2_SA_CONTINUE_SESSION = BIT(0), > }; > >-struct tpm2_get_tpm_pt_in { >- __be32 cap_id; >- __be32 property_id; >- __be32 property_cnt; >-} __packed; >- >-struct tpm2_get_tpm_pt_out { >- u8 more_data; >- __be32 subcap_id; >- __be32 property_cnt; >- __be32 property_id; >- __be32 value; >-} __packed; >- > struct tpm2_get_random_in { > __be16 size; > } __packed; >@@ -51,8 +37,6 @@ struct tpm2_get_random_out { > } __packed; > > union tpm2_cmd_params { >- struct tpm2_get_tpm_pt_in get_tpm_pt_in; >- struct tpm2_get_tpm_pt_out get_tpm_pt_out; > struct tpm2_get_random_in getrandom_in; > struct tpm2_get_random_out getrandom_out; > }; >@@ -379,19 +363,6 @@ int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max) > return total ? total : -EIO; > } > >-#define TPM2_GET_TPM_PT_IN_SIZE \ >- (sizeof(struct tpm_input_header) + \ >- sizeof(struct tpm2_get_tpm_pt_in)) >- >-#define TPM2_GET_TPM_PT_OUT_BODY_SIZE \ >- sizeof(struct tpm2_get_tpm_pt_out) >- >-static const struct tpm_input_header tpm2_get_tpm_pt_header = { >- .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS), >- .length = cpu_to_be32(TPM2_GET_TPM_PT_IN_SIZE), >- .ordinal = cpu_to_be32(TPM2_CC_GET_CAPABILITY) >-}; >- > /** > * tpm2_flush_context_cmd() - execute a TPM2_FlushContext command > * @chip: TPM chip to use >@@ -725,6 +696,14 @@ int tpm2_unseal_trusted(struct tpm_chip *chip, > return rc; > } > >+struct tpm2_get_cap_out { >+ u8 more_data; >+ __be32 subcap_id; >+ __be32 property_cnt; >+ __be32 property_id; >+ __be32 value; >+} __packed; >+ > /** > * tpm2_get_tpm_pt() - get value of a TPM_CAP_TPM_PROPERTIES type property > * @chip: TPM chip to use. >@@ -737,19 +716,23 @@ int tpm2_unseal_trusted(struct tpm_chip *chip, > ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, u32 *value, > const char *desc) > { >- struct tpm2_cmd cmd; >+ struct tpm2_get_cap_out *out; >+ struct tpm_buf buf; > int rc; > >- cmd.header.in = tpm2_get_tpm_pt_header; >- cmd.params.get_tpm_pt_in.cap_id = cpu_to_be32(TPM2_CAP_TPM_PROPERTIES); >- cmd.params.get_tpm_pt_in.property_id = cpu_to_be32(property_id); >- cmd.params.get_tpm_pt_in.property_cnt = cpu_to_be32(1); >- >- rc = tpm_transmit_cmd(chip, NULL, &cmd, sizeof(cmd), >- TPM2_GET_TPM_PT_OUT_BODY_SIZE, 0, desc); >- if (!rc) >- *value = be32_to_cpu(cmd.params.get_tpm_pt_out.value); >- >+ rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_GET_CAPABILITY); >+ if (rc) >+ return rc; >+ tpm_buf_append_u32(&buf, TPM2_CAP_TPM_PROPERTIES); >+ tpm_buf_append_u32(&buf, property_id); >+ tpm_buf_append_u32(&buf, 1); >+ rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, 0, 0, NULL); >+ if (!rc) { >+ out = (struct tpm2_get_cap_out *) >+ &buf.data[TPM_HEADER_SIZE]; >+ *value = be32_to_cpu(out->value); >+ } >+ tpm_buf_destroy(&buf); > return rc; > } > EXPORT_SYMBOL_GPL(tpm2_get_tpm_pt); >-- >2.15.1 >