Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1283012imm; Fri, 28 Sep 2018 15:36:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV63gxpf+YmA5ZfjouM7qiIbFKFoQgl+gDbPWnUacVRR6QPgftujSQvJb2LiyL4LqkU2R+11z X-Received: by 2002:a65:5245:: with SMTP id q5-v6mr559159pgp.67.1538174172820; Fri, 28 Sep 2018 15:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538174172; cv=none; d=google.com; s=arc-20160816; b=qAYUSVeub3hFlb6Dnr0cW0hs6ufdO9FOJvplRDzwvSPTLJ3hC6tbHSGdTlE/gpAe+G xvhiwsJGKuOBrOlcr1TVeUcJRuL1One2q6Xpr0Ds14FIxdo/w6k41rDgnmr0y6t++kcK lPyolFhhOLtm3IoqFcrvpyuZ13ComWMLKRHw9Q1IWewloC4kc4CuM0sFiFEdFFsnfgMZ XO90iAS22vDVQcG+ohkyx+3Z9ZRyOdAh+DceRa4BGdZkCtZnCOABUekGSGd0PcTX7ZWq nYFxBWb5joN/G8Ino+Ctp1MHaVMADdWaJIQhB7bGmwlhgs4EFuVOcmrcfLa76cvwcLqq +PuA== 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=o4I+8groiMJx1I5ZNotyCaELysJbKsRXSrOTXPeKEeI=; b=E+TCaZjNycEKpXCRQ8n2k//3Niou1ScsZsxWNXg1ZBL2Z3ZaTDF2OwBF/DfvwzwL8+ UysKi/BDW2Bw0EA3n5/OLnsn57gRX6wt1IFFMlumit4kegpZKBdoQxFeA54kJo1HU6qD 0MEOPraoQcqEsoul1LVxv/sEP1AknSj52GNKZIPNeJY0b0mHGUtTlVPm5zDJI51686Xj POvfTjLQsXLD5ApeVAmfoNVltfsCcAiXQpRJ/HyP8dqdDP1RpeBJyuray2wZ5MPi/+4Q nCuf3WFIBNa4pdrL1uQHvuDzJKV51MtJmYmIf9ARxXujGznpJ0W5OE8cAqrmaZPszwb5 /HJQ== 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 r28-v6si5922771pgb.444.2018.09.28.15.35.58; Fri, 28 Sep 2018 15:36:12 -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 S1727817AbeI2FBY (ORCPT + 99 others); Sat, 29 Sep 2018 01:01:24 -0400 Received: from mga11.intel.com ([192.55.52.93]:9469 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726564AbeI2FBX (ORCPT ); Sat, 29 Sep 2018 01:01:23 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Sep 2018 15:35:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,316,1534834800"; d="scan'208";a="267880337" Received: from twinkler-lnx.jer.intel.com ([10.12.91.48]) by fmsmga006.fm.intel.com with ESMTP; 28 Sep 2018 15:35:28 -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 v5 19/21] tpm1: reimplement SAVESTATE using tpm_buf Date: Sat, 29 Sep 2018 01:30:33 +0300 Message-Id: <20180928223035.14471-20-tomas.winkler@intel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180928223035.14471-1-tomas.winkler@intel.com> References: <20180928223035.14471-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-V5: 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