From patchwork Tue Jul 5 05:48:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 587430 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1ec:0:0:0:0 with SMTP id 12csp1446462map; Mon, 4 Jul 2022 22:49:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u0PTobfQKkJlbGQoUudXnovFspaTEM5RagmnpBhdxwGlc+I9NiUCn8YOr997oj3C8nubBa X-Received: by 2002:a05:6512:1307:b0:47f:baa4:52c5 with SMTP id x7-20020a056512130700b0047fbaa452c5mr19996100lfu.103.1657000141026; Mon, 04 Jul 2022 22:49:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657000141; cv=none; d=google.com; s=arc-20160816; b=JzYTRpByOlG/01wxAlukn8LQ7Xw84+HJWfcDqfAV64XxE1J6av9j/SnzuYGOXsVz+l W/rrbXWjUMzQsHdawG8l2HvYoQ2iZG2aZ5H4BmuXDy9rAILOaT9ix9mTLKoO9HMr0m8+ xiP8/csEbIvi2mvO7KDi57GZu7gTw2Beu/uelIx0pdZ4+uxYsBXSPyjV/6mpfNGsGyGd 8+4aayVFh2e1espQ7m7tFzVoEmJeacElDi+nHz4t3LLKlKM0nq223u17EafJsYKC2rju IHBEne23bpOcrc9jwH8WWwJTahyPNuj4mZ34pccfa/HXc+PUi5E1CSKbM5ZBsEmS1cY+ bAMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=tZOspA1k0JkbHGeY8rKuBkNr0EUjRE/kDOuiZ/LxGus=; b=NvEG2GFn36rhm6h5hCnFd8P08Mce/oKu9ZXg4KugJeKbTf0afeC6E4QWM7oRycwoN4 iseReAFYh/To52hGioqo6agaWwXvudJB1HUexjpl6DjJhDsv8ahjbDXG5M0aVFAevBL+ K+7osMydoK10JSNzmgkJhc6/PAwXNk66PTEfBiaSyBpEydEqrILX/bk5w5oQUeNccJHD wWILVg+ndtO2pU20I3iIOLvLsLgjl+ReNYpJmStk7ynyTkw0NwBpr5ILDFZ3v6e2ZXEc +Mn5Sx0q0pRZC8iPw62fv//MMU7dKpEa9DaO/n9dHfbcpY3hS3FxbLAOiimZaobi+C2w R0KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZgFxhCoP; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id x24-20020a2e9dd8000000b0025a766b5df5si8107791ljj.207.2022.07.04.22.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 22:49:01 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZgFxhCoP; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3D84A844EC; Tue, 5 Jul 2022 07:48:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (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=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ZgFxhCoP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AB2C5844E8; Tue, 5 Jul 2022 07:48:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 11981844E8 for ; Tue, 5 Jul 2022 07:48:54 +0200 (CEST) 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-x631.google.com with SMTP id n10so10166706plp.0 for ; Mon, 04 Jul 2022 22:48:53 -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=tZOspA1k0JkbHGeY8rKuBkNr0EUjRE/kDOuiZ/LxGus=; b=ZgFxhCoP6O4/qttcO3oAuRyPkeKY3nmkBzhIcvCDzHK/M/5QIvsUhfOE3vAES5O4El EI3i53iNVkC86aEmB5TCaSPkSLupZ4IB/A2lBZBxYNt59nVQbbhJwZXvy6FXdG3rMy1v ajGusHGiJ+IOF4HuPDxYu4I+zrf3kUDrynCBg7LGGiGlF6FgHaXGXxb65E6lIwGTFTe6 hDAOTUNXPsZgx9BLT12SuTsIabpLLWjv+yWCMSAj6QP0Hibyz+YNjPJWLzYCcx6Kxj4T R7c7+sWzcJ1yTVt2aCM+78t+yPOHMlj3AhAkNqObcEa2qwBlGJd61Gy0/DCk9P4kJv5t L18g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tZOspA1k0JkbHGeY8rKuBkNr0EUjRE/kDOuiZ/LxGus=; b=n9dcdHY5uEnVzZAmdecG6hTrd8KWNZYMAgI3GUjdbeUkMmIBmRdcpSw2YbDn2OAvUP m5jYuNvB6vaUlIePQ1A6uCJ0FkQuD7hSRnN4HvzcDkupN6Y82uvcTQZJA4pSiJwjPZXS dZo7s5ZUHjU3TWoe+GCzJmtmxsJWshUUMUJ/0dk7eZF+8BJKbAGLL99+bf4UbAAVexYx AiajaF6lhTQMpqopVpP+pAPYyFzFdIDE03cux/YJAqn9fyCSbC0ZSX5wH40J6OWAbRUq lVwRFtuRZhKpmwS5Sk3nL59s7afMoLNWG2JdePnT/hzjr66BzngN6I3sFE7ZfTcDlDw6 MG+A== X-Gm-Message-State: AJIora/9CiDOFIdh0ArivCqJ7NfwlCQVUUXMctNVQxBmXog8uuD2ga0W AkxDd62L256iATULIl4S7e6Oyg== X-Received: by 2002:a17:903:22c5:b0:16b:f00c:3361 with SMTP id y5-20020a17090322c500b0016bf00c3361mr2842012plg.32.1657000132327; Mon, 04 Jul 2022 22:48:52 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c3e1:100:8c42:b67b:3e2f:7653]) by smtp.gmail.com with ESMTPSA id a5-20020a1709027e4500b0016784c93f23sm22149390pln.197.2022.07.04.22.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 22:48:51 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de Cc: ilias.apalodimas@linaro.org, baocheng.su@siemens.com, jan.kiszka@siemens.com, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH 0/5] efi_loader: fix a verification process issue in secure boot Date: Tue, 5 Jul 2022 14:48:10 +0900 Message-Id: <20220705054815.30318-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean In the commit 4540dabdcaca ("efi_loader: image_loader: support image authentication"), U-Boot implementation of UEFI secure boot was introduced. It was reported by a Siemens engineer, however, that the verification process is not fully compliant with MicroSoft's authenticode specification and it is possible to exploit the code in a signed PE image without deep knowledge. This patch series fixes this security issue and, in addition, adds a test case. patch#1-3: preparatory patches patch#4: add a missing step in signature verification process patch#5: a new test case under pytest AKASHI Takahiro (5): lib: crypto: add mscode_parser efi_loader: signature: export efi_hash_regions() efi_loader: image_loader: replace EFI_PRINT with log macros efi_loader: image_loader: add a missing digest verification for signed PE image test/py: efi_secboot: add a test for a forged signed image include/crypto/mscode.h | 43 ++++++ include/efi_loader.h | 2 + lib/crypto/Kconfig | 9 ++ lib/crypto/Makefile | 12 ++ lib/crypto/mscode.asn1 | 28 ++++ lib/crypto/mscode_parser.c | 135 ++++++++++++++++++ lib/efi_loader/Kconfig | 1 + lib/efi_loader/efi_image_loader.c | 114 +++++++++++---- lib/efi_loader/efi_signature.c | 4 +- test/py/tests/test_efi_secboot/conftest.py | 3 + test/py/tests/test_efi_secboot/forge_image.sh | 5 + test/py/tests/test_efi_secboot/test_signed.py | 35 +++++ 12 files changed, 361 insertions(+), 30 deletions(-) create mode 100644 include/crypto/mscode.h create mode 100644 lib/crypto/mscode.asn1 create mode 100644 lib/crypto/mscode_parser.c create mode 100644 test/py/tests/test_efi_secboot/forge_image.sh