Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp763901pxb; Tue, 14 Sep 2021 08:14:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH5zw7d3fxIw5k5g5UTGjppQwdEv2UJLq62U2l5Z80jLVgST0uhh9ZR8MLE7G+sKuazW/Q X-Received: by 2002:a6b:ba42:: with SMTP id k63mr14063704iof.37.1631632474964; Tue, 14 Sep 2021 08:14:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631632474; cv=none; d=google.com; s=arc-20160816; b=ecyTChaTySz0dM+mvXBP3sx+81tzadiclaoVaisYb8lG7m7ztH/2KR2g8mvt3+IkRc CPyi8juxRUKuREFyY8Uxr4gbBtIgp14pLHcXCTF/aEXjfSf9uM57MVNX+oEhYCJ34Njj KIq64jHRf8nKc1DEClGZ0jZBX4Rr98E10GnYcNTFpcPSObz+cPdcJGXCVIPPj5BMsofN JsGlKeIFj+HhrhbY623oMsuowOxGsE6WS+ud37T7Ef0LkPOoQr4JP/2AKL9ResWSQeoW oyjOsOjTTG0esgmg5zFmI0yXKamateWLnNNlR3WdrPKi+qtBUneJKZx7BhnIWCL+7dJu /mWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lUqtTH2oAVCzUOSVJl79JS+yMyEK22JIAiIvWRzeqzM=; b=gOBDKCmajgkbPCw0Z0z3FjvDnLUN5t7IWgBEihJMj6YtsWyKZtN8eownJeePr/a8Km IUA+H9Zl/1axLkyU53bpcuBhOAccjK44FYtv7UbRIjVCZgPyC3+3L4fI08RwyDrqx1xt XZ/Y6RG0NkfUf0ziTSsgG/ie8V3AiawjKedgpVvwYNptRT55SSf4hpH2sE6TR8kFyiVQ ZRKhKTg+FOIEjVWPWhIoIJlAVwn8whmY+XdattSB7LvGjbxLqJ98hRJ4DZmn/IeDY1aM WOWZRPwch1iSQpeg/XtRyX8zMEEp7NaXdMdQst2ijzI9xwIPu1UVd/zAA4ppWBiWuKAT DJQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f17si5586154iow.57.2021.09.14.08.14.17; Tue, 14 Sep 2021 08:14:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234388AbhINPOp (ORCPT + 99 others); Tue, 14 Sep 2021 11:14:45 -0400 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:43285 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S234151AbhINPOk (ORCPT ); Tue, 14 Sep 2021 11:14:40 -0400 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 18EFAmXl031450; Tue, 14 Sep 2021 18:10:48 +0300 Received: by taln60.nuvoton.co.il (Postfix, from userid 10140) id 2FF7263A19; Tue, 14 Sep 2021 18:10:59 +0300 (IDT) From: amirmizi6@gmail.com To: Eyal.Cohen@nuvoton.com, jarkko@kernel.org, oshrialkoby85@gmail.com, alexander.steffen@infineon.com, robh+dt@kernel.org, mark.rutland@arm.com, peterhuewe@gmx.de, jgg@ziepe.ca, arnd@arndb.de, gregkh@linuxfoundation.org, benoit.houyere@st.com, eajames@linux.ibm.com, joel@jms.id.au Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, oshri.alkoby@nuvoton.com, tmaimon77@gmail.com, gcwilson@us.ibm.com, kgoldman@us.ibm.com, Dan.Morav@nuvoton.com, oren.tanami@nuvoton.com, shmulik.hager@nuvoton.com, amir.mizinski@nuvoton.com, Amir Mizinski Subject: [PATCH v15 4/6] tpm: tpm_tis: verify TPM_STS register is valid after locality request Date: Tue, 14 Sep 2021 18:10:30 +0300 Message-Id: <20210914151032.216122-5-amirmizi6@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20210914151032.216122-1-amirmizi6@gmail.com> References: <20210914151032.216122-1-amirmizi6@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Amir Mizinski This issue could occur when the TPM does not update TPM_STS register after a locality request (TPM_STS Initial value = 0xFF) and a TPM_STS register read occurs in the tpm_tis_status(chip) function call. When a call to tpm_tis_send_data() function is made after a request_locality() call, the condition ("if ((status & TPM_STS_COMMAND_READY) == 0)") is checked. At this moment if the status value is 0xFF, then it is considered, wrongly, in “ready” state (by checking only one bit). However, at this moment the TPM is, in fact, in "Idle" state and remains in "Idle" state because "tpm_tis_ready(chip);" was not executed. Waiting for the condition TPM_STS.tpmGo == 0, will ensure that the TPM status register has the correct value. Suggested-by: Benoit Houyere Signed-off-by: Amir Mizinski --- drivers/char/tpm/tpm_tis_core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 7ea7f64..f340a44 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -177,8 +177,14 @@ static int request_locality(struct tpm_chip *chip, int l) } else { /* wait for burstcount */ do { - if (check_locality(chip, l)) + if (check_locality(chip, l)) { + if (wait_for_tpm_stat(chip, TPM_STS_GO, 0, + chip->timeout_c, + &priv->int_queue, + false) < 0) + return -ETIME; return l; + } tpm_msleep(TPM_TIMEOUT); } while (time_before(jiffies, stop)); } -- 2.7.4