From patchwork Fri Jul 9 02:53:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 1502826 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) 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=sg7240HG; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (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 4GLd5L6Mxzz9sXM for ; Fri, 9 Jul 2021 12:53:26 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GLd5L57lWz3bVq for ; Fri, 9 Jul 2021 12:53:26 +1000 (AEST) Authentication-Results: lists.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=sg7240HG; dkim-atps=neutral X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=stefanb@linux.vnet.ibm.com; receiver=) 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=sg7240HG; dkim-atps=neutral Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 4GLd5F1qg3z3bXy for ; Fri, 9 Jul 2021 12:53:20 +1000 (AEST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 1692XcjD152392; Thu, 8 Jul 2021 22:53:18 -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=66g0LCL+lrbMwjgvpXpHIn7MpSgTZUnMIs4ekQnLfXs=; b=sg7240HGF0buSjXb/fCfweD1Im9yq82yXEPpoH6BHbdtzVEwAO17ZwM92GOWYYnsufqs +gvdNFWK289qi7gANFwLbTVj9rj+UsCRKx2XzMbs6wmxqKtME4vXkYsoLI92iqTjhNK/ 3mMMd0iOSYY81+66gSYiAg6KpOa5kdPrdqJFnuUbkEKbKSqSwsJny4mE3RjcKWloQH+2 Xg5jyz8ie2n1sI0ZBGd6jRflJ4To2NACo9YtAzRFw6nJ6AZFnIzT5kRbuebF80IDy/aP 3lgfhDTTefzh4bTj59PKiPWW7cNUDUGwdWUnAaKTtuyGTAK37QRFYgf9GiD2n8W+ldfL yA== Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 39p1yc4j2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Jul 2021 22:53:18 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1692rEYt002777; Fri, 9 Jul 2021 02:53:17 GMT Received: from b03cxnp07027.gho.boulder.ibm.com (b03cxnp07027.gho.boulder.ibm.com [9.17.130.14]) by ppma01wdc.us.ibm.com with ESMTP id 39jfhd3y42-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 09 Jul 2021 02:53:17 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp07027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1692rGBq27066790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 9 Jul 2021 02:53:16 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DDA4C6057; Fri, 9 Jul 2021 02:53:16 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 367D2C605D; Fri, 9 Jul 2021 02:53:16 +0000 (GMT) Received: from localhost.localdomain (unknown [9.47.158.152]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 9 Jul 2021 02:53:16 +0000 (GMT) From: Stefan Berger To: slof@lists.ozlabs.org Date: Thu, 8 Jul 2021 22:53:07 -0400 Message-Id: <20210709025313.674287-2-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210709025313.674287-1-stefanb@linux.vnet.ibm.com> References: <20210709025313.674287-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 0uFPP5xz39QlCVfxtrQLAXy4MRcp8NOt X-Proofpoint-ORIG-GUID: 0uFPP5xz39QlCVfxtrQLAXy4MRcp8NOt X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-09_01:2021-07-09, 2021-07-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 malwarescore=0 impostorscore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 mlxscore=0 spamscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107090010 Subject: [SLOF] [PATCH v3 1/7] tcgbios: Change format of S_CRTM_VERSION string to ucs-2 X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Berger Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" From: Stefan Berger Change the format of the S_CRTM_VERSION string to ucs-2 since this is what seems to be commonly used by other firmwares following insight from a TCG work group member. Signed-off-by: Stefan Berger --- lib/libtpm/tcgbios.c | 45 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c index d611576..690c4b2 100644 --- a/lib/libtpm/tcgbios.c +++ b/lib/libtpm/tcgbios.c @@ -1106,6 +1106,29 @@ uint32_t tpm_measure_gpt(void) (const uint8_t *)uefi_gpt_data, sz); } +/* convert a normal string of given length into a ucs-2 string */ +static char *string2ucs2(const char *str, size_t str_length, + size_t *ucs2_length) +{ + char *ucs2; + size_t i; + + if (str_length > 0) { + *ucs2_length = str_length * 2; + if (str[str_length - 1] != 0) + *ucs2_length += 2; + } else { + *ucs2_length = 2; + } + ucs2 = SLOF_alloc_mem(*ucs2_length); + if (ucs2) { + memset(ucs2, 0, *ucs2_length); + for (i = 0; i < str_length; i++) + ucs2[i * 2] = str[i]; + } + return ucs2; +} + uint32_t tpm_measure_scrtm(void) { uint32_t rc; @@ -1115,19 +1138,25 @@ uint32_t tpm_measure_scrtm(void) char *slof_text_start = (char *)&_slof_text; uint32_t slof_text_length = (long)&_slof_text_end - (long)&_slof_text; const char *scrtm = "S-CRTM Contents"; + char *ucs2_version; + size_t ucs2_length; version_end = strchr(version_start, '\r'); version_length = version_end - version_start; - dprintf("Measure S-CRTM Version: addr = %p, length = %d\n", - version_start, version_length); + ucs2_version = string2ucs2(version_start, version_length, &ucs2_length); + if (ucs2_version) { + dprintf("Measure S-CRTM Version: addr = %p, length = %d\n", + ucs2_version, ucs2_length); - rc = tpm_add_measurement_to_log(0, EV_S_CRTM_VERSION, - version_start, version_length, - (uint8_t *)version_start, - version_length); - if (rc) - return rc; + rc = tpm_add_measurement_to_log(0, EV_S_CRTM_VERSION, + ucs2_version, ucs2_length, + (uint8_t *)ucs2_version, + ucs2_length); + SLOF_free_mem(ucs2_version, ucs2_length); + if (rc) + return rc; + } dprintf("Measure S-CRTM Content (text): start = %p, length = %d\n", slof_text_start, slof_text_length);