From patchwork Mon Aug 26 22:38:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Philipson X-Patchwork-Id: 822511 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.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 E7B2D19DF5F; Mon, 26 Aug 2024 22:43:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724712232; cv=none; b=gF7Tq+RkwCnPnUn7RF+D5B69GYHlRZaOboU722/U6nBwEqiGOtyckVWC7f5gG0YshBFDhEcZeKa925wUaonuOtCGhXrWsh+7x8wEETAJgwJ0+jnIxTv2vyGpycoNK+n6t7NT6uo+F4XjvwSMDBamYROALCWX1lX3SQmPtHmy6RA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724712232; c=relaxed/simple; bh=2Dx1poMFInj5NHx9OAbSKdQ7X35FioAzcok5qUhAaf8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=shNL52Wh1p7FkrC49HB5wfUuSqWNdSEZVQ8CwB7Zmr5H3PSVfQsPBm05L3RNIOHmtFFFluGs/PyDBR1VgOscQBxPULr51jzy2xRl8fJPyJJgy0BktvI1tNErjPQFrUoEoE/KyMDiAYGSVo/rBo8lkLsqvt3jZW9RQ2DwHVA3liY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=jeqxygkF; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jeqxygkF" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47QKtTWb020332; Mon, 26 Aug 2024 22:43:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=corp-2023-11-20; bh=9 Nw22CaxXzlTl2N9NHPGDeoB6dwSTixh6nR+/z+gl9o=; b=jeqxygkFu/fcP4SNl SHQo1dGrS8ZndD/MxeVXlGJGES2s+ipRofe2/Zc1ovx3Bwy8CsGTdmunR2NvGEP9 zm5/paY+0krrxs6eN9yKpwfJzqW+Jea/MzHrXj0Gu+T9iwNgXOgIbKsr9AZJrCCn +1nfcbbUWr1GmM0FhqCEmvnEoAQHwv2o04PXXwSiiTrTwCzq+GVkNeXEOarAkQxd 23qmorYCkyZdsQkcZcJSj23DtbcPDZvkZ6zEiZKfT22lrtj1DYwS8uShFcdl6lBc fVrnJq2ymHgMHBisTxDVdWRPPSqdp0hmPq6RW2L7EI9VDU15Lrfrx5pI3h3l75/H Tu9EA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4177hwm9fs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Aug 2024 22:43:25 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 47QM8PZR032584; Mon, 26 Aug 2024 22:43:23 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 418a0t5sar-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 26 Aug 2024 22:43:23 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 47QMhMoM027970; Mon, 26 Aug 2024 22:43:22 GMT Received: from localhost.us.oracle.com (bur-virt-x6-2-100.us.oracle.com [10.153.92.40]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 418a0t5s9p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 26 Aug 2024 22:43:22 +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 v10 16/20] tpm: Make locality requests return consistent values Date: Mon, 26 Aug 2024 15:38:31 -0700 Message-Id: <20240826223835.3928819-17-ross.philipson@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240826223835.3928819-1-ross.philipson@oracle.com> References: <20240826223835.3928819-1-ross.philipson@oracle.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-26_16,2024-08-26_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 malwarescore=0 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408260174 X-Proofpoint-GUID: Ck6Hl6bqb-unCqdkzb6jKQrtjjLk0AoY X-Proofpoint-ORIG-GUID: Ck6Hl6bqb-unCqdkzb6jKQrtjjLk0AoY From: "Daniel P. Smith" 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 22ebf679ea69..20a8b341be0d 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -210,7 +210,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)), @@ -229,18 +229,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;