Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp163796lqh; Thu, 30 May 2024 18:36:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhtlp9eMm3NBy+1nj4GZ54LLnIoWab6CkHilpJyXoYS3rp3iz1KfsvpCIKdblkv9KaLh2daGoOsDcImtt62IYpvCtziUFHJ+yA9YV2nQ== X-Google-Smtp-Source: AGHT+IG5pyeyB3V8lK37EQL3LBqYoPPLPW7hj/bSL5CG8vLUTwe8LHJZ+3IeTQClxAiKcWe7g929 X-Received: by 2002:a05:6358:98e:b0:186:1f52:540d with SMTP id e5c5f4694b2df-19b492d58e0mr71188055d.28.1717119407009; Thu, 30 May 2024 18:36:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717119406; cv=pass; d=google.com; s=arc-20160816; b=P0wAQC8x8hIIT4mCmmWaQgXj2T+TPow55GBICPtmihQOYOd5qEpmLxhPbyO3oD/1O8 lmk9rswuAJWq23f++7g0+YwT2sB3rE/2wPMWsXFUM8n2rYT6ASPKFglDFyREYQ+fS2zm 2t6D56KEwhNTLSHNx2+Jak6O9dqZlEedWt8AEqoBevRp5IRlBIJdrYIHlA43y59OBJAC UAVBJye5RICMaNK51Q86Dvh9ealnFQixEQkodoAxH2bl4pGiCZHvB1qwMzbV68RaLDtk VqJ/XjFzy/F/ybGizP1Du7wSYwzMOrZ5GPp8O3Fjw5ll4QeaVIurYAOZRzyHugYGcYa+ KNPw== ARC-Message-Signature: i=2; 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; bh=nxq08WAenyrvlX5ERENW+3rM625h7NGLPpnK2Ul2QSs=; fh=ksrYNUbdo9+K4DYOCXVji8cRdTI1C1SaRA8HdvQyCiA=; b=UQYSjv8NiUXa3C7VEn1ThRzauZ01J0xzWBhHqp6q/jCKhVKHDd3mbKct15NeCEXhdq gh7pEbx+O8IJL3f7tJkGgs+oIXu3ONhliF25QIjsPOzIoOsm7CTDdrE1LygI0VTYMYLL 2ySST0RWKw5KXtNc8bYJ6jS1FxEm7NnP1LX81urjBO5NoCGQmpLzMSVfmNOwNYziKDHx yVKV7kcT/y7sJryXhflkAGxxax7Xrh78IcyN8M4QsvFgfNyDEYkFtOt216pejvVpN6ft Y6bgrBBTsrbcOJWFZ2o3k7wPLe1HJaEKHZkkyYE0tUyaekGR9U5r8UnlPOXlkjGZvzs9 8uYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=neutral (bad format) header.i=@oracle.com; arc=pass (i=1 spf=pass spfdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-196153-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196153-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oracle.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35c55277csi610713a12.704.2024.05.30.18.36.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 18:36:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-196153-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=neutral (bad format) header.i=@oracle.com; arc=pass (i=1 spf=pass spfdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel+bounces-196153-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196153-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=oracle.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9448A2840D2 for ; Fri, 31 May 2024 01:36:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBCA779B87; Fri, 31 May 2024 01:33:06 +0000 (UTC) Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (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 A739678C6F; Fri, 31 May 2024 01:33:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717119186; cv=none; b=HRx0vozM/8KcIjtURJG9mOYn+bgoASIbhMTHuV3O4VWBDnlSmHtcCee92tMTB7qcfmQ9pbke61RynO115fSrI6PmzODXQj5xWhMT7C3+cEdOR1yG4TwfkZrx9mlf+cfHY1kmdby7e1WGWxGw5clyjHOePD6zEzUtODKPZNhakjM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717119186; c=relaxed/simple; bh=hyPoUYzn90rnj4HWvkb6raZcJsWrR1cHwG8NUGCC1k0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nIe0tJyywqmWNUeMfcGh548F7KHHCP4qTd7ab3ofNyPMuix4Kztn6fYM6NDYm3WRyrfGogPo8fEfD3UPbIh6kuefqAp8ApjOQO5rnwtqVwA9/va2oA3j+GTmzAJVgCR30Wlf86PN5KvZuGTXGh04LYU87Dq2c3Af08j9t9WJPp4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 44UFNqOb001861; Fri, 31 May 2024 01:31:20 GMT DKIM-Signature: =?UTF-8?Q?v=3D1;_a=3Drsa-sha256;_c=3Drelaxed/relaxed;_d=3Doracle.com;_h?= =?UTF-8?Q?=3Dcc:content-transfer-encoding:date:from:in-reply-to:message-i?= =?UTF-8?Q?d:mime-version:references:subject:to;_s=3Dcorp-2023-11-20;_bh?= =?UTF-8?Q?=3Dnxq08WAenyrvlX5ERENW+3rM625h7NGLPpnK2Ul2QSs=3D;_b=3DHV0ez11i?= =?UTF-8?Q?zHMFhuhxR/xMe0VDwXfdOESahtaeuK3AZBpPYkb66zuAFQv4j803NKMjKKEM_Ax?= =?UTF-8?Q?/nk82kdcpUEomK5fOkSWAISLQmU3oLUxhzgK9sIj+DArSJO/VqvpTtWaALy5/4B?= =?UTF-8?Q?T3d_+d1TN2dcp8fzav+xifJBGCWU18+1073qtCIMo+ungzia+4z87uJ37VUD+ww?= =?UTF-8?Q?ZfHVjHxxO_LFnMbAjOEee5i4EPJDdncu3GeW44n2kCuDGY1sZJwhoYPQYoelXya?= =?UTF-8?Q?RqH1Wr+83fEvfkl_XdOc5CIXF9vwaKzmUfr5qlzyunY+40UGyxF9QC531bKDjjE?= =?UTF-8?Q?VJLvykHG98iGexUGDJ1fL_pg=3D=3D_?= Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3yb8fcj7j5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 31 May 2024 01:31:19 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 44UMutAn016282; Fri, 31 May 2024 01:31:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3yc50t980r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 31 May 2024 01:31:18 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 44V1SKNe027418; Fri, 31 May 2024 01:31:17 GMT Received: from bur-virt-x6-2-100.us.oracle.com (bur-virt-x6-2-100.us.oracle.com [10.153.92.40]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3yc50t96yw-14 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 31 May 2024 01:31:17 +0000 From: Ross Philipson To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, iommu@lists.linux-foundation.org Cc: ross.philipson@oracle.com, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, dave.hansen@linux.intel.com, ardb@kernel.org, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, corbet@lwn.net, ebiederm@xmission.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, kanth.ghatraju@oracle.com, andrew.cooper3@citrix.com, trenchboot-devel@googlegroups.com Subject: [PATCH v9 13/19] tpm: Protect against locality counter underflow Date: Thu, 30 May 2024 18:03:25 -0700 Message-Id: <20240531010331.134441-14-ross.philipson@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240531010331.134441-1-ross.philipson@oracle.com> References: <20240531010331.134441-1-ross.philipson@oracle.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-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-30_21,2024-05-30_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2405310010 X-Proofpoint-GUID: HNDubto-grwXgietQQlmdfNwuYKjAoD2 X-Proofpoint-ORIG-GUID: HNDubto-grwXgietQQlmdfNwuYKjAoD2 From: "Daniel P. Smith" 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 176cd8dbf1db..7c1761bd6000 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); -- 2.39.3