Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2445958rwr; Fri, 28 Apr 2023 10:22:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5GbafzhruP5J52U+uDhqxSf+2/b0eIS5n6/XZuJ9y8bxM4bCivbZZKA1NfHKOLueCCGhyt X-Received: by 2002:a05:6a00:886:b0:63d:5de3:b3f2 with SMTP id q6-20020a056a00088600b0063d5de3b3f2mr9392519pfj.18.1682702576039; Fri, 28 Apr 2023 10:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682702576; cv=none; d=google.com; s=arc-20160816; b=gS5DmysG+Rc/pg+rUfhSrbi6qOpQTK588WAb0C2L6XuUgbDHLZkLODXCMYnGAIxhHI F923xLtfTx/4E36JV2so5bQn0GwItXZEp9Dp1lGq7IxKhn434H7bI4daRgD9xov0GppZ d6iEWwzVLn0RfdFgYdgLfyx9k7knk6x+u/KKrT+vZEHKILP0Xh7qE057kQg3VTv+WBjY IU3SYA6//IZsXIWD2ogEH5Zcdvse687swjC0r//CCbJgx0GH0whgRagpO8BdgUEYlakK 4Y9vz50qA+hglsvDNfTyPq71zZcQ6ePeqMohuuDi5RyVrvFCosRMEWGrqIXpLPSXdzlA X6Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TpyzCSmEZWyLTAkBjSDMRnKIO4TuDG4oDpBT6xax2qM=; b=dpjdAgX38t7B6XTjYHWqtoyl2Bk1msMaHTNX4+VWn2wDYfUcf0IgulPQHbHAk5sfEN xRY6CY5Ea6Pl9GC42e5aFZKUuTLebJ0k5XBsR2w00zd84RJMoZl+t8uliWWg6Yaiob+f HTFqXHt1qZdogsEYuJd7veR7N5B2gc7gQbZ8eH5t+nT7imx4Q7i3dIOPWXRDs2iyLjqF zs2hOTPDQhpDSRVuBEEeGctdZ3gIZ1scjQeJI2cfeEEGrmPSY6x9oUN/x5T3jN1s83z2 UJvAzxxxgxdPEmAhe+BAuaoKhaEVCuzOTrVahegbHy38rVx2M3PJaZ22db7WkA7ccWw8 EHxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aSdEfY+4; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d19-20020a656213000000b0051b70ce7dd2si20702483pgv.80.2023.04.28.10.22.42; Fri, 28 Apr 2023 10:22:56 -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=aSdEfY+4; 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 S1346186AbjD1ROo (ORCPT + 99 others); Fri, 28 Apr 2023 13:14:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjD1ROn (ORCPT ); Fri, 28 Apr 2023 13:14:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7314610C6; Fri, 28 Apr 2023 10:14:42 -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 0265160ED6; Fri, 28 Apr 2023 17:14:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 639A2C433EF; Fri, 28 Apr 2023 17:14:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682702081; bh=NiuqoaeWuPDwwSWViVSbLcMtEXaqPz9t4R/6XaWcI3I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=aSdEfY+4uZ8xYHBo8TLpN5VRvXYLh0171NctTtY5XsSubQCs3jeQvYRXxENjXXzSh N/4afR12pxKfpOdB87gwo032xAe33S0HKLFEUn7Fgwiln/+Z84Aum6DTNn20R8/AH+ 4j76waM+tQYnAqL9bFUJ7RLHe4ftGJip2l+GZg72075wzTZFllfuijmmoeO3SWFlgP RO3qNFlKXK1lNbjjshX1qZjeiAMbQpwgJ1Yi7rUH1BuAVJVdQyb4sKtOsUFYS/Bmzm NU57BuZNfSTOpRCgrOdiZ9JQhwo2XL+p4n4VRIjIE6lh38946xZ7xBgWNr3pyCTVEu eT+1E9Lb9Ckfw== Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2a8bcfbf276so96046211fa.3; Fri, 28 Apr 2023 10:14:41 -0700 (PDT) X-Gm-Message-State: AC+VfDxOD2dMo9ovBVgJlGWDFL36vjoCx1ZmkfJeQ+vpOmtp3wcy6jGw o7SApztqNZTohqP65u6Of0j1rEmp82PqSQh357c= X-Received: by 2002:a2e:8716:0:b0:2aa:af16:5c58 with SMTP id m22-20020a2e8716000000b002aaaf165c58mr1738781lji.43.1682702079348; Fri, 28 Apr 2023 10:14:39 -0700 (PDT) MIME-Version: 1.0 References: <20230424165726.2245548-1-ardb@kernel.org> <1d8389c7c4fb6efac18cc38c004f49ca@ispras.ru> In-Reply-To: <1d8389c7c4fb6efac18cc38c004f49ca@ispras.ru> From: Ard Biesheuvel Date: Fri, 28 Apr 2023 18:14:28 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 0/6] efi/x86: Avoid legacy decompressor during EFI boot To: Evgeniy Baskov Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.3 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 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 On Fri, 28 Apr 2023 at 14:23, Evgeniy Baskov wrote: > > On 2023-04-24 19:57, Ard Biesheuvel wrote: > > This series is conceptually a combination of Evgeny's series [0] and > > mine [1], both of which attempt to make the early decompressor code > > more > > amenable to executing in the EFI environment with stricter handling of > > memory permissions. > > > > My series [1] implemented zboot for x86, by getting rid of the entire > > x86 decompressor, and replacing it with existing EFI code that does the > > same but in a generic way. The downside of this is that only EFI boot > > is > > supported, making it unviable for distros, which need to support BIOS > > boot and hybrid EFI boot modes that omit the EFI stub. > > > > Evgeny's series [0] adapted the entire decompressor code flow to allow > > it to execute in the EFI context as well as the bare metal context, and > > this involves changes to the 1:1 mapping code and the page fault > > handlers etc, none of which are really needed when doing EFI boot in > > the > > first place. > > > > So this series attempts to occupy the middle ground here: it makes > > minimal changes to the existing decompressor so some of it can be > > called > > from the EFI stub. Then, it reimplements the EFI boot flow to > > decompress > > the kernel and boot it directly, without relying on the trampoline > > code, > > page table code or page fault handling code. This allows us to get rid > > of quite a bit of unsavory EFI stub code, and replace it with two clear > > invocations of the EFI firmware APIs to clear NX restrictions from > > allocations that have been populated with executable code. > > > > The only code that is being reused is the decompression library itself, > > along with the minimal ELF parsing that is required to copy the ELF > > segments in place, and the relocation processing that fixes up absolute > > symbol references to refer to the correct virtual addresses. > > > > Note that some of Evgeny's changes to clean up the PE/COFF header > > generation will still be needed, but I've omitted those here for > > brevity. > > My series also implements W^X for both UEFI and non-UEFI boot paths, but > I > agree that we can just consider non-UEFI code legacy and it would be > better > to avoid touching it and encourage everyone to use UEFI code path on x86 > instead. If PE format will also get fixed with either my patches or some > others, I do like your approach more than mine, as it removes a lot of > old > cruft but does not break things (as far as I see). Seems like a perfect > compromise between [1] and my approach. > Thanks, I'm glad we agree. > I've briefly tested the patches and looked through them and they look > good > to me. Two things I've noticed: > * there's one TSC-related TODO; > * probably we want to clear .bss in efi32_stub_entry and > efi64_stub_entry > for UEFI handover protocol, since it's unfortunately still present > and > .bss will contain garbage. I'll look into that. > I'll probably do some more testing on the weekend and let you know if I > find something. > Yes, please. > Please tell me if/when you are going to merge these or similar, and I > will > clean up and rebase PE-related patches on top of these. > > I'd also like to send W^X patches for EFISTUB (omitting the non-UEFI > boot > path) as a follow up after the PE file header will get fixed. They will > be > considerably smaller with this approach and will not touch legacy code. >