Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp305207imm; Tue, 16 Oct 2018 23:51:57 -0700 (PDT) X-Google-Smtp-Source: ACcGV6285D/GoouK5ilrlJ/YQ5qBc8HQ++2nZKTWD0ELOVDsEFQPSlDoBvwX5rdxfNy2daMrFwal X-Received: by 2002:a63:1c1b:: with SMTP id c27-v6mr23488119pgc.351.1539759117684; Tue, 16 Oct 2018 23:51:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539759117; cv=none; d=google.com; s=arc-20160816; b=ZluDyuALtdKyuY39HYOMSY/Xz+O9UhtSaFvIA8MaJQkT8BJi7ZupRYEqak5XXQiRYo 4DOYR2yADho7HoUwdHZdRIffMhY0f6VD3aeO+MqZR6IHC5MYt2J2l9052Nv3Pe2EeRcK SKABaYlIjS65e+4lbjI9gS50w8HJucO4TPamq4VTI/ydl9UGHpDISMH8b51v+2Ys+HnB ro90g0+kDsDRrGACwboXpbzcBI+Nkf+2Kk23nS8wSfoNPm3tYZQBE8NZEuvR+grsrqCs jSWJkWrd+cBjulB7i2zxrCUpn8JMcyzbf2bu+BwJj3UYNokxDGL6lCRUyAqT1h3ETdfD UHhw== 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=IHg+wXQnmrw+UudGWebXJxGXfk1LGKeD79P3ljnfHBc=; b=NBx5tOW8p/C6aM9tB4J+WDVaCZZa2YduPajjdkjmyY1NbMFLY8T3j6T2ewy6QFg77s QMUoVGSvKe6Yek+isdf7b+iLmcJw/mEh+Dns6hJD27ifH97u1G5WWspC2uT2w7JlwfIK mTW/Z7FB4mCgRPNbJiI8v4pnA2oB43dIf658vCuA21Z307UPnMC/2cCNGBf4p30wSDTJ OSGl7drkf1BbDKhK6CO8lM9JS19v/6+mZOfp9vosOUYNF9Ojx05HK1AYDYJ154WuT2YR N0EklVfCzerEDuYexUG9UnDUrnCsDG9GpRIlex2XY+PAK5p4jNrrA/MibQfaOTXAOLu0 S+Ig== 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 29-v6si16793055pgl.104.2018.10.16.23.51.42; Tue, 16 Oct 2018 23:51:57 -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 S1727804AbeJQOpL (ORCPT + 99 others); Wed, 17 Oct 2018 10:45:11 -0400 Received: from mga11.intel.com ([192.55.52.93]:48122 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727570AbeJQOpK (ORCPT ); Wed, 17 Oct 2018 10:45:10 -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 fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2018 23:50:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,391,1534834800"; d="scan'208";a="79371319" Received: from twinkler-lnx.jer.intel.com ([10.12.91.48]) by fmsmga008.fm.intel.com with ESMTP; 16 Oct 2018 23:50:53 -0700 From: Tomas Winkler To: Jarkko Sakkinen , Jason Gunthorpe Cc: Nayna Jain , Alexander Usyskin , Tadeusz Struk , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Tomas Winkler Subject: [PATCH v6 16/20] tpm1: implement tpm1_pcr_read_dev() using tpm_buf structure Date: Wed, 17 Oct 2018 09:46:09 +0300 Message-Id: <20181017064613.19746-17-tomas.winkler@intel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181017064613.19746-1-tomas.winkler@intel.com> References: <20181017064613.19746-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 Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen --- V3: New in the series. V4-V6: Resend. 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 6895f183396b..51d147675b1f 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 b5c4fa158c30..d30f336518f6 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c @@ -571,29 +571,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