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);