From patchwork Mon May 10 12:28:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 12247997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F281C433B4 for ; Mon, 10 May 2021 13:17:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33CFA611CA for ; Mon, 10 May 2021 13:17:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235877AbhEJNQ5 (ORCPT ); Mon, 10 May 2021 09:16:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:41188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242920AbhEJM3p (ORCPT ); Mon, 10 May 2021 08:29:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8E63361432; Mon, 10 May 2021 12:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620649719; bh=+r27oHZ1a/tQTDcHtEZoHK25erNJaGMCMvSY8xQQE44=; h=From:To:Cc:Subject:Date:From; b=R4raJGkfjmUstqpiDFgvi85Tk3cHQDR9P1AqLYGVGZ1T+suKkJ3P8k73yhC5kXOvh PUZn+lYorbrWTSUwg7xQluGeXuzbDAkGYFhemk/MVyUTJ7wqcKBIiD/sKf3LLixQZn 8WX/FIsIta6sTAy2vE5dzexiAqfhDAgQ7sJWnu1Iki5jGAF/ZJbCHFoayXjK6cCibq E/hbKJOeAHwVPpCSt5jyzEDimMh6jp1ixb9u5UEewR6XDMi+aiFrCGieSgwWoWSEWl txZPW8liKfoVLCtUUWAyWXM4ICr9SEgmJ9v0wLslTwvLeNZ9Sph/9Ty2Rk74SDRMEu s5KfdTa6/P99A== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Jarkko Sakkinen , Hans de Goede , stable@vger.kernel.org, Lino Sanfilippo , Peter Huewe , Jason Gunthorpe , James Bottomley , Stefan Berger , Jerry Snitselaar Subject: [PATCH 1/2] tpm, tpm_tis: Extend locality handling to TPM2 in tpm_tis_gen_interrupt() Date: Mon, 10 May 2021 15:28:30 +0300 Message-Id: <20210510122831.409608-1-jarkko@kernel.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org The earlier fix (linked) only partially fixed the locality handling bug in tpm_tis_gen_interrupt(), i.e. only for TPM 1.x. Extend the locality handling to cover TPM2. Cc: Hans de Goede Cc: stable@vger.kernel.org Link: https://lore.kernel.org/linux-integrity/20210220125534.20707-1-jarkko@kernel.org/ Fixes: a3fbfae82b4c ("tpm: take TPM chip power gating out of tpm_transmit()") Reported-by: Lino Sanfilippo Signed-off-by: Jarkko Sakkinen Tested-by: Lino Sanfilippo --- v1: * Testing done with Intel NUC5i5MYHE with SLB9665 TPM2 chip. drivers/char/tpm/tpm_tis_core.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index a2e0395cbe61..6fa150a3b75e 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -709,16 +709,14 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip) cap_t cap; int ret; - /* TPM 2.0 */ - if (chip->flags & TPM_CHIP_FLAG_TPM2) - return tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); - - /* TPM 1.2 */ ret = request_locality(chip, 0); if (ret < 0) return ret; - ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); + if (chip->flags & TPM_CHIP_FLAG_TPM2) + ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); + else + ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0); release_locality(chip, 0); From patchwork Mon May 10 12:28:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 12247999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B28DFC43460 for ; Mon, 10 May 2021 13:17:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D285611CA for ; Mon, 10 May 2021 13:17:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236338AbhEJNRL (ORCPT ); Mon, 10 May 2021 09:17:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:41244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242982AbhEJM3r (ORCPT ); Mon, 10 May 2021 08:29:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 397BB6145F; Mon, 10 May 2021 12:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620649722; bh=thmzAZf9iH1VveaS5sV5nVLiuryScGt+oyOOrDw29CU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mLBIEcPUQJhjcz4rMbIwrQzGJBkXmoSKFgV9EI65vdWAGAlLZ/a3ZXoeg78ToOJ4u XJafKPZ1EAarQoTIa/H9Ls/tCOMGm/0tmnS9bw9/l2xvnla/BkC64brhvH8qy01YDw 8mXjTKRLwjI9f3vvDr0lP6rKb7AqpWou4euSufNz0Hrz6V/ORdRmmlETKA8XMiIPVn ofr4LSItR/eTQpvXQwwETsFk9jB02a7K9K4IL1J1n5uG1kFSF4jHFUT0zyQD7fGvW0 SzFjIYSnXEt5Mm9pDzLnrG+sgq16e+0USjre8BGxUt7JmDEX7OFBB/nlJ9ALbiY6EF /D1q53f6e9eXw== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Jarkko Sakkinen , Hans de Goede , Lino Sanfilippo , stable@vger.kernel.org, Peter Huewe , Jason Gunthorpe , Stefan Berger , James Bottomley , Jerry Snitselaar Subject: [PATCH 2/2] tpm, tpm_tis: Reserve locality in tpm_tis_resume() Date: Mon, 10 May 2021 15:28:31 +0300 Message-Id: <20210510122831.409608-2-jarkko@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510122831.409608-1-jarkko@kernel.org> References: <20210510122831.409608-1-jarkko@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Reserve locality in tpm_tis_resume(), as it could be unsert after waking up from a sleep state. Reported-by: Hans de Goede Cc: Lino Sanfilippo Cc: stable@vger.kernel.org Fixes: a3fbfae82b4c ("tpm: take TPM chip power gating out of tpm_transmit()") Signed-off-by: Jarkko Sakkinen --- v1: * Testing done with Intel NUC5i5MYHE containing SLB9665 TPM 2.0 chip. * The used test case: "echo mee | sudo tee /sys/power/state" executed without issues. drivers/char/tpm/tpm_tis_core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 6fa150a3b75e..55b9d3965ae1 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1125,12 +1125,20 @@ int tpm_tis_resume(struct device *dev) if (ret) return ret; - /* TPM 1.2 requires self-test on resume. This function actually returns + /* + * TPM 1.2 requires self-test on resume. This function actually returns * an error code but for unknown reason it isn't handled. */ - if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) { + ret = request_locality(chip, 0); + if (ret < 0) + return ret; + tpm1_do_selftest(chip); + release_locality(chip, 0); + } + return 0; } EXPORT_SYMBOL_GPL(tpm_tis_resume);