From patchwork Sun Apr 16 12:07:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 8252 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1522919vqo; Sun, 16 Apr 2023 05:15:18 -0700 (PDT) X-Google-Smtp-Source: AKy350Y6PW4amRhKGUxkJu2hVEI9O4O5aywogUsTKBvM4ukhVCXg0+ok/SCCCfbOCd1IE28d3p6J X-Received: by 2002:a05:6a20:29a4:b0:db:9131:dd7c with SMTP id f36-20020a056a2029a400b000db9131dd7cmr11342576pzh.39.1681647318122; Sun, 16 Apr 2023 05:15:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681647318; cv=none; d=google.com; s=arc-20160816; b=JHAE+C2abRdNUajzu+gn9yPlIJCaLSG40krExAxT3/eu5oM0gflWM6rGgTOKAx7329 8OBRQTWtiP1j9xZY/BXtmEaQKI/cNHM/OLmoHGYFW/gdS4psxPXw+/MOACGg6cl5wQxf 5i6D/x7Y0NDbAKAeHU/bEIfGhC+G1QVEycD2V391FF+5Rwwm/q/zD3xnasGQbI3giuR3 mf9HPKjtrZMYGc85GQEAa4VcYzYnd0VvpB/YAJUw0bYagQsCdNJFVWEnFB01mkx9Xr+E 6gzI8Hhf8x29thuJpruxLRiQHp/zShdvlMex3FPCY7cf4CjJsn0DtdU1awrFCuq8Odhp 35Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=y5AiJbF0m0/XXdWMUUp2QiXE8mgCAJfwGrnAV1dxnLA=; b=Rov3mtxVHgs6SkQX4T/ulW54ZdBX+T5isxUVfSWxC2XIFZdutAWuCBF9sm5yo5D/Wr u9gtQcnjVq9ilkq2UM+EQAp2cJgRQWNEuMBtlhIpnVUUYSBF3/a7wYa8Y4bQbf2GPsEL kZCfv3h3Ug6L1Gpd/yTMI4mZJyZvY0UJPfqJIPjI8wppwszXbRMKrMMdtKA9A44fWwqM qMgsk8ga/ZIKaPngT6xyRTE0RWGfblfUpvz288RkKYV/HnfLXSHhDv6MPBPny6JLxmBG usXE+6bzSgTQKpRPBK6HWHW+6+acy2OP6j9PBTtuoVAWq9rMHgTSLFqf/XjAFDAuPxjx Uy/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dZDd+E8+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 185-20020a6219c2000000b0063b630df52asi7148893pfz.252.2023.04.16.05.15.00; Sun, 16 Apr 2023 05:15:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dZDd+E8+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbjDPMIA (ORCPT + 99 others); Sun, 16 Apr 2023 08:08:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjDPMH7 (ORCPT ); Sun, 16 Apr 2023 08:07:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFCF540E9; Sun, 16 Apr 2023 05:07:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 547D360ED7; Sun, 16 Apr 2023 12:07:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48450C433D2; Sun, 16 Apr 2023 12:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681646876; bh=sy+ObN4smYcFEbKUs0id0D8hm8sqTWwnEcjdBo0cxsA=; h=From:To:Cc:Subject:Date:From; b=dZDd+E8+gdFsHASdqCVYFPPc0eXkv1ERoDxqG5ZDKnr7yKRcrE4sI/0rWjtXgF2M7 4wAhjZHbLicB2XtAX+bpjQdF++NsnTYP7LeKfE6elVLSEpH6gGk9o/MaLP/vUdiVHZ hn7oFrJ95tI83HIWm7AFG+zKj6Fgxu8oGtGVfdpOgdvXgGRYQbHkNeB2oq7f51G2bq 9yam4LRB3tllGgtnrmMUAQWjq6aB6lC67RHYzRzGJHEMnjC+iq6tdRqja/uc///Gtc oWWInl77H4vIDPT3RfCy+Rq6cbUjIuZ+RYXWPSqlgUKuqyhnrj7cyW0ypzTbkHUo6I sfuDKic24mDow== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Gerd Hoffmann , Dave Young , Mario Limonciello , Kees Cook , Tom Lendacky , "Kirill A . Shutemov" , Linus Torvalds Subject: [RFC PATCH 0/3] efi: Implement generic zboot support Date: Sun, 16 Apr 2023 14:07:26 +0200 Message-Id: <20230416120729.2470762-1-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3857; i=ardb@kernel.org; h=from:subject; bh=sy+ObN4smYcFEbKUs0id0D8hm8sqTWwnEcjdBo0cxsA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIcX6yd/FnxwaVu2Z+O2c7ObCjXHiWW9ifjz85HvtXKb9D A+To9eZO0pZGMQ4GGTFFFkEZv99t/P0RKla51myMHNYmUCGMHBxCsBENoox/E+TO3T910+/WZKL Nx5dOunrm/NrOW73yPzwb6ir//9q7/+tDP+jTep338wvS3l44OK2rND8p1UmLhoFjNP+Kh590a+ fNI0VAA== X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763335018179090346?= X-GMAIL-MSGID: =?utf-8?q?1763335018179090346?= This series is a proof-of-concept that implements support for the EFI zboot decompressor for x86. It replaces the ordinary decompressor, and instead, performs the decompression, KASLR randomization and the 4/5 level paging switch while running in the execution context of EFI. This simplifies things substantially, and makes it straight-forward to abide by stricter future requirements related to the use of writable and executable memory under EFI, which will come into effect on x86 systems that are certified as being 'more secure', and ship with an even shinier Windows sticker. This is an alternative approach to the work being proposed by Evgeny [0] that makes rather radical changes to the existing decompressor, which has accumulated too many features already, e.g., related to confidential compute etc. EFI zboot images can be booted in two ways: - by EFI firmware, which loads and starts it as an ordinary EFI application, just like the existing EFI stub (with which it shares most of its code); - by a non-EFI loader that parses the image header for the compression metadata, and decompresses the image into memory and boots it. Realistically, the second option is unlikely to ever be used on x86, given that it already has its existing bzImage, but the first option is a good choice for distros that target EFI boot only (and some distros switched to this format already for arm64). The fact that EFI zboot is implemented in the same way on arm64, RISC-V, LoongArch and [shortly] ARM helps with maintenance, not only of the kernel itself, but also the tooling around it relating to kexec, code signing, deployment, etc. Series can be pulled from [1], which contains some prerequisite patches that are only tangentially related. [0] https://lore.kernel.org/all/cover.1678785672.git.baskov@ispras.ru/ [1] https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=efi-x86-zboot Cc: Evgeniy Baskov Cc: Borislav Petkov Cc: Andy Lutomirski Cc: Dave Hansen Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Alexey Khoroshilov Cc: Peter Jones Cc: Gerd Hoffmann Cc: Dave Young Cc: Mario Limonciello Cc: Kees Cook Cc: Tom Lendacky Cc: Kirill A. Shutemov Cc: Linus Torvalds Ard Biesheuvel (3): efi/libstub: x86: Split off pieces shared with zboot efi/zboot: x86: Implement EFI zboot support efi/zboot: x86: Clear NX restrictions on populated code regions arch/x86/Makefile | 18 +- arch/x86/include/asm/efi.h | 10 + arch/x86/kernel/head_64.S | 15 + arch/x86/zboot/Makefile | 29 + drivers/firmware/efi/Kconfig | 2 +- drivers/firmware/efi/libstub/Makefile | 15 +- drivers/firmware/efi/libstub/Makefile.zboot | 2 +- drivers/firmware/efi/libstub/efi-stub-helper.c | 3 + drivers/firmware/efi/libstub/x86-stub.c | 592 +------------------ drivers/firmware/efi/libstub/x86-zboot.c | 322 ++++++++++ drivers/firmware/efi/libstub/x86.c | 612 ++++++++++++++++++++ drivers/firmware/efi/libstub/zboot.c | 3 +- drivers/firmware/efi/libstub/zboot.lds | 5 + 13 files changed, 1031 insertions(+), 597 deletions(-) create mode 100644 arch/x86/zboot/Makefile create mode 100644 drivers/firmware/efi/libstub/x86-zboot.c create mode 100644 drivers/firmware/efi/libstub/x86.c