From patchwork Wed Jan 31 17:08:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel P. Smith" X-Patchwork-Id: 194869 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp2032708dyb; Wed, 31 Jan 2024 09:11:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOkDgiQAgJPZwamS31nGA3DfBSalD+ToCjcEj0EdgMbO1T3mibPVA7Lc71RVzTIFFDEN6n X-Received: by 2002:a0c:cc8f:0:b0:68c:7729:a420 with SMTP id f15-20020a0ccc8f000000b0068c7729a420mr333638qvl.58.1706721070519; Wed, 31 Jan 2024 09:11:10 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1706721070; cv=pass; d=google.com; s=arc-20160816; b=a5GaccLIcviZcXg30PCQQY/hS79douWPZ41BPc0gAIDXcTmE0jEznmzUjvKJpaXd3U gzIPRereaHcTeHRwwuH+P3xveu3QXxd5XzJqjlv7pSMk5or6AlLezlxE9Q0iDKsK1HqY xuLD44HIXc0owo6K5Sz2UmyrZBtfWgxEZuVqnwNlUch4fgWeuCSHxnSGFNP/Kyx6RTSf hw5065+71vBukYXPcxTx8fZsCtm7U6xOvUsBRO+P7F+L0xRwiePIEEJqClMbrja6uyZ4 lMekgd257w27HEwKbD0pesKyF7QSm3arGbtMNzL25uklNjMDr+Am1eAE4xkpOD54uX3P ihJQ== 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=h0m6s7A7yWn0LEIvIuinrWRz0FAsqDfPRmBpoyWc61s=; fh=M7EnF211wGkspSu/lZVUvF4mdT9cZaIWATkGCIiwZeY=; b=EL0KM6KO/8EJ6S7xyiP5yZwvyYDGgFrruWvBqhzTTwkLhMrMZFr8P4OolLqhA3Ezt/ u0Z4KELA7M+GoNoUw+ZzO8tG/ui28RAkfcqpLyaVtEgweZW0pOCXOo/Sgt8xIW4j+HOo z7qL0XANInZ5yz5bFQsJ9HaKkZhEJpjwbnJDgt6e6PJsvis1+1VmIBZJTuk13qL5jWkj Mmx0Eni4nigY429O0NQ0WDWPjRd1oFAnMbnJ+SOkZRM4hGQVVFcaobEyocUVD2cnDpyW 2DQZFRpw67ce0b2Cr10ZsW89+4nvKpnmXz//tKUzYWRHTCVRuMUnZBlJonLeab/n0b+o Izyg==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@apertussolutions.com header.s=zoho header.b=CgWvmZnK; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-46875-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46875-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXvWCLJ+CCRrdfXecKrB0f6ia/aPbk5mTdFBqZAVPPXAXR65KqV+W56kJhaxBi69J1dTkQ/0jrXzYueT4fLxJJa3PIaQQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i15-20020a05620a0a0f00b00784069227d7si4960795qka.626.2024.01.31.09.11.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 09:11:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46875-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=CgWvmZnK; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-46875-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46875-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 50CB21C20EF7 for ; Wed, 31 Jan 2024 17:11:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B05F12FF79; Wed, 31 Jan 2024 17:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=apertussolutions.com header.i=dpsmith@apertussolutions.com header.b="CgWvmZnK" 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 2615C12CD9D; Wed, 31 Jan 2024 17:08:47 +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=1706720930; cv=pass; b=g7DC5INDyzMqCo1Klyq6iUIuoY+Ce2f0Qcee0FH2qgnu9CB9Bj9uxQ1xY0hFM4yj7FqFsHtSrWGDFoq2BBoG7BRoLb6K9bNWClfrTCXafx482Mfi7gaFiBqgbkfmZW9/DULhJhOk07Z4Wb6K/Dy/MY1aFfr9jjo2oxAHRTubvq4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706720930; c=relaxed/simple; bh=foLZdtJaf3dwkHAyBp3JvO1GPfScZqHAa5oye1tQXu0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lcj7BpDCPD0R3I6PdGd9dBOZZ+TEbVEeVgTjkFrRb3ASMvwAQCoa1JXE29S5ohfniC2y6AupQ0Qa0z0LiaQTr/k2wLPIbDtQLI4Zew29YPj1JR6X81C2cVxdz20Ycw5K4j0mrKcUqhBaGWqwwsgQCptZVFDmvS/EnUb6ht8T9Wg= 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=CgWvmZnK; 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=1706720916; cv=none; d=zohomail.com; s=zohoarc; b=h18WEIigS5Svh8PKqKBkI/fMkUus+VVqRtPy0fZRM0GygiMi1inZCi1oGqL49CxmlSrZhgTvEcCu4y4weqMF/H9aiv0deG2fup9NvtX9IZ2zRT7r7f8oxcQNxp6XFpw1Z+kvp3IBdvMP2fxocK9ulcF6LwsiMiriQ/nJNlAtwIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706720916; 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=h0m6s7A7yWn0LEIvIuinrWRz0FAsqDfPRmBpoyWc61s=; b=m+9tviKLGIkfA9ubEdl4HDPGh5s2dxg1rhlDOVVSHaDoJ2+fpSKrKO+F41qb8Ma2w0t5wED7muFfIIf4ADPVzxs0TxsMU48aWFXA5CKTPU6eTzwCrOmzUbUhrPQhCtcuDhqb+tVd0uN8fv9mHHV6x3srfDOgQ5Rk2BIMLBG9xzY= 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=1706720916; 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=h0m6s7A7yWn0LEIvIuinrWRz0FAsqDfPRmBpoyWc61s=; b=CgWvmZnK9T9Kq0viwHU4mO8eRu6GRaCej1TuRPoV9EU3hi6p/eM9CsDVpLhWUH4Y JPJUvieK+sV2q8xhwEP54z5GVWgLQKfdl5IGSG0OzVyTDoZDy00dKzV/gkHd1b2r521 qsChDDlY/uxB3zUU1sSd5k4Mah6ysVcdKwP9vG/I= Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1706720915107755.6194080525407; Wed, 31 Jan 2024 09:08:35 -0800 (PST) From: "Daniel P. Smith" To: Jason Gunthorpe , Jarkko Sakkinen , Sasha Levin , Lino Sanfilippo , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Daniel P. Smith" , Ross Philipson , Kanth Ghatraju , Peter Huewe Subject: [PATCH 1/3] tpm: protect against locality counter underflow Date: Wed, 31 Jan 2024 12:08:21 -0500 Message-Id: <20240131170824.6183-2-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 X-ZohoMailClient: External X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789626753279525067 X-GMAIL-MSGID: 1789626753279525067 Commit 933bfc5ad213 introduced the use of a locality counter to control when a locality request is allowed to be sent to the TPM. In the commit, the counter is indiscriminately decremented. Thus creating a situation for an integer underflow of the counter. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson Reported-by: Kanth Ghatraju Fixes: 933bfc5ad213 ("tpm, tpm: Implement usage counter for locality") --- drivers/char/tpm/tpm_tis_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 1b350412d8a6..4176d3bd1f04 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -180,7 +180,8 @@ static int tpm_tis_relinquish_locality(struct tpm_chip *chip, int l) struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); mutex_lock(&priv->locality_count_mutex); - priv->locality_count--; + if (priv->locality_count > 0) + priv->locality_count--; if (priv->locality_count == 0) __tpm_tis_relinquish_locality(priv, l); mutex_unlock(&priv->locality_count_mutex); From patchwork Wed Jan 31 17:08:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel P. Smith" X-Patchwork-Id: 194870 Return-Path: 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 (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 ; 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= 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 X-ZohoMailClient: External X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789626773001503266 X-GMAIL-MSGID: 1789626773001503266 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; From patchwork Wed Jan 31 17:08:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Daniel P. Smith" X-Patchwork-Id: 194872 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp2033182dyb; Wed, 31 Jan 2024 09:11:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZsDFY8a7vwWQOKa1pb3s8CT3AbgOvWRKuHynuodqZXkrf1/hgkOdtRaQrJHzSc+BRD4s3 X-Received: by 2002:a05:622a:1007:b0:42a:b360:fcce with SMTP id d7-20020a05622a100700b0042ab360fccemr3106047qte.23.1706721107797; Wed, 31 Jan 2024 09:11:47 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1706721107; cv=pass; d=google.com; s=arc-20160816; b=zPiO4uPmWxt7n12fXiDqW5+S8nmDz+gaQkKwGrdTKjaZpBd9qrZG69gqRFZOWSyCJ4 ihOKAeZLkRy8oxXQXnR9awlq8j7hlExML7K0drmztmqAQWe+Fcdh19nxvb9Lr8BDqLLx Cbha0xXcBiuGBTmc1PikDZW1vDEyvNnLCsmTkrv4KTopHsqevABDHSMs83hf8b1olpTE Uwmnl0/BnTAT7dSxi7Z6vqpJjiHEfxT9eM/0y0woQzPayK5GPSO7ucwyzYYTeR2iPs/W hBp2vnZxIace2FFNDlwda3/gzaZkcktYRL6AzdddAfNXSuJrzmLo3yEu/2T4Fn0RlEuo z/Qw== 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=oisGpTWFjqHAtfqypalRiEg2UzjE5idBdPhb3LBh9zU=; fh=tHancUy5/7HF19x+iAj+CT3y/APykZ8yX543tM97gD0=; b=wG4Y+K3Yb5mVTYh+RrSXuMh77iOW4O5IWR7nBz6X3/gONYYfqFYPzZ+h0qrNLBpJkp 6NDrugL/5jlRRTGBTiC9Y0cjrXveF3ix+SmWw6S8JGByzHlaXo/zJkyqlDCP83ar6Koc 5UIJG9+K93BFjwujY6/+cWow7fdxhilKUJYU9xvLVryO95tkzRnYJtcRoWZLGfjIChHS tk3Y8NsaWQdd22ztNG3Qq159G1u+KsQdC7a5H3UoyNtRRFKyaCxHB3KhClTZCLlvR2CP KtO7HjoObT1OnuhW0UXZdfP6NDcjh4WNkuDkBUWlz0KWNYXjjE6VrMnbmKjvzqkxY8HA 3w1w==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@apertussolutions.com header.s=zoho header.b="eISNC/Lz"; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-46877-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46877-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUpJ9MWzsJygNRRY1c5+JFrvx0/eokFk/IqV+ONENL23YfIR9/3t0XR0jRWAsC5A6A+yCUgbM6sjGLpZsE3VEs3PwXXIA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bp6-20020a05622a1b8600b0042b218f14f1si3421385qtb.647.2024.01.31.09.11.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 09:11:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46877-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="eISNC/Lz"; arc=pass (i=2 spf=pass spfdomain=apertussolutions.com dkim=pass dkdomain=apertussolutions.com); spf=pass (google.com: domain of linux-kernel+bounces-46877-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46877-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 95B671C216F1 for ; Wed, 31 Jan 2024 17:11:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6778135A65; Wed, 31 Jan 2024 17:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=apertussolutions.com header.i=dpsmith@apertussolutions.com header.b="eISNC/Lz" 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 6B91112CDAB; Wed, 31 Jan 2024 17:09:07 +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=1706720949; cv=pass; b=T0O8fjpK/9w6CYh2+leekEdr+lFNg0HI3jjgPw0wgCCTAUaIZN9/emNqKd31fiMEzwPj6DUsrK6nojWtSwRRSCQhhUL9b3Z3nGmsz/AeXZ5LbJllmDZGRasg1maWKKrHFwW6GvFEsEvjU4h6NWcEp71vcrXSOcQ9HU8J0/RwY7o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706720949; c=relaxed/simple; bh=trM7msgFSArPjPrDsbJnOiFND6qGuUZ3YFCmeWhK78U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xw1XzEUtJqlWGefjRadPw8SQTFihQY1IMzpP7+RUhHLPs15uyVzffBqb1adwaYQW5vxaVGqgar2WnHn1RMsomeZWIq5wdV8k2L/OIvU8Zb8HqIshtXtraIDEYD/3VsuKADsdq8qIbcMKV5wgI9Cckz6V054LH7JeKRCDnP/XSHc= 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=eISNC/Lz; 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=1706720920; cv=none; d=zohomail.com; s=zohoarc; b=PNN1/Biy48y5Kta70ks1MYvS51v2IjkqawXWdzI++/D9OtAgn/Ni3UrU4XXUpSYL5EgaDpwGI+G6ASISPtunVQXy2RE8z2jYD44qoPU10QsL8GmVsyiqvtvY94Js8qXOgcRr9MZ2fPwNxC7uTHjgwi0eW9fQ31ci2vK+JWkPrJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706720920; 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=oisGpTWFjqHAtfqypalRiEg2UzjE5idBdPhb3LBh9zU=; b=m8r5EFVqBaR9jLnuARSgDyHu3exFMmVu40uPCctDAO5NgzFJUqPLOMN6Mr+52hjIJP/3a5lA79N88l8Enkop9RV+SIvXWJP5CH8OEbqoGhvHMYxevHwpfICzOYbNj3Eoa0YFNHppQR/AwBeEddxZeY6vFX2f42ksmvYf7c3hzwE= 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=1706720920; 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=oisGpTWFjqHAtfqypalRiEg2UzjE5idBdPhb3LBh9zU=; b=eISNC/LzWk1CAU88clvqoeCIBlQfQmDJpqjp39np/pyvPIV10RakmWMjssapiZhe mN0j9grEHlVjZo9s+1LsyemfPet8SnkP+pjVlww43PxseUbqbFnFjpb6cTA5BeWeTVt km6K82n3tniVMj1cMWadWx7JZ1dy8tjsmIjbughk= Received: from sisyou.hme. (static-72-81-132-2.bltmmd.fios.verizon.net [72.81.132.2]) by mx.zohomail.com with SMTPS id 1706720919703416.7846206921556; Wed, 31 Jan 2024 09:08:39 -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 3/3] tpm: make locality request return value consistent Date: Wed, 31 Jan 2024 12:08:23 -0500 Message-Id: <20240131170824.6183-4-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 X-ZohoMailClient: External X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789626792389341184 X-GMAIL-MSGID: 1789626792389341184 The function tpm_tis_request_locality() is expected to return the locality value that was requested, or a negative error code upon failure. If it is called while locality_count of struct tis_data is non-zero, no actual locality request will be sent. Because the ret variable is initially set to 0, the locality_count will still get increased, and the function will return 0. For a caller, this would indicate that locality 0 was successfully requested and not the state changes just mentioned. Additionally, the function __tpm_tis_request_locality() provides inconsistent error codes. It will provide either a failed IO write or a -1 should it have timed out waiting for locality request to succeed. This commit changes __tpm_tis_request_locality() to return valid negative error codes to reflect the reason it fails. It then adjusts the return value check in tpm_tis_request_locality() to check for a non-negative return value before incrementing locality_cout. In addition, the initial value of the ret value is set to a negative error to ensure the check does not pass if __tpm_tis_request_locality() is not called. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson --- drivers/char/tpm/tpm_tis_core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 5709f87991d9..352fefc07823 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -208,7 +208,7 @@ static int __tpm_tis_request_locality(struct tpm_chip *chip, int l) again: timeout = stop - jiffies; if ((long)timeout <= 0) - return -1; + return -EBUSY; rc = wait_event_interruptible_timeout(priv->int_queue, (check_locality (chip, l)), @@ -227,18 +227,21 @@ static int __tpm_tis_request_locality(struct tpm_chip *chip, int l) tpm_msleep(TPM_TIMEOUT); } while (time_before(jiffies, stop)); } - return -1; + return -EBUSY; } static int tpm_tis_request_locality(struct tpm_chip *chip, int l) { struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); - int ret = 0; + int ret = -EBUSY; + + if (l < 0 || l > TPM_MAX_LOCALITY) + return -EINVAL; mutex_lock(&priv->locality_count_mutex); if (priv->locality_count == 0) ret = __tpm_tis_request_locality(chip, l); - if (!ret) + if (ret >= 0) priv->locality_count++; mutex_unlock(&priv->locality_count_mutex); return ret;