Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4998390imm; Tue, 18 Sep 2018 02:40:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbTrw0Kp2nJlVB/tQHd24Atghtq8DN88lBf3QFGN1uliPcbX7c5TJHd0WFURqglr5oMKNra X-Received: by 2002:a63:25c4:: with SMTP id l187-v6mr27108040pgl.29.1537263633712; Tue, 18 Sep 2018 02:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537263633; cv=none; d=google.com; s=arc-20160816; b=YTr7zH59ePCBYzTJpoeOSq2Y69SKjKcnJZjI1Y9+TqKENIvChvbRzjE/OZ78HKk/t6 Q8UNkrXERQsBblHk2xiYSBnwH2wQOFXcJAzUkAuZEmFBrWxCZSbGusS8np0GhfEiSPax +o51bfgtbJBL7xyuuT0pXFSbp3wNBeYWMRwN822Ixjkzer2qdJOPLQ0OjFqWgYNPt6ZX UT5EmCFzkDnMa8n+pZIMktRg5OVvQ6yXctDDCvCoCGwhhbmRoCBIbKmR9y2RKTg2ehhf bajqv1mGguAzWTR6kymxaHQokDCHaywCcuzGMFc2XbsBXck/p/lUObx4xKR0s6BkGBT7 UFrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=+cBo+7RGjjbbTDqj4aRIea2LJ2OSEnEs7awZ5hD+w0Y=; b=SjWBxDsD12xwqxOjfmMgbx142mtf5I3fOcac7ZGIIfzZ67L/bm4v+Kq+5DAHJ19ZAH vWfqKYSkN0F0R534RF8GusSODujOOlmnuzWl2FrHHk8oVk21x7e9mgJEujnUilGNPg79 EDueHid8hz89G3jwWGY7gP8DbL+lPG9TGeDMX64aiHLeIlwsisgil0bnqJT0Nhk3Ny6u 5wfHqFKcfNnNVWucWLYxRdmMqjBqbH75FnFKABqI8F4xKV9IM3AxZ3Q2yVTR+z/T6204 2Bt0NX74HugDi+L2+YsBmWLD/WJKGNLmnosVFAarGe0PFe1pANDv8lSy84iU480C31oq wfYg== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j8-v6si15064388pll.493.2018.09.18.02.40.17; Tue, 18 Sep 2018 02:40:33 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729945AbeIRPKX (ORCPT + 99 others); Tue, 18 Sep 2018 11:10:23 -0400 Received: from mga01.intel.com ([192.55.52.88]:59400 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729915AbeIRPKW (ORCPT ); Tue, 18 Sep 2018 11:10:22 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Sep 2018 02:38:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,389,1531810800"; d="scan'208";a="71724205" Received: from twinkler-lnx.jer.intel.com ([10.12.91.48]) by fmsmga008.fm.intel.com with ESMTP; 18 Sep 2018 02:38:33 -0700 From: Tomas Winkler To: Jarkko Sakkinen , Jason Gunthorpe Cc: Alexander Usyskin , Tadeusz Struk , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Tomas Winkler Subject: [PATCH v3 17/20] tpm1: implement tpm1_pcr_read_dev() using tpm_buf structure Date: Tue, 18 Sep 2018 12:34:56 +0300 Message-Id: <20180918093459.19165-18-tomas.winkler@intel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180918093459.19165-1-tomas.winkler@intel.com> References: <20180918093459.19165-1-tomas.winkler@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement tpm1_pcr_read_dev() using tpm_buf and remove now unneeded structures from tpm.h Signed-off-by: Tomas Winkler --- V3: new in the series drivers/char/tpm/tpm.h | 18 ++---------------- drivers/char/tpm/tpm1-cmd.c | 38 +++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index d6eca81a011a..d0402aa122ec 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -382,13 +382,10 @@ typedef union { struct tpm_output_header out; } tpm_cmd_header; -struct tpm_pcrread_out { - u8 pcr_result[TPM_DIGEST_SIZE]; +struct tpm_cmd_t { + tpm_cmd_header header; } __packed; -struct tpm_pcrread_in { - __be32 pcr_idx; -} __packed; /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 * bytes, but 128 is still a relatively large number of random bytes and @@ -396,17 +393,6 @@ struct tpm_pcrread_in { * compiler warnings about stack frame size. */ #define TPM_MAX_RNG_DATA 128 -typedef union { - struct tpm_pcrread_in pcrread_in; - struct tpm_pcrread_out pcrread_out; -} tpm_cmd_params; - -struct tpm_cmd_t { - tpm_cmd_header header; - tpm_cmd_params params; -} __packed; - - /* A string buffer type for constructing TPM commands. This is based on the * ideas of string buffer code in security/keys/trusted.h but is heap based * in order to keep the stack usage minimal. diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c index 5708d4bf908f..e81641f9d0e3 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c @@ -574,29 +574,33 @@ int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max) return rc; } -#define TPM_ORDINAL_PCRREAD 21 -#define READ_PCR_RESULT_SIZE 30 -#define READ_PCR_RESULT_BODY_SIZE 20 -static const struct tpm_input_header pcrread_header = { - .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND), - .length = cpu_to_be32(14), - .ordinal = cpu_to_be32(TPM_ORDINAL_PCRREAD) -}; - +#define TPM_ORD_PCRREAD 21 int tpm1_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) { + struct tpm_buf buf; int rc; - struct tpm_cmd_t cmd; - cmd.header.in = pcrread_header; - cmd.params.pcrread_in.pcr_idx = cpu_to_be32(pcr_idx); - rc = tpm_transmit_cmd(chip, NULL, &cmd, READ_PCR_RESULT_SIZE, - READ_PCR_RESULT_BODY_SIZE, 0, + rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_PCRREAD); + if (rc) + return rc; + + tpm_buf_append_u32(&buf, pcr_idx); + + rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, + TPM_DIGEST_SIZE, 0, "attempting to read a pcr value"); + if (rc) + goto out; - if (rc == 0) - memcpy(res_buf, cmd.params.pcrread_out.pcr_result, - TPM_DIGEST_SIZE); + if (tpm_buf_length(&buf) < TPM_DIGEST_SIZE) { + rc = -EFAULT; + goto out; + } + + memcpy(res_buf, &buf.data[TPM_HEADER_SIZE], TPM_DIGEST_SIZE); + +out: + tpm_buf_destroy(&buf); return rc; } -- 2.14.4