From patchwork Mon Sep 28 22:06:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Richter X-Patchwork-Id: 1372909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C0c7Z2jMdz9s1t for ; Tue, 29 Sep 2020 08:07:06 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ftFRnlqi; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4C0c7Z1RzzzDqLF for ; Tue, 29 Sep 2020 08:07:06 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=erichte@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=ftFRnlqi; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4C0c6k0djzzDqLF for ; Tue, 29 Sep 2020 08:06:21 +1000 (AEST) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08SM1vSG083120 for ; Mon, 28 Sep 2020 18:06:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=a71llUwLByLEv7E/2gchFh4qT3z6v5X9rXtXoo28h2M=; b=ftFRnlqizJLlNa9n2maQu0NiYJepvAhcjNlT/I964UixuthK1QOBIXvBMaUFOxPnILAC F+h6NLyNjcZyobe3bBp07PUV5DbAJ7orbprWnC5EEZrVrEzbL0grNOjLa0irGIMj1k/R 00z/rKqZiAe94wHQXXtL3QmPM1S24QNx64iK4ZCUvav5nsJPK8xer+cmyeuUlRxc1QhD xWQpPjTOM3bMdqLy1du34CgYThZE6v0BA7FsAmesG55K3f4RBcWt2LkjB5l1xcH4XYas tAMPInDqRiErahbeJp+8Zh9MfaN2nAoGCXiJp3T2u4xTpaUThALQx/SDjoIkAeeNf1ED yA== Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 33uqn6110u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 28 Sep 2020 18:06:18 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 08SM3L47002602 for ; Mon, 28 Sep 2020 22:06:16 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 33sw982jex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 28 Sep 2020 22:06:16 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 08SM6DeX31064402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Sep 2020 22:06:13 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8AC00AE056; Mon, 28 Sep 2020 22:06:13 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 997F5AE051; Mon, 28 Sep 2020 22:06:12 +0000 (GMT) Received: from ceres.ibmuc.com (unknown [9.211.92.104]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 28 Sep 2020 22:06:12 +0000 (GMT) From: Eric Richter To: skiboot@lists.ozlabs.org Date: Mon, 28 Sep 2020 17:06:06 -0500 Message-Id: <20200928220609.10479-2-erichte@linux.ibm.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200928220609.10479-1-erichte@linux.ibm.com> References: <20200928220609.10479-1-erichte@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-28_22:2020-09-28, 2020-09-28 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 adultscore=0 impostorscore=0 phishscore=0 malwarescore=0 spamscore=0 bulkscore=0 suspectscore=3 mlxlogscore=721 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009280164 Subject: [Skiboot] [PATCH v6a 1/4] tssskiboot.c: chunk reads/writes in 1024-sized buffers to support larger nv indices X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: klaus@linux.ibm.com, nayna@linux.ibm.com Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The Nuvoton npct650 chip has a command buffer max size of 1024. Attempting to read or write from an NV index larger than this value would return an error. This patch changes the tss_nv_read and tss_nv_write commands to chunk their operations in 1024-byte batches to allow support for larger NV indices. Signed-off-by: Eric Richter --- libstb/tss2/tssskiboot.c | 82 ++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/libstb/tss2/tssskiboot.c b/libstb/tss2/tssskiboot.c index 5f6d7611..b97159e7 100644 --- a/libstb/tss2/tssskiboot.c +++ b/libstb/tss2/tssskiboot.c @@ -13,6 +13,8 @@ #include #include +#define TSS_MAX_NV_BUFFER_SIZE 1024 + /* * Helper to string-fy TSS error response codes. */ @@ -98,6 +100,7 @@ int tss_nv_read(TPMI_RH_NV_INDEX nv_index, void *buffer, NV_Read_Out *out = NULL; NV_Read_In *in = NULL; TPM_RC rc = OPAL_SUCCESS; + int64_t buffer_remaining; if (!buffer) { rc = OPAL_PARAMETER; @@ -125,21 +128,30 @@ int tss_nv_read(TPMI_RH_NV_INDEX nv_index, void *buffer, in->nvIndex = nv_index; in->authHandle = nv_index; - in->offset = offset; - in->size = buffer_size; - rc = TSS_Execute(context, - (RESPONSE_PARAMETERS *) out, - (COMMAND_PARAMETERS *) in, - NULL, - TPM_CC_NV_Read, - TPM_RS_PW, NULL, 0, - TPM_RH_NULL, NULL, 0); + buffer_remaining = buffer_size; + while (buffer_remaining > 0) { + in->offset = offset; + in->size = MIN(TSS_MAX_NV_BUFFER_SIZE, buffer_remaining); - if (!rc) - memcpy(buffer, out->data.b.buffer, buffer_size); - else - tss_error_trace("tss_nv_read", rc); + rc = TSS_Execute(context, + (RESPONSE_PARAMETERS *) out, + (COMMAND_PARAMETERS *) in, + NULL, + TPM_CC_NV_Read, + TPM_RS_PW, NULL, 0, + TPM_RH_NULL, NULL, 0); + + if (rc) { + tss_error_trace("tss_nv_read", rc); + goto cleanup; + } + + memcpy(buffer, out->data.b.buffer, in->size); + buffer += TSS_MAX_NV_BUFFER_SIZE; + buffer_remaining -= TSS_MAX_NV_BUFFER_SIZE; + offset += TSS_MAX_NV_BUFFER_SIZE; + } cleanup: TSS_Delete(context); @@ -161,6 +173,7 @@ int tss_nv_write(TPMI_RH_NV_INDEX nv_index, void *buffer, TSS_CONTEXT *context = NULL; NV_Write_In *in = NULL; TPM_RC rc = OPAL_SUCCESS; + int64_t buffer_remaining; if (!buffer) { rc = OPAL_PARAMETER; @@ -182,23 +195,36 @@ int tss_nv_write(TPMI_RH_NV_INDEX nv_index, void *buffer, in->nvIndex = nv_index; in->authHandle = TPM_RH_PLATFORM; - in->offset = offset; - rc = TSS_TPM2B_Create(&in->data.b, buffer, buffer_size, - sizeof(in->data.t.buffer)); - if (rc) { - tss_error_trace("tss_nv_write", rc); - goto cleanup; + + buffer_remaining = buffer_size; + while (buffer_remaining > 0) { + in->offset = offset; + rc = TSS_TPM2B_Create(&in->data.b, buffer, + MIN(TSS_MAX_NV_BUFFER_SIZE, buffer_remaining), + sizeof(in->data.t.buffer)); + + if (rc) { + tss_error_trace("tss_nv_write", rc); + goto cleanup; + } + + rc = TSS_Execute(context, + NULL, + (COMMAND_PARAMETERS *) in, + NULL, + TPM_CC_NV_Write, + TPM_RS_PW, NULL, 0, + TPM_RH_NULL, NULL, 0); + if (rc) { + tss_error_trace("tss_nv_write", rc); + goto cleanup; + } + + buffer += TSS_MAX_NV_BUFFER_SIZE; + buffer_remaining -= TSS_MAX_NV_BUFFER_SIZE; + offset += TSS_MAX_NV_BUFFER_SIZE; } - rc = TSS_Execute(context, - NULL, - (COMMAND_PARAMETERS *) in, - NULL, - TPM_CC_NV_Write, - TPM_RS_PW, NULL, 0, - TPM_RH_NULL, NULL, 0); - if (rc) - tss_error_trace("tss_nv_write", rc); cleanup: TSS_Delete(context); free(in);