From patchwork Sat Dec 9 04:52:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Carvalho X-Patchwork-Id: 846503 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.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ytxjl2CY2z9sCZ for ; Sat, 9 Dec 2017 15:55:23 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3ytxjl10WzzF0BJ for ; Sat, 9 Dec 2017 15:55:23 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=cclaudio@linux.vnet.ibm.com; receiver=) 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 3ytxfx06DSzDsPC for ; Sat, 9 Dec 2017 15:52:56 +1100 (AEDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB94n8e5094966 for ; Fri, 8 Dec 2017 23:52:55 -0500 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2er94407tb-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 08 Dec 2017 23:52:54 -0500 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 8 Dec 2017 23:52:53 -0500 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 8 Dec 2017 23:52:51 -0500 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vB94qoPn45547632 for ; Sat, 9 Dec 2017 04:52:50 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 19358AC040 for ; Fri, 8 Dec 2017 23:53:51 -0500 (EST) Received: from legolas.ibm.com (unknown [9.80.208.91]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 9487CAC03F for ; Fri, 8 Dec 2017 23:53:50 -0500 (EST) From: Claudio Carvalho To: skiboot@lists.ozlabs.org Date: Sat, 9 Dec 2017 02:52:21 -0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512795154-15659-1-git-send-email-cclaudio@linux.vnet.ibm.com> References: <1512795154-15659-1-git-send-email-cclaudio@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17120904-0040-0000-0000-000003CF0046 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008175; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000244; SDB=6.00957531; UDB=6.00484124; IPR=6.00737560; BA=6.00005731; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018437; XFM=3.00000015; UTC=2017-12-09 04:52:52 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17120904-0041-0000-0000-000007C43C94 Message-Id: <1512795154-15659-8-git-send-email-cclaudio@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-09_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712090063 Subject: [Skiboot] [PATCH v2 07/20] libstb/cvc.c: import softrom behavior from drivers/sw_driver.c X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Softrom is used only for testing with mambo. By setting compatible="ibm,secureboot-v1-softrom" in the "ibm,secureboot" node, firmware images can be properly measured even if the Container-Verification-Code (CVC) is not available. In this case, the mbedtls_sha512() function is used to calculate the sha512 hash of the firmware images. This imports the softrom behavior from libstb/drivers/sw_driver.c code into cvc.c, but now softrom is implemented as a flag. When the flag is set, the wrappers for the CVC services work the same way as in sw_driver.c. Signed-off-by: Claudio Carvalho --- libstb/cvc.c | 16 ++++++++++++++++ libstb/secureboot.c | 5 ++++- libstb/secureboot.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libstb/cvc.c b/libstb/cvc.c index b0f5cd3..fd1f607 100644 --- a/libstb/cvc.c +++ b/libstb/cvc.c @@ -26,6 +26,7 @@ #include #include "secureboot.h" #include "cvc.h" +#include "mbedtls/sha512.h" /* * Assembly interfaces to call into the Container Verification Code. @@ -43,6 +44,7 @@ struct container_verification_code { }; static struct container_verification_code *cvc = NULL; +static bool softrom = false; static void *secure_rom_mem = NULL; struct cvc_service { @@ -194,6 +196,8 @@ int cvc_init(void) if (version == IBM_SECUREBOOT_V1 && proc_gen == proc_gen_p8) { rc = cvc_secure_rom_init(); + } else if (version == IBM_SECUREBOOT_SOFTROM) { + softrom = true; } else { prlog(PR_ERR, "%s FAILED. /ibm,secureboot not supported\n", __func__); @@ -214,6 +218,15 @@ int call_cvc_sha512(const uint8_t *data, size_t data_len, uint8_t *digest, return OPAL_SUCCESS; memset(digest, 0, SHA512_DIGEST_LENGTH); + if (softrom) { + mbedtls_sha512_context ctx; + mbedtls_sha512_init(&ctx); + mbedtls_sha512_starts(&ctx, 0); // SHA512 = 0 + mbedtls_sha512_update(&ctx, data, data_len); + mbedtls_sha512_finish(&ctx, digest); + mbedtls_sha512_free(&ctx); + return OPAL_SUCCESS; + } service = cvc_find_service(CVC_SHA512_SERVICE); @@ -239,6 +252,9 @@ int call_cvc_verify(void *container, size_t len, const void *hw_key_hash, !hw_key_hash || hw_key_hash_size <= 0) return OPAL_PARAMETER; + if (softrom) + return OPAL_UNSUPPORTED; + service = cvc_find_service(CVC_VERIFY_SERVICE); if (!service) diff --git a/libstb/secureboot.c b/libstb/secureboot.c index 2787951..953b123 100644 --- a/libstb/secureboot.c +++ b/libstb/secureboot.c @@ -34,6 +34,7 @@ static struct { const char *compat; } secureboot_map[] = { { IBM_SECUREBOOT_V1, "ibm,secureboot-v1" }, + { IBM_SECUREBOOT_SOFTROM, "ibm,secureboot-v1-softrom" }, }; static void secureboot_enforce(void) @@ -112,7 +113,9 @@ void secureboot_init(void) if (!secure_mode) return; - if (version == IBM_SECUREBOOT_V1) { + if (version == IBM_SECUREBOOT_V1 || + version == IBM_SECUREBOOT_SOFTROM) { + hash_algo = dt_prop_get(node, "hash-algo"); if (strcmp(hash_algo, "sha512")) { /** diff --git a/libstb/secureboot.h b/libstb/secureboot.h index ea97ed7..8506ea0 100644 --- a/libstb/secureboot.h +++ b/libstb/secureboot.h @@ -24,6 +24,7 @@ enum secureboot_version { IBM_SECUREBOOT_V1, + IBM_SECUREBOOT_SOFTROM, }; bool secureboot_is_compatible(struct dt_node *node, int *version, const char **compat);