From patchwork Tue Jan 28 08:25:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1230202 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.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.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.a=rsa-sha256 header.s=google header.b=jqdQ3gCJ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 486KTN1lkYz9sP6 for ; Tue, 28 Jan 2020 19:26:32 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9F7BB81844; Tue, 28 Jan 2020 09:26:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="jqdQ3gCJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E2EEE81965; Tue, 28 Jan 2020 09:26:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 243EB81838 for ; Tue, 28 Jan 2020 09:26:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pl1-x644.google.com with SMTP id g6so4815020plt.2 for ; Tue, 28 Jan 2020 00:26:13 -0800 (PST) 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=TiK/c2I1d77KpQnIIOWuqrDx+Z51/G19/NiMbqF7mdw=; b=jqdQ3gCJ7po8RTOPg82CC5GveNDVlEzPmEaxC2+OrAEC1jcU/qbi076niLoxETEL6D XOx0iIfgqYvEmHHX5dJ1OM6LdcgdBWsqs2j3Xq3rsCahCU/87CK5D1NokivX9n0ugS7f C/HCnTLryYLpwpQvGxyfIvD3HuEhOCrSRs52axpp8qg23aEzczRHELoqbHQAg7iZQoWD e8nSRde9eShKJqdYsernSCMJA7qoqUJnDSO5WtZ6aSDxB2BWNepQaB5wl5OBr4u3c3kW YmNnyl7NqxlWKfH+0IAHfgr+yU6dillB/9KxufiNJrF2ErYfa3wfYKRUIU80NzMNtQkp OWoA== 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=TiK/c2I1d77KpQnIIOWuqrDx+Z51/G19/NiMbqF7mdw=; b=VgvnzIq9ZTkZY4DaivU82Ro9t8/U59RDrVMOHnwqKJfJPw1Cb9+Tl7F4Ts/ySnF0jx NVKxvKTaCZTwYIhVesmz6y+MEPu8bEuSBkDFpfFgYMEAX79EFBMimb92E7A6ZOQS968N SFpUv1psdDxZJtraLfBQHDQlM/yLq2ZAX0md3U/z6mu2ERGf/38vzcjBZP+VyPhMjWR5 tIqQ/cB5VyaqR/QMIXangeOFYzesbRN5tqyF9lFl00Ui1rJ+kzcan+w8083F327qVQhm tncgSF5tckGIjjgvCxVpT/+yVNTN01WJobOo6ic+SfG5W8J7aFlxwSH2VGBPsZaPwoL+ TuVQ== X-Gm-Message-State: APjAAAUSwqWbnGCEtwdvYR89f7GdUodPGQBZI4FM08vqpORyug2qCk9M 84DIL15gxdkPKWURD65ZeepSOg== X-Google-Smtp-Source: APXvYqwC4WQOmcy9lfODCsXA8I2rJcZT5qbTp8v8nk+/tQRq8KQHH1P9c+AwVsaAGLdHO+3sacrAMQ== X-Received: by 2002:a17:90a:cf11:: with SMTP id h17mr3439180pju.103.1580199971509; Tue, 28 Jan 2020 00:26:11 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id o19sm1732065pjr.2.2020.01.28.00.26.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 00:26:10 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de, trini@konsulko.com Subject: [PATCH v5 00/16] efi_loader: add secure boot support Date: Tue, 28 Jan 2020 17:25:16 +0900 Message-Id: <20200128082532.15943-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: u-boot@lists.denx.de, mail@patrick-wildt.de Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean # Documentation for UEFI secure boot on U-Boot will be submitted in # a separate patch in near future. 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.) Please note, however, this patch doesn't work on its own; there are a couple of functional dependencies[2] and [3], that I have submitted before. For complete workable patch set, see my repository[4], which also contains experimental timestamp-based revocation suuport. My "non-volatile" support[5], which is under discussion, 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. 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 * basic pytest test cases Unsupported features: (marked as TODO in most cases in the source code, and won't be included in this series) * 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 * verification "policy", in particular, check against signature's owner * private authenticated variables * variable authentication with EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS * real secure storage support, including hardware-specific PK (Platform Key) installation TODO's other than "Unsupported features": (won't be included in this series) * fail recovery, in particular, in modifying authenticated variables * support read-only attributes of well-defined global variables in particular, "SignatureSupport" * Extensive test suite (or more test cases) to confirm compatibility with EDK2 => I requested EDK SCT community to add tests[6]. Test: * My pytest, included in this patch set, passed. * efi_selftest passed. (At least no regression.) * Travis CI tests have passed. Known issues: * efitools is used in pytest, and its version must be v1.5.2 or later. (Solution: You can define EFITOOLS_PATH in defs.py for your own efitools.) 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 sbsign (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-November/390127.html (import x509/pkcs7 parsers from linux) [3] https://lists.denx.de/pipermail/u-boot/2020-January/398057.html (extend rsa_verify() for UEFI secure boot) [4] http://git.linaro.org/people/takahiro.akashi/u-boot.git/ efi/secboot [5] https://lists.denx.de/pipermail/u-boot/2019-September/382835.html (non-volatile variables support) [6] https://bugzilla.tianocore.org/show_bug.cgi?id=2230 Changes in v5 (Jan 28, 2020) * rebased to pre-v2020.04-rc1 (fixed some merge conflicts) * remove already-merged commits (v4's patch#1) * fix a compile error caused by gcc 9.x (patch#4) * return SECURITY_VIOLATION instead of ACCESS_DENIED if authentication fails (patch#7) * use qsort() for section sorting (patch#7) * add "efidebug test" sub-command (patch#11) * add efi_start_image(SECURITY_VIOLATION) test (patch#14) Changes in v4 (Dec 18, 2019) * adjust EFI_SECURE_BOOT dependencies due to a change of RSA extension patch v5 (patch#2) * change "imply" to "select" against kconfig dependencies (patch#2) * otherwise, no functional changes Changes in v3 (Dec 9, 2019) * allow for arbitrary number of regions in efi_image_region_add() (patch#3, #5 and #8) * remove a redundant check in a while loop at efi_sigstore_free() (patch#4) Changes in v2 (Nov 26, 2019) * rebased to v2020.01-rc3 * rename IMAGE_DIRECTORY_ENTRY_CERTTABLE to IMAGE_DIRECTORY_ENTRY_SECURITY (patch#1,#9) * add comments (patch#1) * drop v1's patch#2 as it is no longer necessary * drop v1's patch#3 as other "SECURE_BOOT" architectures have renamed this option and no longer use it * add structure descriptions (patch#3) * rework hash calculation code in efi_signature_verify() and remove an odd constant, WinIndrectSha256 (patch#3) * move travis.yml changes to a separate patch (patch#12, #16) * yield_fixture() -> fixture() (patch#12) * call console.restart_uboot() at every test case (13,#14) * add patch#15; enable UEFI-related configurations by default on sandbox * add patch#16; modify Travis CI environment to run UEFI secure boot test Changes in v1 (Nov 13, 2019) * rebased to v2020.01-rc * remove already-merged patches * re-work the patch set for easier reviews, including - move a config definition patch forward (patch#4) - refactor/rename verification functions (patch#5/#10) - split signature database parser as a separate patch (patch#6) - split secure state transition code as a separate patch (patch#8) - move most part of init_secure_boot() into init_variables() (patch#8) - split test environment setup from test patches (patch#14) * add function descriptions (patch#5-#11) * make sure the section list is sorted in ascending order in hash calculation of PE image (patch#10) * add a new "-at" (authenticated access) option to "env -e" (patch#13) * list required host packages, in particular udisks2, in pytest (patch#14) * modify conftest.py to run under python3 (patch#14) * use a partition on a disk instead of a whole disk without partition table (patch#14) * reduce dependency on efitools, yet relying on its host tools (patch#14) * modify pytests to catch up wth latest changes of "env -e" syntax (patch#15,#16) RFC (Sept 18, 2019) AKASHI Takahiro (16): efi_loader: add CONFIG_EFI_SECURE_BOOT config option efi_loader: add signature verification functions efi_loader: add signature database parser efi_loader: variable: support variable authentication efi_loader: variable: add secure boot state transition efi_loader: variable: add VendorKeys variable efi_loader: image_loader: support image authentication efi_loader: set up secure boot cmd: env: use appropriate guid for authenticated UEFI variable cmd: env: add "-at" option to "env set -e" command cmd: efidebug: add "test bootmgr" sub-command efi_loader, pytest: set up secure boot environment efi_loader, pytest: add UEFI secure boot tests (authenticated variables) efi_loader, pytest: add UEFI secure boot tests (image) sandbox: add extra configurations for UEFI and related tests travis: add packages for UEFI secure boot test .travis.yml | 11 +- cmd/efidebug.c | 78 +- cmd/nvedit.c | 5 +- cmd/nvedit_efi.c | 23 +- configs/sandbox64_defconfig | 3 + configs/sandbox_defconfig | 3 + include/efi_api.h | 87 ++ include/efi_loader.h | 91 +- lib/efi_loader/Kconfig | 18 + lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_boottime.c | 10 +- lib/efi_loader/efi_image_loader.c | 460 ++++++++- lib/efi_loader/efi_setup.c | 38 + lib/efi_loader/efi_signature.c | 809 +++++++++++++++ lib/efi_loader/efi_variable.c | 951 ++++++++++++++++-- test/py/README.md | 8 + test/py/tests/test_efi_secboot/conftest.py | 151 +++ test/py/tests/test_efi_secboot/defs.py | 21 + .../py/tests/test_efi_secboot/test_authvar.py | 282 ++++++ test/py/tests/test_efi_secboot/test_signed.py | 117 +++ .../tests/test_efi_secboot/test_unsigned.py | 121 +++ 21 files changed, 3157 insertions(+), 131 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