Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1740283rda; Tue, 24 Oct 2023 01:32:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHMA5BRzNA1Nsu3i2fqu+/A4q5GWxKyx672xaKj6jY3X7tWM6/nckHeRxEAhjHjDrWBT82 X-Received: by 2002:a05:6a00:2e97:b0:692:a727:1fdd with SMTP id fd23-20020a056a002e9700b00692a7271fddmr14363249pfb.4.1698136375890; Tue, 24 Oct 2023 01:32:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698136375; cv=none; d=google.com; s=arc-20160816; b=U1+TztWmNMJWr/PFkRhQd2B9kCBykU2PuiAb1OagTz+5c0ky33CAILX+tlLjfyhMdF Hc22XGHig0f/BfaoFjiLncLxFWErLQ0I+wwiALRIVzO31iVeVYPlQtzCYhciWiOm+LY4 cdXTmK06n/DUljNcgGtfrDOWjpBt4QHtJTM8Ba0tmJCnEJlTpSDvnr73lEW4LFeZX3mh Smuh3lX2xFRtAPgV0IqH48aX7z5iy6I2+iXi7ep5FeOEjpVIdNzIEi5XoDFhad4/RmBW ov0HVQUQeNU5mk8zNPmTfRNxk4TuhR2xD5R55a2MSMPFfUNAzQ1ZKNp9X5BoYQ61Mcol fgnw== 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=ITFJy6PL18AxXcQ0tJtKX/riP17Qh3+LpE2GcIDMeCU=; fh=3MSZ23Xq9U1rrq473F/ZVmLPcObprEungexq3fQsBbo=; b=GqW5t42d7fFnBelYewYXMFyHysYM+sHEwlPT9vCGct/2XYvVVsZkzcO2pU7HI6QYWP jhgG796RjNPPKb4/jQWjstjlcOLKPJqUPBpmnCxQ57MUIfEyOXQ5juVB9E6auYeFshKN yEgtzkygFNPQZxAsk8nlHN+Ze8gmGeVK6pjitZwY4uaLlZPAScfgeL6VSA9cwYeDPiWo dLmI/TATsH/fFs38PouZ8oL3xWKoOHwP0MBO9ZmOCxOX8xDQ6YXLc4FFBxVcvein+Wwy ougq7SiqzF6ZRzofsNWftKgSl/pz9R51IzMp5KMhKc7Bkq92saob2U34pT4S/02rSM26 vWrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dFy3KW0S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id c28-20020a056a00009c00b006b6119c4695si7937282pfj.380.2023.10.24.01.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 01:32:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dFy3KW0S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D45A180ACFF0; Tue, 24 Oct 2023 01:32:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233905AbjJXIcm (ORCPT + 99 others); Tue, 24 Oct 2023 04:32:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233341AbjJXIcl (ORCPT ); Tue, 24 Oct 2023 04:32:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0067C10D7 for ; Tue, 24 Oct 2023 01:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698136307; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ITFJy6PL18AxXcQ0tJtKX/riP17Qh3+LpE2GcIDMeCU=; b=dFy3KW0SV74+SGVa0/t7EawHPFUSTH3ropzlqORy6kW3dEpVLTtj6ye8JlNolZMd3gUooz HL9rB2GoS7gmV0QqhaudOSUHkOlDjtpxEItHn3dj3cmK/rOaDfA2NtlJf5ELjQFpk7muNb W7RhehYCLP/EFnLJBEmrSoJ2r6QS9r4= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-G5cFkz2QN86mT_4t5uKirA-1; Tue, 24 Oct 2023 04:31:45 -0400 X-MC-Unique: G5cFkz2QN86mT_4t5uKirA-1 Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-7a944728f92so44610839f.0 for ; Tue, 24 Oct 2023 01:31:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698136305; x=1698741105; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ITFJy6PL18AxXcQ0tJtKX/riP17Qh3+LpE2GcIDMeCU=; b=Cn0RQwoFXQtwJc2HPpXz+yfCoREzJ1roihcKw8bpGkrI3Z7JuSdYBRTt0z2KC1t7cR EyiYiqZAoXOhAjL5piMvyVcWUA76JQJAqsevsvdpR4Jvy8pky1cD8pMJPV3f5dfOxe6K zNU2NHIlus+To6ojsrzRN1GBBUQ3uJbkn4DQfcB8kf1yNZroy1AvEOZkobuKTRiA87sD iAQXdyrqTH+ibBlfnwjgKy+GFpxkLf9iCyw3efKg6PFVNzCwh7BswAmjKLK/+adOghBq kkBHPlVOFwKfmwDXw6B9nUw/XhaUM9dFf02iKX/bKf05oq6PftpqiliyCEgKZezf+WmV 4XSw== X-Gm-Message-State: AOJu0Yzq/dspz8/eoUiryqvGKzMK5YksIhYLfgXoRA1xR9kgWx6aq/g3 gALxScHWKRtaoREC6iXot0Wx9BOOV0Z1Znpj65bwAkgdkEU9VGLuGrT/FESSeuKrOugHQ8ghLE1 g4SU1iVFfwcpdEcEnDJ7POfTF1bZH6yO3neEm33OA X-Received: by 2002:a05:6e02:1d9d:b0:34f:7ba2:50e8 with SMTP id h29-20020a056e021d9d00b0034f7ba250e8mr13143888ila.2.1698136304773; Tue, 24 Oct 2023 01:31:44 -0700 (PDT) X-Received: by 2002:a05:6e02:1d9d:b0:34f:7ba2:50e8 with SMTP id h29-20020a056e021d9d00b0034f7ba250e8mr13143861ila.2.1698136304468; Tue, 24 Oct 2023 01:31:44 -0700 (PDT) MIME-Version: 1.0 References: <20230912090051.4014114-17-ardb@google.com> In-Reply-To: From: Dave Young Date: Tue, 24 Oct 2023 16:31:27 +0800 Message-ID: Subject: Re: [PATCH v2 00/15] x86/boot: Rework PE header generation To: Jan Hendrik Farr Cc: Ard Biesheuvel , Ard Biesheuvel , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Evgeniy Baskov , Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner , Peter Jones , Matthew Garrett , Gerd Hoffmann , Kees Cook , "H. Peter Anvin" , "Goyal, Vivek" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 01:32:53 -0700 (PDT) On Tue, 24 Oct 2023 at 16:21, Dave Young wrote: > > On Tue, 24 Oct 2023 at 01:37, Jan Hendrik Farr wrote: > > > > On 23 13:22:53, Ard Biesheuvel wrote: > > > On Tue, 3 Oct 2023 at 04:03, Jan Hendrik Farr wrote: > > > > > > > > On 12 09:00:51, Ard Biesheuvel wrote: > > > > > From: Ard Biesheuvel > > > > > > > > > > Now that the EFI stub boot flow no longer relies on memory that is > > > > > executable and writable at the same time, we can reorganize the PE/COFF > > > > > view of the kernel image and expose the decompressor binary's code and > > > > > r/o data as a .text section and data/bss as a .data section, using 4k > > > > > alignment and limited permissions. > > > > > > > > > > Doing so is necessary for compatibility with hardening measures that are > > > > > being rolled out on x86 PCs built to run Windows (i.e., the majority of > > > > > them). The EFI boot environment that the Linux EFI stub executes in is > > > > > especially sensitive to safety issues, given that a vulnerability in the > > > > > loader of one OS can be abused to attack another. > > > > > > > > This split is also useful for the work of kexecing the next kernel as an > > > > EFI application. With the current EFI stub I have to set the memory both > > > > writable and executable which results in W^X warnings with a default > > > > config. > > > > > > > > What made this more confusing was that the flags of the .text section in > > > > current EFI stub bzImages are set to > > > > IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ. So if you load that section > > > > according to those flags the EFI stub will quickly run into issues. > > > > > > > > I assume current firmware on x86 machines does not set any restricted > > > > permissions on the memory. Can someone enlighten me on their behavior? > > > > > > > > > > No current x86 firmware does not use restricted permissions at all. > > > All memory is mapped with both writable and executable permissions, > > > except maybe the stack. > > > > > > The x86 Linux kernel has been depending on this behavior too, up until > > > recently (fixes are in -rc now for the v6.6 release). Before this, it > > > would copy its own executable image around in memory. > > > > > > So EFI based kexec will need to support this behavior if it targets > > > older x86 kernels, although I am skeptical that this is a useful > > > design goal. > > > > I don't see this as an important goal either. > > > > > I have been experimenting with running the EFI stub code in user space > > > all the way until ExitBootServices(). The same might work for UKI if > > > it is layered cleanly on top of the EFI APIs (rather than poking into > > > system registers or page tables under the hood). > > > > > > How this would work with signed images etc is TBD but I quite like the > > > idea of running everything in user space and having a minimal > > > purgatory (or none at all) if we can simply populate the entire > > > address space while running unprivileged, and just branch to it in the > > > kexec() syscall. I imagine this being something like a userspace > > > helper that is signed/trusted itself, and gets invoked by the kernel > > > to run EFI images that are trusted and tagged as being executable > > > unprivileged. > > > > I've been experimenting with running EFI apps inside kernel space instead. > > This is the more natural approach for signed images. Sure, a malicious EFI > > app could do arbitrary stuff in kernel mode, but they're signed. On the other > > hand running this entirely in user space would at least guarantee that the > > system can not crash due to a misbehaving EFI app (at least until > > ExitBootServices()). > > > > The question of whether or not to make this the job of a userspace helper that > > is signed must have come up when kexec_file_load syscall was added. It would > > have also been an option at the time to extend trust to a signed version of > > the userspace kexec tool. > > > > Why was kexec_file_load created instead of restricting kexec_load to a signed > > version of the kexec userspace tool? > > I think one of the reasons is that it is hard to handle dynamic linked > libraries, not only the kexec-tools binary. Hmm, another one is that ptrace needs to be disabled in some way, anyway I think it is way too complicated, but I do not remember the details, added Vivek in cc. See this article: https://lwn.net/Articles/532778/ > > Thanks > Dave