Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp796932ybt; Wed, 24 Jun 2020 11:24:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKorwQd7AyUDunnENIWpu8uPtLxPyYxkVjhhR7OtOK9ds5b+GHhONnyiHspwcRATKLsPdI X-Received: by 2002:a17:906:2e84:: with SMTP id o4mr6871589eji.65.1593023093011; Wed, 24 Jun 2020 11:24:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593023093; cv=none; d=google.com; s=arc-20160816; b=bRsySYmNzzRai74oOY1NkoUrp/UJ14l0sxdbNUshToN0vj2zyBCh0PmkSQEE46bIKu aD5zzNc2rF0Ddg0LsvDPfsmstZc001rtdfmG0cgnyp926U2mD0X7nGXg6dc3Kz/+/Csc QyocU4bPJWJtMc+SGDtFqSCTWWxzvPSetBE3caX+ucGuwWMEOpC+2KK7AKGuMi6Jfeck xrCy4uNe/f9guOEe1RWJvReb/bYo9XWc9C6bZpaTmObX7nEvh6qLGzrwK8KGPqovOIUo sgvNXqi86xxX8UNKSnaRZwaGET9M6kwcDbd8Xqbo2ZydcHMI5pPBNNzFRkflvsqMiLpC OtOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QMzkwj2wsknevPPq60SbMcXJOGOru8KLNDodk/beSis=; b=it+B8DnelD0o02KTtGn/P6NbPLNuSH6qbph1wabXQAjtvTDZNpwj23F7FP5vztt47R mRzeDUxTbQ6qwQb7+ruCtAM4BWJQnjGuMq1XNl96RIlclY9E4aNFTOkcq7riBcOHmf0a S3i1HrN4Vej99Y0/TLFRWhP9fPRunWJGmHDiiEfoZjp1i0wtZ9set6n4hVPUZVF2oIrk upNRLlCsTo82vJ+P3laXeDWQzFU7aGvKNyjkY+XdCOEPX/2mhGRrxBvzmICu2GZBaye/ gL5TtE1sVFmgrEY2zfCw87G0rhiE+KnwfQ1XWboyPAvZ/KxFjZDnDTRmxz+HKvK/iAMJ WNTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bRtaoBxn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q26si6403384eja.585.2020.06.24.11.24.27; Wed, 24 Jun 2020 11:24:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bRtaoBxn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2405998AbgFXSXS (ORCPT + 99 others); Wed, 24 Jun 2020 14:23:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:40988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405469AbgFXSXR (ORCPT ); Wed, 24 Jun 2020 14:23:17 -0400 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE1A0207FC; Wed, 24 Jun 2020 18:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593022996; bh=ZF4PxoE2gxKJKGHg1jFJn1yz5MUXPaZ030E8kTj+DE4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bRtaoBxn1ZeKTiqgV++Nwoq7bTRDmjNRHfzGTMcHitS7vaxi4jjIenOaMdghJ0Lfz ifGlOYXyH8iHLUFM2rkvjpZsNxIbGgCiPqBnt/jE24sR8KMwcA/fP8VK+Pi+grXNI6 mwvMNKzv00Vqqm6/UINgackm2GJyjAIMDl3YyC9o= Received: by mail-ot1-f45.google.com with SMTP id 64so2838975oti.5; Wed, 24 Jun 2020 11:23:16 -0700 (PDT) X-Gm-Message-State: AOAM530qVi7Xh97QvdMbB7klJEjxUxbq/Sbvx6YhL8z9pHMucAtd+AL3 kI/lO+qUUwIrVqWxf0rHFTnjW9weIp1atNh3FN8= X-Received: by 2002:a4a:b34b:: with SMTP id n11mr24365561ooo.41.1593022995076; Wed, 24 Jun 2020 11:23:15 -0700 (PDT) MIME-Version: 1.0 References: <20200624033142.cinvg6rbg252j46d@google.com> <202006232143.66828CD3@keescook> <20200624104356.GA6134@willie-the-truck> <202006240820.A3468F4@keescook> <202006240844.7BE48D2B5@keescook> <20200624162919.GH25945@arm.com> <20200624171613.GJ25945@arm.com> In-Reply-To: <20200624171613.GJ25945@arm.com> From: Ard Biesheuvel Date: Wed, 24 Jun 2020 20:23:03 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 3/9] efi/libstub: Remove .note.gnu.property To: Dave Martin Cc: Mark Rutland , linux-efi , Catalin Marinas , Arvind Sankar , Will Deacon , Nathan Chancellor , linux-arch , Fangrui Song , Masahiro Yamada , X86 ML , Russell King , clang-built-linux , Ingo Molnar , Borislav Petkov , Kees Cook , Arnd Bergmann , Thomas Gleixner , Peter Collingbourne , Linux ARM , Nick Desaulniers , Linux Kernel Mailing List , James Morse Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 24 Jun 2020 at 19:16, Dave Martin wrote: > > On Wed, Jun 24, 2020 at 06:40:48PM +0200, Ard Biesheuvel wrote: > > On Wed, 24 Jun 2020 at 18:29, Dave Martin wrote: > > > > > > On Wed, Jun 24, 2020 at 05:48:41PM +0200, Ard Biesheuvel wrote: > > > > On Wed, 24 Jun 2020 at 17:45, Kees Cook wrote: > > > > > > > > > > On Wed, Jun 24, 2020 at 05:31:06PM +0200, Ard Biesheuvel wrote: > > > > > > On Wed, 24 Jun 2020 at 17:21, Kees Cook wrote: > > > > > > > > > > > > > > On Wed, Jun 24, 2020 at 12:46:32PM +0200, Ard Biesheuvel wrote: > > > > > > > > I'm not sure if there is a point to having PAC and/or BTI in the EFI > > > > > > > > stub, given that it runs under the control of the firmware, with its > > > > > > > > memory mappings and PAC configuration etc. > > > > > > > > > > > > > > Is BTI being ignored when the firmware runs? > > > > > > > > > > > > Given that it requires the 'guarded' attribute to be set in the page > > > > > > tables, and the fact that the UEFI spec does not require it for > > > > > > executables that it invokes, nor describes any means of annotating > > > > > > such executables as having been built with BTI annotations, I think we > > > > > > can safely assume that the EFI stub will execute with BTI disabled in > > > > > > the foreseeable future. > > > > > > > > > > yaaaaaay. *sigh* How long until EFI catches up? > > > > > > > > > > That said, BTI shouldn't _hurt_, right? If EFI ever decides to enable > > > > > it, we'll be ready? > > > > > > > > > > > > > Sure. Although I anticipate that we'll need to set some flag in the > > > > PE/COFF header to enable it, and so any BTI opcodes we emit without > > > > that will never take effect in practice. > > > > > > In the meantime, it is possible to build all the in-tree parts of EFI > > > for BTI, and just turn it off for out-of-tree EFI binaries? > > > > > > > Not sure I understand the question. What do you mean by out-of-tree > > EFI binaries? And how would the firmware (which is out of tree itself, > > and is in charge of the page tables, vector table, timer interrupt etc > > when the EFI stub executes) distinguish such binaries from the EFI > > stub? > > I'm not an EFI expert, but I'm guessing that you configure EFI with > certain compiler flags and build it. 'EFI' is not something you build. It is a specification that describes how a conformant firmware implementation interfaces with a conformant OS. Sorry to be pedantic, but that is really quite relevant. By adhering to the EFI spec rigorously, we no longer have to care about who implements the opposite side, and how. So yes, of course there are ways to build the opposite side with BTI enabled, in a way that all its constituent pieces keep working as expected. A typical EDK2 based implementation of EFI consists of 50-100 individual PE/COFF executables that all get loaded, relocated and started like ordinary user space programs. What we cannot do, though, is invent our own Linux specific way of decorating the kernel's PE/COFF header with an annotation that instructs a Linux specific EFI loader when to enable the GP bit for the .text pages. > Possibly some standalone EFI > executables are built out of the same tree and shipped with the > firmware from the same build, but I'm speculating. If not, we can just > run all EFI executables with BTI off. > > > > If there's no easy way to do this though, I guess we should wait for / > > > push for a PE/COFF flag to describe this properly. > > > > > > > Yeah good point. I will take this to the forum. > > In the interim, we could set the GP bit in EFI's page tables for the > executable code from the firmware image if we want this protection, but > turn it off in pages mapping the executable code of EFI executables. > This is better than nothing. > We need to distinguish between the EFI stub and the EFI runtime services here. The EFI stub consists of kernel code that executes in the context of the firmware, at which point the loader has no control whatsoever over page tables, vector tables, etc. This is the stage where the loading and starting of PE/COFF images takes place. If we want to enable BTI for code running in this context, we need PE/COFF annotations, as discussed above. The EFI runtime services are firmware code that gets invoked by the OS at runtime. Whether or not such code is emitted with BTI annotations is a separate matter (but should also be taken to the forum nonetheless), and does not need any changes at the PE/COFF level. However, for this code, I'd like the sandboxing to be much more rigorous than it is today, to the point where the security it provides doesn't even matter deeply to the OS itself. (I had some patches a while ago that reused the KPTI infrastructure to unmap the entire kernel while EFI runtime services are in progress. There was also an intern in the team that implemented something similar on top of KVM)