Message ID | 20240131170824.6183-3-dpsmith@apertussolutions.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-46876-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp2032953dyb; Wed, 31 Jan 2024 09:11:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtgE0XjpPHqO0QoNnDpjbaswwk45sAwopWmp1PNqnJshIf/YRED0mh/t2e1rOQ7CENP3sw X-Received: by 2002:ac8:57c8:0:b0:42a:b0b6:1ca6 with SMTP id w8-20020ac857c8000000b0042ab0b61ca6mr2310349qta.64.1706721089303; Wed, 31 Jan 2024 09:11:29 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1706721089; cv=pass; d=google.com; s=arc-20160816; b=OpFMznVyHMskOW2tSBOaEO1XW/TR/mrlhmuGVitgjemCYnvUUCNhcSKG2rS7SejzXv PeltxsloBx+5JEgLhTEsCEzBbQbkuWYn7ZKQhfUsqlHFuhl5Nr8Tdd9oPKGFP539CARP Zdhy67tJD4nHoixkS4veBAVAlWoQKfdIaOHen+DloDxxnbUrT3fMBhRfJOl7PEL90lQ8 irXo5X0AFg+8tCrfAu71GVWb0HS2iGgQtbhP91XYozOku5dDXaQXspxsPk/oqu4CLPm5 l10ChAoKSe9gM559BjgsRem6nDQglhhVHi1JmMS4gmH4GpKYS4aS7vAr9KXrp/O/lRAk kpDA== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:delivered-to; bh=qy+lvF7GALRrQcNMzdxUYaDVhh02/KHKHqHE2SY4zeM=; fh=Z+bV+iXsVeM2sokFzh6I+WjbLY0PE4hsFWyegyict/Q=; b=HwpAvT3iBMQx/VZifUzFBQiTr34vNTI+DkcQAWK9CT8z7ep3WO1YwnIwhb8Fwh9fmx LcvHU4UwCgUhDH9MxVRjarRZT7yCqyKRuLVBgMCbl6+Xu2XNoMJTM8pcRU0FLfJ5t2mQ IM84G1MKn/nNyxg6qx0Capk4uYRWsADHv+rdOPr1ZE2ha7CAcI0RMvA60McI70/Ima9t Gb9eaLVCcXtVe8RG9sBiBC1MeprqVpRTNshhZZ1xh+X8CaS099hTi9MqpDcp/+VcA2u+ a1J6bn6ffU7biiGbLHj30yGSAKvzGLtTK0Oy4kO0dVmbMuwKjnrMM9YrjNlZRij5lW03 d4xA==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@apertussolutions.com header.s=zoho header.b="QKEK/gQH"; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-46876-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46876-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCW0XLSh8YlWzOgRRteH7yal2Ta3cOCv+UtMyahL8Qf0GLLzzp1YXpwE7mLOHla6O20YtOe+1TSvk8pQ8UuF40a9fI9Vkg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a19-20020a05622a02d300b0042a9b0a246bsi8786675qtx.285.2024.01.31.09.11.29 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 09:11:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46876-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@apertussolutions.com header.s=zoho header.b="QKEK/gQH"; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-46876-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46876-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 003311C20D84 for <ouuuleilei@gmail.com>; Wed, 31 Jan 2024 17:11:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88EC4130E5B; Wed, 31 Jan 2024 17:09:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=apertussolutions.com header.i=dpsmith@apertussolutions.com header.b="QKEK/gQH" Received: from sender4-of-o50.zoho.com (sender4-of-o50.zoho.com [136.143.188.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07EE712CD9D; Wed, 31 Jan 2024 17:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706720939; cv=pass; b=KoFFNpuMDgxp82KytIyKYrGeju8sQBLC4wI0AKNPYHf4yt95GYux8wXb77d0jFtAeSOU3CyfmCNupoHKBbGgOPT9U8LtH4YAVyBVCIUVbfPLE7wvlkSMVW5L3A7Yh7nZCoQftpHOePPRd3/ah/QVqh+8hAKPuFZ2x9pC414l1tU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706720939; c=relaxed/simple; bh=4KBntWU1blLLw3C630GBwTov4hAWEfv+DbWCCvwUS3E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DF5naJ5yyO8JVuSvoz/LLnTIxht0hum2sgbPxdRAuXyoGUyXNENeY1+KLxxesRCoS3bA0fdYKnVTNuhdPJwBYrWaIZZXWw+9XltzA28divDsheFcWPt9jrLHD1Wovsxn/oHCc3gBlN7rkMlZa2u6D/5Vcb31/o1CqeEgxxo5Wb4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=apertussolutions.com; spf=pass smtp.mailfrom=apertussolutions.com; dkim=pass (1024-bit key) header.d=apertussolutions.com header.i=dpsmith@apertussolutions.com header.b=QKEK/gQH; arc=pass smtp.client-ip=136.143.188.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=apertussolutions.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=apertussolutions.com Delivered-To: dpsmith@apertussolutions.com ARC-Seal: i=1; a=rsa-sha256; t=1706720918; cv=none; d=zohomail.com; s=zohoarc; b=TigL/EDKYbWiexgIWBY4p9mtoP7CT+SxHxFrqk+5Cu3SBZpyMsBk6vNd9x1S44ifE1GB5HaStua4u5QkUwdVE5QNxLoRA53BzMQtr7MNMoRFtARLosBAtmLcs4RbD0m+o+F4KYjx3+ghb+JWeJ+XVrWoP/AHp1E8ZnihefPta48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706720918; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=qy+lvF7GALRrQcNMzdxUYaDVhh02/KHKHqHE2SY4zeM=; b=FLG1qXfX15wgFjen94KAKvwW1I9D3Oa524yVcD3etXYJ8J+UCp3pqk+60VbVx/LJKFhDBKeaBokVAnSGxa30TwSfoudvJFU4sz9c45T+y1T1vhs2OSCsYFTxGlfGgb6WUUkQVGr0ny6/HYUV9m8k76nGhbHBrpfDU7DZSJW5U60= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@apertussolutions.com; dmarc=pass header.from=<dpsmith@apertussolutions.com> DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1706720918; s=zoho; d=apertussolutions.com; i=dpsmith@apertussolutions.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=qy+lvF7GALRrQcNMzdxUYaDVhh02/KHKHqHE2SY4zeM=; b=QKEK/gQHDZmGw+oPs0FKy0rXaHj/D7n+HL8+Ym2aX8p4xK2zFRO+mpXwSrro3C8X xqPShwk9XbrZKfJpbMXvS5aSzN/VStre1DrsyaHpwZu60kCSBjlbognONUieQ198khd xE51kzkHDouN2dGhkgzJTIZrKXl+KlLZMtVkJJwY= Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1706720917763245.2481735163061; Wed, 31 Jan 2024 09:08:37 -0800 (PST) From: "Daniel P. Smith" <dpsmith@apertussolutions.com> To: Jason Gunthorpe <jgg@ziepe.ca>, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Daniel P. Smith" <dpsmith@apertussolutions.com>, Ross Philipson <ross.philipson@oracle.com>, Peter Huewe <peterhuewe@gmx.de>, Jarkko Sakkinen <jarkko@kernel.org> Subject: [PATCH 2/3] tpm: ensure tpm is in known state at startup Date: Wed, 31 Jan 2024 12:08:22 -0500 Message-Id: <20240131170824.6183-3-dpsmith@apertussolutions.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240131170824.6183-1-dpsmith@apertussolutions.com> References: <20240131170824.6183-1-dpsmith@apertussolutions.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-ZohoMailClient: External X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789626773001503266 X-GMAIL-MSGID: 1789626773001503266 |
Series |
[1/3] tpm: protect against locality counter underflow
|
|
Commit Message
Daniel P. Smith
Jan. 31, 2024, 5:08 p.m. UTC
When tis core initializes, it assumes all localities are closed. There are cases when this may not be the case. This commit addresses this by ensuring all localities are closed before initializing begins. Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com> Signed-off-by: Ross Philipson <ross.philipson@oracle.com> --- drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++- include/linux/tpm.h | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
Comments
On Wed Jan 31, 2024 at 7:08 PM EET, Daniel P. Smith wrote: > When tis core initializes, it assumes all localities are closed. There ~~~~~~~~ tpm_tis_core > are cases when this may not be the case. This commit addresses this by > ensuring all localities are closed before initializing begins. Remove the last sentence and replace with this paragraph: "Address this by ensuring all the localities are closed in the beginning of tpm_tis_core_init(). There are environments, like Intel TXT, which may leave a locality open. Close all localities to start from a known state." BTW, why we should motivated to take this patch anyway? Since the patch is not marked as a bug fix the commit message must pitch why it is important to care. > Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com> > Signed-off-by: Ross Philipson <ross.philipson@oracle.com> > --- > drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++- > include/linux/tpm.h | 6 ++++++ > 2 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c > index 4176d3bd1f04..5709f87991d9 100644 > --- a/drivers/char/tpm/tpm_tis_core.c > +++ b/drivers/char/tpm/tpm_tis_core.c > @@ -1109,7 +1109,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, > u32 intmask; > u32 clkrun_val; > u8 rid; > - int rc, probe; > + int rc, probe, i; > struct tpm_chip *chip; > > chip = tpmm_chip_alloc(dev, &tpm_tis); > @@ -1170,6 +1170,15 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, > goto out_err; > } > > + /* > + * There are environments, like Intel TXT, that may leave a TPM > + * locality open. Close all localities to start from a known state. > + */ > + for (i = 0; i <= TPM_MAX_LOCALITY; i++) { > + if (check_locality(chip, i)) > + tpm_tis_relinquish_locality(chip, i); > + } > + > /* Take control of the TPM's interrupt hardware and shut it off */ > rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); > if (rc < 0) > diff --git a/include/linux/tpm.h b/include/linux/tpm.h > index 4ee9d13749ad..abe0d44d00ee 100644 > --- a/include/linux/tpm.h > +++ b/include/linux/tpm.h > @@ -116,6 +116,12 @@ struct tpm_chip_seqops { > const struct seq_operations *seqops; > }; > > +/* > + * The maximum locality (0 - 4) for a TPM, as defined in section 3.2 of the > + * Client Platform Profile Specification. > + */ > +#define TPM_MAX_LOCALITY 4 > + > struct tpm_chip { > struct device dev; > struct device devs; Is there a dependency to 1/3? BR, Jarkko
On 2/1/24 17:33, Jarkko Sakkinen wrote: > On Wed Jan 31, 2024 at 7:08 PM EET, Daniel P. Smith wrote: >> When tis core initializes, it assumes all localities are closed. There > ~~~~~~~~ > tpm_tis_core > >> are cases when this may not be the case. This commit addresses this by >> ensuring all localities are closed before initializing begins. > > Remove the last sentence and replace with this paragraph: > > "Address this by ensuring all the localities are closed in the beginning > of tpm_tis_core_init(). There are environments, like Intel TXT, which > may leave a locality open. Close all localities to start from a known > state." okay. > BTW, why we should motivated to take this patch anyway? Without this change, in this scenario the driver is unnecessarily thrashing the TPM with locality requests/relinquishes pairs for which will never take effect and that the TPM must do state change tracking. While I am confident that TPM chips are resilient to such abuse, I do not think it would be good form to knowingly allow such behavior to occur. > Since the patch is not marked as a bug fix the commit message must pitch > why it is important to care. As far as I am aware, the TPM driver has always made this assumption, so I guess it could be written as a bug against the first commit of the driver. The reality is that it is more the case that the TPM driver has never completely supported higher localities. While there has been logic to support localities interface, the driver has always been hard wired to use locality 0. Basically, this change makes the TPM driver function correctly when multiple localities are in use. I can write it up either way, just let me know. >> Signed-off-by: Daniel P. Smith <dpsmith@apertussolutions.com> >> Signed-off-by: Ross Philipson <ross.philipson@oracle.com> >> --- >> drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++- >> include/linux/tpm.h | 6 ++++++ >> 2 files changed, 16 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c >> index 4176d3bd1f04..5709f87991d9 100644 >> --- a/drivers/char/tpm/tpm_tis_core.c >> +++ b/drivers/char/tpm/tpm_tis_core.c >> @@ -1109,7 +1109,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, >> u32 intmask; >> u32 clkrun_val; >> u8 rid; >> - int rc, probe; >> + int rc, probe, i; >> struct tpm_chip *chip; >> >> chip = tpmm_chip_alloc(dev, &tpm_tis); >> @@ -1170,6 +1170,15 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, >> goto out_err; >> } >> >> + /* >> + * There are environments, like Intel TXT, that may leave a TPM >> + * locality open. Close all localities to start from a known state. >> + */ >> + for (i = 0; i <= TPM_MAX_LOCALITY; i++) { >> + if (check_locality(chip, i)) >> + tpm_tis_relinquish_locality(chip, i); >> + } >> + >> /* Take control of the TPM's interrupt hardware and shut it off */ >> rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); >> if (rc < 0) >> diff --git a/include/linux/tpm.h b/include/linux/tpm.h >> index 4ee9d13749ad..abe0d44d00ee 100644 >> --- a/include/linux/tpm.h >> +++ b/include/linux/tpm.h >> @@ -116,6 +116,12 @@ struct tpm_chip_seqops { >> const struct seq_operations *seqops; >> }; >> >> +/* >> + * The maximum locality (0 - 4) for a TPM, as defined in section 3.2 of the >> + * Client Platform Profile Specification. >> + */ >> +#define TPM_MAX_LOCALITY 4 >> + >> struct tpm_chip { >> struct device dev; >> struct device devs; > > Is there a dependency to 1/3? There is no direct dependency between these patches, but 1 and 2 are necessary to resolve the issue at hand while 3 corrects the return value behavior of the locality request function. v/r, dps
On Mon Feb 19, 2024 at 7:17 PM UTC, Daniel P. Smith wrote: > On 2/1/24 17:33, Jarkko Sakkinen wrote: > > On Wed Jan 31, 2024 at 7:08 PM EET, Daniel P. Smith wrote: > >> When tis core initializes, it assumes all localities are closed. There > > ~~~~~~~~ > > tpm_tis_core > > > >> are cases when this may not be the case. This commit addresses this by > >> ensuring all localities are closed before initializing begins. > > > > Remove the last sentence and replace with this paragraph: > > > > "Address this by ensuring all the localities are closed in the beginning > > of tpm_tis_core_init(). There are environments, like Intel TXT, which > > may leave a locality open. Close all localities to start from a known > > state." > > okay. > > > BTW, why we should motivated to take this patch anyway? > > Without this change, in this scenario the driver is unnecessarily > thrashing the TPM with locality requests/relinquishes pairs for which > will never take effect and that the TPM must do state change tracking. > While I am confident that TPM chips are resilient to such abuse, I do > not think it would be good form to knowingly allow such behavior to occur. This would a factor better motivation part for the commit. I can buy this argument instead the one right now, thanks :-) BR, Jarkko
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 4176d3bd1f04..5709f87991d9 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1109,7 +1109,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, u32 intmask; u32 clkrun_val; u8 rid; - int rc, probe; + int rc, probe, i; struct tpm_chip *chip; chip = tpmm_chip_alloc(dev, &tpm_tis); @@ -1170,6 +1170,15 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } + /* + * There are environments, like Intel TXT, that may leave a TPM + * locality open. Close all localities to start from a known state. + */ + for (i = 0; i <= TPM_MAX_LOCALITY; i++) { + if (check_locality(chip, i)) + tpm_tis_relinquish_locality(chip, i); + } + /* Take control of the TPM's interrupt hardware and shut it off */ rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); if (rc < 0) diff --git a/include/linux/tpm.h b/include/linux/tpm.h index 4ee9d13749ad..abe0d44d00ee 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -116,6 +116,12 @@ struct tpm_chip_seqops { const struct seq_operations *seqops; }; +/* + * The maximum locality (0 - 4) for a TPM, as defined in section 3.2 of the + * Client Platform Profile Specification. + */ +#define TPM_MAX_LOCALITY 4 + struct tpm_chip { struct device dev; struct device devs;