From patchwork Wed Sep 18 01:26:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1163638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Bycyl14+"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46Y2LK3N6Bz9s4Y for ; Wed, 18 Sep 2019 11:23:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 3278CC21C29; Wed, 18 Sep 2019 01:23:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 76A48C21C2F; Wed, 18 Sep 2019 01:23:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B817BC21C2F; Wed, 18 Sep 2019 01:23:25 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by lists.denx.de (Postfix) with ESMTPS id 5F168C21C29 for ; Wed, 18 Sep 2019 01:23:24 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id q21so3233216pfn.11 for ; Tue, 17 Sep 2019 18:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Oup2SBrHfzE7TkzAFR3DSMyLZyq4DssMvBnbhfoQhw=; b=Bycyl14+M3cZx0UE5WnqrBVb+tZMl6rxdOiQjo3m9yzS0dP2EuH9TC0dxqmKsYvbE3 XWj5LUht4fL+T454dmhW1e4lF6sSHoxvFi9ZpQ6ZtcffcKN82UzcWHXjRlw/R9JXRDjs Ygvs4FR4dxyQXEOPEjZvaZHivoFVgL2aLItZeQ6++d5pLL2JLyr+x2R+lOA9+tGxGYHk Dt6J0/gHsd2ROs8s8U1OzgrwnmBrwPU3RrYjjTIfEUPxiyXf2kLyvBvqDll45FQnk/KA W564UnpoG8jnaMKbmS6CESM+2GYsszRogVI75GaudPzLF6MB91WajI98kftdSB0djhYS 5Okg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=6Oup2SBrHfzE7TkzAFR3DSMyLZyq4DssMvBnbhfoQhw=; b=tBrfiH+OkXGAhhMgkyQGlQNng3feOBS02j8JE/QViLG67LzhSgxSTRDVs1Roko2z7v B1VQZOJTSmbhTtq6uRp6dVzVKD3DjS5Alg1jbTnDfjmMVOWbMMHa1D7yhsYgYBOM+2G3 8RKlEHF+b+Bu38roeEsPDPdRh1PXy0pbWLFHfuNp4BV/Y8/VYGFdMJFILNCL8BBOlfHD NblocbuO8/KCFT6Eon7WhYWOPitBVRLYkEHH8SGP8i/qy9B77oWJCy4cbn3sNZFGEUBp DlyPEjYTf98hN5ZdqAN7G9XHr35M9Wmymj3nDdnhcIEV0GEsO0YiPENeU9HASzWC7EtM lDrg== X-Gm-Message-State: APjAAAX8fNT/m1gHrQoWNt/QAALbEccvMCkNmkqEHjV056PIvqERVgoC wvbW6elyInXkCztSXUOpAk5R1w== X-Google-Smtp-Source: APXvYqwKATyaifnONKsnAr5d1T/PD+P2CezeQMcPWyXHg1N3w9dJ6ncW0kyNzVhHEN9/GYg0MSLc4Q== X-Received: by 2002:aa7:8009:: with SMTP id j9mr1353637pfi.107.1568769802640; Tue, 17 Sep 2019 18:23:22 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w6sm9073256pfw.84.2019.09.17.18.23.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Sep 2019 18:23:22 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de, trini@konsulko.com Date: Wed, 18 Sep 2019 10:26:28 +0900 Message-Id: <20190918012643.25192-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC 00/15] efi_loader: add secure boot support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" One of major missing features in current UEFI implementation is "secure boot." The ultimate goal of my attempt is to implement image authentication based on signature and provide UEFI secure boot support which would be fully compliant with UEFI specification, section 32[1]. (The code was originally developed by Patrick Wildt.) While this patch/RFC is still rough-edged, the aim here is to get early feedbacks from the community as the patch is quite huge (in total) and also as it's a security enhancement. Please note, however, this patch doesn't work on its own; there are a couple of functional dependencies[2], [3] and [4], that I have submitted before, in addition to related preparatory patches[5], [6], [7] and [8] for pytest support. For complete workable patch set, see my repository[9], which also contains exeperimental timestamp-based revocation suuport. My "non-volatile" support[10], which is under reviews now, is not mandatory and so not included here, but this inevitably implies that, for example, signature database variables, like db and dbx, won't be persistent unless you explicitly run "env save" command and that UEFI variables are not separated from U-Boot environment. Anyhow, Linaro is also working on implementing real "secure storage" solution based on TF-A and OP-TEE. Supported features: * image authentication based on db and dbx * supported signature types are EFI_CERT_SHA256_GUID (SHA256 digest for unsigned images) EFI_CERT_X509_GUID (x509 certificate for signed images) * SecureBoot/SignatureSupport variables * SetupMode and user mode * variable authentication based on PK and KEK EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS * pytest test cases Unsupported features: * hash algorithms other than SHA256 * dbt: timestamp(RFC6131)-based certificate revocation * dbr: OS recovery * xxxDefault: default values for signature stores * transition to AuditMode and DeployedMode * recording rejected images in EFI_IMAGE_EXECUTION_INFO_TABLE * variable authentication based on PK and KEK EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS * real secure storage, including hardware-specific PK (Platform Key) installation Known issues: * [3] and [4] have not been well reviewed yet. * Some test case(test_efi_var_auth1:1g) still fails. * Extensive clean-ups * not bisect-ready (for easier code modification) for now TODO: * implement "unsupported" features, in particular, timestamp-based revocation * fix some workarounds in the source (marked as TODO/FIXME) * extensive test suite (or more test cases) to confirm compatibility with EDK2 Hints about how to use: (Please see other documents, or my pytest scripts, for details.) * You can create your own certificates with openssl. * You can sign your application with pesign (on Ubuntu). * You can create raw data for signature database with efitools, and install/manage authenticated variables with "env -set -e" command or efitools' "UpdateVars.efi" application. [1] https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf [2] https://lists.denx.de/pipermail/u-boot/2019-September/382911.html (support APPEND_WRITE) [3] https://lists.denx.de/pipermail/u-boot/2019-September/382573.html (import x509/pkcs7 parsers from linux) [4] https://lists.denx.de/pipermail/u-boot/2019-September/382917.html (extend rsa_verify() for UEFI secure boot) [5] https://lists.denx.de/pipermail/u-boot/2019-August/382027.html (sandbox: fix cpu property in test.dts for pytest) [6] https://lists.denx.de/pipermail/u-boot/2019-September/382914.html (extend "env [set|print] -e to manage UEFI variables v1) [7] https://lists.denx.de/pipermail/u-boot/2019-September/383343.html (install FILE_SYSTEM_PROTOCOL to a whole disk) [8] https://lists.denx.de/pipermail/u-boot/2019-September/383348.html (support Sandbox's "host" device) [9] http://git.linaro.org/people/takahiro.akashi/u-boot.git/ efi/secboot [10] https://lists.denx.de/pipermail/u-boot/2019-September/382835.html (non-volatile variables support) AKASHI Takahiro (15): lib: charset: add u16_strcmp() test: add tests for u16_strcmp() include: pe.h: add image-signing-related definitions include: image.h: add key info to image_sign_info include: image.h: export hash algorithm helper functions secure boot: rename CONFIG_SECURE_BOOT efi_loader: add signature verification functions efi_loader: variable: support variable authentication efi_loader: variable: add VendorKeys and SignatureSupport variables efi_loader: image_loader: support image authentication efi_loader: initialize secure boot state efi_loader: add CONFIG_EFI_SECURE_BOOT cmd: env: provide appropriate guid for well-defined variable efi_loader, pytest: add UEFI secure boot tests (image) efi_loader, pytest: add UEFI secure boot tests (authenticated variables) Kconfig | 7 + arch/arm/cpu/armv7/ls102xa/Kconfig | 3 +- arch/arm/cpu/armv8/fsl-layerscape/Kconfig | 3 +- arch/arm/mach-imx/Kconfig | 3 +- arch/powerpc/cpu/mpc85xx/Kconfig | 3 +- cmd/nvedit_efi.c | 31 +- include/charset.h | 15 + include/efi_api.h | 47 + include/efi_loader.h | 58 +- include/image.h | 17 +- include/pe.h | 16 + lib/charset.c | 25 + lib/efi_loader/Kconfig | 13 + lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_boottime.c | 2 +- lib/efi_loader/efi_image_loader.c | 364 ++++++- lib/efi_loader/efi_setup.c | 5 + lib/efi_loader/efi_signature.c | 602 ++++++++++++ lib/efi_loader/efi_variable.c | 928 ++++++++++++++++-- test/py/tests/test_efi_secboot/conftest.py | 168 ++++ test/py/tests/test_efi_secboot/defs.py | 7 + .../py/tests/test_efi_secboot/test_authvar.py | 287 ++++++ test/py/tests/test_efi_secboot/test_signed.py | 97 ++ .../tests/test_efi_secboot/test_unsigned.py | 126 +++ test/unicode_ut.c | 13 + 25 files changed, 2714 insertions(+), 127 deletions(-) create mode 100644 lib/efi_loader/efi_signature.c create mode 100644 test/py/tests/test_efi_secboot/conftest.py create mode 100644 test/py/tests/test_efi_secboot/defs.py create mode 100644 test/py/tests/test_efi_secboot/test_authvar.py create mode 100644 test/py/tests/test_efi_secboot/test_signed.py create mode 100644 test/py/tests/test_efi_secboot/test_unsigned.py