Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp707053imm; Fri, 21 Sep 2018 07:03:25 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda79aqTq/qvcSsgjCMXyyIxe7/I8BkIZHrfG/xQBPp83T/VSXlsU7XLeQnrBWeXw6XcebHU X-Received: by 2002:a63:ad44:: with SMTP id y4-v6mr41304942pgo.138.1537538605613; Fri, 21 Sep 2018 07:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537538605; cv=none; d=google.com; s=arc-20160816; b=AS2UKwPCdwatBTF17llYdLHN0R+FykPbUij4yhBpUvjxp0DU2OFPMXEjPqeo6igiyD 5OgxH6iLSqcDBEYJ3DNTRRZF0Lz6mDCTjLqNxjDycSpt1NdhU0wP7Q+hibaf/Fl0+hYY gWQ2QDlrFXCp4IfXFRuLGD8+tTtKnHzj8Q8G6WCbOyXBhs/6Q6wBl4otIq1H1L5E4hnH fDtku0oJJ0SueU4xAiQEHhsgxNhhpva3qg1CNAKr84/dHyFNt5TFkidTF7+wgn/v3uXJ vJilrx4LPywX4S+unJxlkzlPWuwtoPCZA+Yje6qj9T4n0CNC5B6BspwuDe4vk2dRldMB SF0g== 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=5VAK1e1NtE68EWyH5UqPjTcKDfRKDYTkq2RjEVfzNSU=; b=prdbxsRkOw5aGx2sjPtGtTYiUCrkGF6fIx8CJG7D5SiS1f56jA23oxeoqJltdkyGct SyZtBroCWp5IjU4Fjt2zO06Cvt+3eInptoYtsbvlmYsKgLY8IuAw2FpWyJbGZZZgd+aR xPoFoTazFhkjkzB2mbkQ0EVr85HMAX9HvcSzz85G+D5C9wpxeC4LBV2n0ohF/U0meuxC ldEBpNWO9D70+dGbeg2WmEMZ6hTivJoxHV8ROjzWEzulGFt2AbPBJuMN5ze9t6SKsPcU Mik1t6aC7WtEhtGhgiy/rOHT/Xhq8g8/nfiMWki1pqdaKoWNxBZsAJB0U32SubeaE1AJ 8uRw== 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 w3-v6si24789554pgp.220.2018.09.21.07.03.05; Fri, 21 Sep 2018 07:03:25 -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 S2390525AbeIUTvi (ORCPT + 99 others); Fri, 21 Sep 2018 15:51:38 -0400 Received: from mga18.intel.com ([134.134.136.126]:4682 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389586AbeIUTvh (ORCPT ); Fri, 21 Sep 2018 15:51:37 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2018 07:02:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,285,1534834800"; d="scan'208";a="71839225" Received: from twinkler-lnx.jer.intel.com ([10.12.91.48]) by fmsmga007.fm.intel.com with ESMTP; 21 Sep 2018 07:02: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 v4 19/21] tpm1: reimplement SAVESTATE using tpm_buf Date: Fri, 21 Sep 2018 16:58:18 +0300 Message-Id: <20180921135820.20549-20-tomas.winkler@intel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180921135820.20549-1-tomas.winkler@intel.com> References: <20180921135820.20549-1-tomas.winkler@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In tpm1_pm_suspend() function reimplement, TPM_ORD_SAVESTATE comamnd using tpm_buf. Signed-off-by: Tomas Winkler Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen --- V3: New in the series. V4: Resend. drivers/char/tpm/tpm1-cmd.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c index ef37c91b6844..cde9a01ad31f 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c @@ -720,12 +720,6 @@ int tpm1_auto_startup(struct tpm_chip *chip) } #define TPM_ORD_SAVESTATE 152 -#define SAVESTATE_RESULT_SIZE 10 -static const struct tpm_input_header savestate_header = { - .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND), - .length = cpu_to_be32(10), - .ordinal = cpu_to_be32(TPM_ORD_SAVESTATE) -}; /** * tpm1_pm_suspend() - pm suspend handler @@ -739,18 +733,22 @@ static const struct tpm_input_header savestate_header = { int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr) { u8 dummy_hash[TPM_DIGEST_SIZE] = { 0 }; - struct tpm_cmd_t cmd; - int rc, try; + struct tpm_buf buf; + unsigned int try; + int rc; + /* for buggy tpm, flush pcrs with extend to selected dummy */ if (tpm_suspend_pcr) rc = tpm1_pcr_extend(chip, tpm_suspend_pcr, dummy_hash, "extending dummy pcr before suspend"); + rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_SAVESTATE); + if (rc) + return rc; /* now do the actual savestate */ for (try = 0; try < TPM_RETRY; try++) { - cmd.header.in = savestate_header; - rc = tpm_transmit_cmd(chip, NULL, &cmd, SAVESTATE_RESULT_SIZE, + rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, 0, 0, NULL); /* @@ -766,6 +764,8 @@ int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr) if (rc != TPM_WARN_RETRY) break; tpm_msleep(TPM_TIMEOUT_RETRY); + + tpm_buf_reset(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_SAVESTATE); } if (rc) @@ -775,6 +775,8 @@ int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr) dev_warn(&chip->dev, "TPM savestate took %dms\n", try * TPM_TIMEOUT_RETRY); + tpm_buf_destroy(&buf); + return rc; } -- 2.14.4