Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4997509imm; Tue, 18 Sep 2018 02:39:31 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbIfS5BQuQvi+E35HGAqBz3NFBzkjgG+Q9aVjSDIVzMcuOceNW/yPRJxKUEWDFN+iLyO+mZ X-Received: by 2002:a62:25c5:: with SMTP id l188-v6mr29589237pfl.179.1537263571279; Tue, 18 Sep 2018 02:39:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537263571; cv=none; d=google.com; s=arc-20160816; b=h0iSOB2WpxJfs50nyzC80fvoE46T/Czt7IaQlwojWm8YFH2G4tjnKWTTso58vyf51B ZXcw6AiljmihXFeE6L8AxqI4d0AAd3IHF7innX6iT8QxBBTvA6q9gNeOOHXerSZrV/44 VcM18K5GY9W4OuTEUHxGhzm+/W0KggAdkneOcmCI6aKdJ3Xi268XgInkyeDaQVt7FQus fH+qnKHHVTxK8Sw8WJRC6b2Z0nvqMW82E/AjMORAA0TwuHOZ0Q07CfypaFQTBQC8YgHr hJygsDVexLmEaVA2n94Me+UpFLDqpbp4uAkMw0L5c0p3FZhWzPQRwdJgJPgp2mRuyETL JSEQ== 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=RYmtF7bB3UchA+e6TlrIbSpi9PDuFKnGfpf0/qoHRH0=; b=kNrgybWUJO+vvQBGquBbn0Rh2Zn8pQy+3Vsi2i1fm5DFId9SgILYYlpdA7vv32/kTI C1bvX7ZVu+Q8AuFSg9x9k6z7YXgodXvQ+IHd7LABdcR6QW0zWVbhjeggLtjAnZZmF2+k uUQQsj//T+MhwHMlJ3BarHsXMXI/u7c6SU0suePWSqLgadsOEOZiOMcDEbvtJB8nrFgc BwYDtuwugYyXgvExdehewpxgAqnRxnocyQukYGivc9mcZuS0SbjtqCuBhpOiwQfKroa7 USTB7muFWEsV5AcXlLCTgKvg1Z8s9+dHD2cKuCqX9H4FVmwqGM2MR6SiQiZtEKOIzCYl mUYw== 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 t16-v6si17188501pgi.457.2018.09.18.02.39.16; Tue, 18 Sep 2018 02:39:31 -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 S1729977AbeIRPK2 (ORCPT + 99 others); Tue, 18 Sep 2018 11:10:28 -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 S1729915AbeIRPK1 (ORCPT ); Tue, 18 Sep 2018 11:10:27 -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:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,389,1531810800"; d="scan'208";a="71724216" Received: from twinkler-lnx.jer.intel.com ([10.12.91.48]) by fmsmga008.fm.intel.com with ESMTP; 18 Sep 2018 02:38:37 -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 19/20] tpm1: reimplement SAVESTATE using tpm_buf Date: Tue, 18 Sep 2018 12:34:58 +0300 Message-Id: <20180918093459.19165-20-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 In tpm1_pm_suspend() function reimplement, TPM_ORD_SAVESTATE comamnd using tpm_buf. Signed-off-by: Tomas Winkler --- V3: new in the series 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 777b1158e1b5..c4a0bacb1378 100644 --- a/drivers/char/tpm/tpm1-cmd.c +++ b/drivers/char/tpm/tpm1-cmd.c @@ -719,12 +719,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) -}; /* * We are about to suspend. Save the TPM state @@ -733,18 +727,22 @@ static const struct tpm_input_header savestate_header = { int tpm1_pm_suspend(struct tpm_chip *chip, u32 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); /* @@ -760,6 +758,8 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 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) @@ -769,6 +769,8 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 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