Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3491714imm; Fri, 19 Oct 2018 11:29:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV62DqlbBkZs4R2QMbYEWf0bFYs/Z69ovjBYr4R6iv5vWUADKz/fXtCS4eQPOlw6smY1OAqc4 X-Received: by 2002:a62:1e83:: with SMTP id e125-v6mr35295597pfe.231.1539973755989; Fri, 19 Oct 2018 11:29:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539973755; cv=none; d=google.com; s=arc-20160816; b=FJ+BwTX8++JqTh9As24IK5ZqRK8lv7u+DX9AwM2ZH8te29bkIOIV8NOKZ9BYh37K2U iOC/vlrvZ3/9Zlmn5hFIytDtZbEE3xFIJ0yAEY7+1CoVZ/FMzrFrFwAR0gLoB+leE1s1 PqbgZhdzo2CfQqhA4QiFB2P/PL9b0+rWTmYqkdsFOZltK1ZvpSyCSVr7jXV5NO9N5KCy l7VxCTpPxYI/o8+pzVE3C87ky6ywtY8Du+Q4Voafh0S4U1+BcejHlDDDGCCb/J0Qq5mV jeXLt69hKSeOfU/6ViMcsAYv/suBEid3nmejW86azW4bLrT/voaPki9+vQ8SFnlYThda hfCw== 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=EfKCTNVpwdU8FnWZFNbFmXBDIo1dytv2fphA13VHd/c=; b=XSRJUk0BcJIxydnR8bGASioR26RrTn7P/N+7i1+edAIf0LAb4VLinje98GPIpd8liy qXLOYtyVdkUTZHRFswLgW5PlmNSCSRtN2vX0FO9fm/Hoxud1SIU3p1LD7MGWGhyLoV9q FopPkQVGl9eDVohWi926eGblT8Gq3BLeHP+/9hS4QTAS1qfwQHy7DjYZwzaLdyOe1tOf I9D/CXCUYepdA7csWGK+uyUCoS23T6XLg6nB7SlE7uRs27horbO8i0DHLg8ZVAJImrrp /8n/Q1+P1NiBB6xRkY0UqyMC0Prt39dBmXhHkEbtoGl+39KuKvp09bHkFSwZmSMDjCZC CvDQ== 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 d12-v6si1288371pgl.200.2018.10.19.11.29.00; Fri, 19 Oct 2018 11:29: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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728227AbeJTCfb (ORCPT + 99 others); Fri, 19 Oct 2018 22:35:31 -0400 Received: from mga01.intel.com ([192.55.52.88]:54192 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727081AbeJTCf3 (ORCPT ); Fri, 19 Oct 2018 22:35:29 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Oct 2018 11:28:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,401,1534834800"; d="scan'208";a="267150372" Received: from twinkler-lnx.jer.intel.com ([10.12.91.48]) by orsmga005.jf.intel.com with ESMTP; 19 Oct 2018 11:28:14 -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 v7 19/21] tpm1: reimplement SAVESTATE using tpm_buf Date: Fri, 19 Oct 2018 21:23:05 +0300 Message-Id: <20181019182307.17745-20-tomas.winkler@intel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181019182307.17745-1-tomas.winkler@intel.com> References: <20181019182307.17745-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-V7: 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 05b772477bac..d418a27a75e0 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c @@ -718,12 +718,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