From patchwork Sat Nov 11 17:28:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Carvalho X-Patchwork-Id: 837059 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 3yZ3sF000pz9sNd for ; Sun, 12 Nov 2017 04:33:20 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yZ3sD5lRNzDrLT for ; Sun, 12 Nov 2017 04:33:20 +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.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=cclaudio@linux.vnet.ibm.com; receiver=) Received: from mx0a-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 3yZ3mW0v3lzDrLV for ; Sun, 12 Nov 2017 04:29:14 +1100 (AEDT) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vABHQkIT187175 for ; Sat, 11 Nov 2017 12:29:12 -0500 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e5uq91qhw-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sat, 11 Nov 2017 12:29:12 -0500 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 11 Nov 2017 10:29:11 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 11 Nov 2017 10:29:09 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vABHT97C58327206 for ; Sat, 11 Nov 2017 10:29:09 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 44A6FC603C for ; Sat, 11 Nov 2017 10:29:09 -0700 (MST) Received: from legolas.ibm.com (unknown [9.85.175.178]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id ACD31C6037 for ; Sat, 11 Nov 2017 10:29:08 -0700 (MST) From: Claudio Carvalho To: skiboot@lists.ozlabs.org Date: Sat, 11 Nov 2017 15:28:34 -0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510421322-27237-1-git-send-email-cclaudio@linux.vnet.ibm.com> References: <1510421322-27237-1-git-send-email-cclaudio@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111117-0004-0000-0000-000013328085 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008052; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00944424; UDB=6.00476526; IPR=6.00724686; BA=6.00005688; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017969; XFM=3.00000015; UTC=2017-11-11 17:29:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111117-0005-0000-0000-000084D44525 Message-Id: <1510421322-27237-12-git-send-email-cclaudio@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-11_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1711110250 Subject: [Skiboot] [PATCH 11/19] libstb/secureboot.c: import sb_verify() from stb.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" This imports the sb_verify() function from stb.c, but now it calls the added CVC verify wrapper in order to verify signed firmware images. The hw-key-hash and hw-key-hash-size initialized in secureboot.c are passed to the CVC verify function wrapper. In secureboot.c, the sb_verify() is renamed to secureboot_verify(). The sb_verify() calls are updated in a subsequent patch. Signed-off-by: Claudio Carvalho --- libstb/cvc.c | 13 +++++++++++++ libstb/cvc.h | 1 + libstb/secureboot.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ libstb/secureboot.h | 18 ++++++++++++++++++ 4 files changed, 85 insertions(+) diff --git a/libstb/cvc.c b/libstb/cvc.c index 5f46e5e..6d133e5 100644 --- a/libstb/cvc.c +++ b/libstb/cvc.c @@ -122,6 +122,19 @@ static const char *cvc_get_service_name(enum cvc_service_id id) return NULL; } +int cvc_get_service_version(enum cvc_service_id id) +{ + struct cvc_service *service; + if (!cvc) + return -1; + + service = cvc_find_service(id); + if (!service) + return -1; + + return service->version; +} + #define SECURE_ROM_MEMORY_SIZE (16 * 1024) #define SECURE_ROM_XSCOM_ADDRESS 0x02020017 diff --git a/libstb/cvc.h b/libstb/cvc.h index c53cf81..7dfda33 100644 --- a/libstb/cvc.h +++ b/libstb/cvc.h @@ -36,6 +36,7 @@ const char* __attrconst get_secureboot_dt_compat(enum secureboot_dt_version vers int cvc_init(void); void cvc_register(uint64_t start_addr, uint64_t end_addr); void cvc_service_register(uint32_t type, uint32_t version, uint32_t offset); +int cvc_get_service_version(enum cvc_service_id id); /************************************************************************ * Wrappers for the services provided by the Container-Verification-Code diff --git a/libstb/secureboot.c b/libstb/secureboot.c index 6f4be80..7014f07 100644 --- a/libstb/secureboot.c +++ b/libstb/secureboot.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "secureboot.h" #include "container.h" #include "cvc.h" @@ -115,3 +116,55 @@ void secureboot_init(void) secureboot_enforce(); } } + +int secureboot_verify(enum resource_id id, void *buf, size_t len) +{ + const char *name; + uint64_t log; + int rc = -1; + + if (!secure_mode) + return 0; + + name = flash_map_resource_name(id); + if (!name) { + prlog(PR_EMERG, "container NOT VERIFIED, resource_id=%d " + "unknown\n", id); + secureboot_enforce(); + } + + rc = call_cvc_verify(buf, len, hw_key_hash, hw_key_hash_size, &log); + + if (rc == OPAL_SUCCESS) { + prlog(PR_INFO, "%s verified\n", name); + } else if (rc == OPAL_PARTIAL) { + /* + * The value returned in log indicates what checking has + * failed. Return codes defined in + * /hostboot/src/include/securerom/status_codes.H + */ + prlog(PR_EMERG, "%s verification FAILED. log=0x%llx\n", + name, be64_to_cpu(log)); + secureboot_enforce(); + } else if (rc == OPAL_PARAMETER) { + prlog(PR_EMERG, "%s NOT VERIFIED, invalid param. buf=%p, " + "len=%zd key-hash=%p hash-size=%zd\n", name, buf, len, + hw_key_hash, hw_key_hash_size); + secureboot_enforce(); + } else if (rc == OPAL_RESOURCE) { + prlog(PR_EMERG, "%s NOT VERIFIED, CVC-verify service not " + "available\n", name); + secureboot_enforce(); + } else if (rc == OPAL_UNSUPPORTED) { + prlog(PR_EMERG, "%s NOT VERIFIED, CVC-verify " + "version %d not supported\n", name, + cvc_get_service_version(CVC_VERIFY_SERVICE)); + secureboot_enforce(); + } else { + prlog(PR_EMERG, "%s NOT VERIFIED, unknown CVC-verify error. " + "rc=%d\n", name, rc); + secureboot_enforce(); + } + + return 0; +} diff --git a/libstb/secureboot.h b/libstb/secureboot.h index 5bdae0a..db54976 100644 --- a/libstb/secureboot.h +++ b/libstb/secureboot.h @@ -17,6 +17,24 @@ #ifndef __SECUREBOOT_H #define __SECUREBOOT_H +#include + void secureboot_init(void); +/** + * secureboot_verify - verify a PNOR partition content + * @id : PNOR partition id + * @buf : PNOR partition content to be verified + * @len : @buf length + * + * This verifies the integrity and authenticity of @buf downloaded from PNOR if + * secure mode is on. The verification is done by the Container Verification + * Code (CVC) flashed in ROM. + * + * For more information refer to 'doc/stb.rst' + * + * returns: 0 otherwise the boot process is aborted + */ +int secureboot_verify(enum resource_id id, void *buf, size_t len); + #endif /* __SECUREBOOT_H */