Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1815264rdb; Wed, 31 Jan 2024 09:49:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlomHmWPUjO2KpbZZTIQzHVZJth0Q/MLjMeieKxfg3/0C4Il/Is3JRqtF6QFycj8rdXBn1 X-Received: by 2002:a05:6358:d39b:b0:176:5cad:a2e1 with SMTP id mp27-20020a056358d39b00b001765cada2e1mr2638801rwb.26.1706723366223; Wed, 31 Jan 2024 09:49:26 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1706723366; cv=pass; d=google.com; s=arc-20160816; b=TThXVpjb4pxQzcxYGCCniJ5LaxZO2n/Z5gWODGNrLkb57XNz9e2vxpC6qvLshaIbNf /hg7p8KXl2qI2qTw7a6J1Wgy0gSK6mw9q8iB9q1WYc//lx+XkQaf5Y30CFATTS7LmOJp mnSEMQRTnXDX+7AkHVswD81hNRKe5Mlr4FmZdVL+sP8zZA2NYt7cZ0G5uhemWjw3cQg5 8qy3D8huORdFI96e1FlhOTVYCo5U0tqwujdK729fJaMUBnZV07L7Bs7T/j6nOEQee2m3 +byXYlOM3trcKFn533mRdTGqooiq8SptaiUOkIg2WMHP2zuYh9Qlb/1uDvzqwBvyJ/QY A6qw== 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=x66V+f9AWY5YByD7SARYBfM+ML74WG/9XQhKZC03OII=; b=Cy3Rfg5XZYFs9w510MNKK81YxecGL3cMN62GE0oQ0/hRYJRmPaGsvVfzJdmbrI1Bi3 ww3nJrQ/1oNEBl0f5KDz1nOzUA7bMojft4cPfpwtPX37ycaxHh4gV2XnWBjMIMn4n2gH /Y6qTcYe/5ArPiEwtJM4jUYeA0rgR51v+A1Sf0rQy7xaDSS6OGgntQa6gCBB6nTxkIuZ NqhVUJaKi1i1F+YGuR4zSPM0l2qk4hlZcyg97PjbrSGF8aEQfbassQlzLb+HdeKyC2nA NQl+15pDogKvZ5yD710rKhmMsLX+g6pWsGHpLMbz04gph5OJf4/wxR1xNgQxXMu7A4qr uktw==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46876-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXImXBn/Ju7c2l5xE24VNKm4FMGwEJj227GvtcGD7ZIrzk3Xt+IAtX1cNQ1uxCn3ZL1cNTYAEJoMCDtXLZEMEzh5RoXDG5thCk7BAPR3w== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b30-20020a63715e000000b005ce08c4bff1si9960409pgn.754.2024.01.31.09.49.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 09:49:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46876-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46876-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 4BA8DB3344E for ; Wed, 31 Jan 2024 17:11:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A54A5130E2A; Wed, 31 Jan 2024 17:09:00 +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= 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" To: Jason Gunthorpe , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Daniel P. Smith" , Ross Philipson , Peter Huewe , Jarkko Sakkinen 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-ZohoMailClient: External 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 Signed-off-by: Ross Philipson --- 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; -- 2.30.2