From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 34D6BD80591 for ; Wed, 15 Jan 2025 18:53:12 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=n6kHtFUrpmYcHu5gAl2Q35EVBn9Dl0Ot2FeVX/ojvag=; c=relaxed/simple; d=groups.io; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:To:Cc:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20240830; t=1736967191; v=1; x=1737226390; b=PaUeqXOcCkflrcnFljtX3mtzGrac0E7Je76N6N4DjDjkA9jUdeMitBwD/uCOaA5WtAbvQvHX bgbIc8lHn11tElSwqudfofMPuj5V9Zz0p/7jMaX52KO6sOWjrY8NdTdCuGbw8uwW0CnrihQ4Fqf 5f6fKtYPvzUzlrRcrL8Mz9A1rEccBj3/QWXKYInDqrZJItfTheKdzTH6QD5WIsh0+EW5y1avq6i s48KvpGOM3qcpjI56zGNZ2JWwVbWSrwchf3wikGk97uHgfdYEvXe9M83ULgoOTZuCL23V3y92BZ 4x1yuuhHUIinnX67eB/6Y+6zGf8SSK8MykwP7jktBFVYw== X-Received: by 127.0.0.2 with SMTP id m75AYY7687511xQlbpUq4o2p; Wed, 15 Jan 2025 10:53:10 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.8526.1736735607453660105 for ; Sun, 12 Jan 2025 18:33:27 -0800 X-Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-533-1sTx6LCjO2Cf8ti0XVfRtQ-1; Sun, 12 Jan 2025 21:33:25 -0500 X-MC-Unique: 1sTx6LCjO2Cf8ti0XVfRtQ-1 X-Mimecast-MFC-AGG-ID: 1sTx6LCjO2Cf8ti0XVfRtQ X-Received: by mail-il1-f199.google.com with SMTP id e9e14a558f8ab-3ab68717b73so32325115ab.2 for ; Sun, 12 Jan 2025 18:33:24 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXAoXV8NMFTWCTpD503/gdOWQ9KqW2JkKmqT/1dI1LbDhfwPMpvs6i/ws0o2OiAKfQy3IvBFw==@edk2.groups.io X-Gm-Message-State: o0FB9zEtsZCfqkCGUD6rroBjx7686176AA= X-Gm-Gg: ASbGnctxlC1lZCcfExFsZzDx4pu2BvCpC+q67jZbvxB5W1shyfAJWMiIy3mPLdWheeV Rd5O7T/iMvLV1jYOiprXNDnCYSznUVzhT2OY6HFU= X-Received: by 2002:a05:6e02:308b:b0:3a7:6c6a:e2a2 with SMTP id e9e14a558f8ab-3ce3a9b8f55mr145581525ab.9.1736735604321; Sun, 12 Jan 2025 18:33:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHX/BB3a+x1+hlFag+y4MCY2vYZR+JO6tZHm61qqMxdGOWka7/7g093c98crf0DIa7amAkRJIPbGaJHsF5lggk= X-Received: by 2002:a05:6e02:308b:b0:3a7:6c6a:e2a2 with SMTP id e9e14a558f8ab-3ce3a9b8f55mr145581395ab.9.1736735604015; Sun, 12 Jan 2025 18:33:24 -0800 (PST) MIME-Version: 1.0 References: <20250108215957.3437660-1-usamaarif642@gmail.com> <20250108215957.3437660-2-usamaarif642@gmail.com> <8613563a-ee7c-4271-b1f0-4d1ac365ad3a@gmail.com> In-Reply-To: <8613563a-ee7c-4271-b1f0-4d1ac365ad3a@gmail.com> From: "Dave Young via groups.io" Date: Mon, 13 Jan 2025 10:33:29 +0800 X-Gm-Features: AbW1kvYKcHAghdXJwnimGQLKt2N80oQHvYivo3yXntwzaQ6sbrU260HdmO9BHWo Message-ID: Subject: Re: [edk2-devel] [RFC 1/2] efi/memattr: Use desc_size instead of total size to check for corruption To: Usama Arif Cc: Ard Biesheuvel , linux-efi@vger.kernel.org, devel@edk2.groups.io, kexec@lists.infradead.org, hannes@cmpxchg.org, x86@kernel.org, linux-kernel@vger.kernel.org, leitao@debian.org, gourry@gourry.net, kernel-team@meta.com X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wdHfoHRN7TP_O4B03pjiknpHXa2BbB7tbMm9G6vSCDg_1736735604 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Resent-Date: Wed, 15 Jan 2025 10:52:53 -0800 Resent-From: dyoung@redhat.com Reply-To: devel@edk2.groups.io,dyoung@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: text/plain; charset="UTF-8" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240830 header.b=PaUeqXOc; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=pass (policy=none) header.from=groups.io On Fri, 10 Jan 2025 at 18:54, Usama Arif wrote: > > > > On 10/01/2025 07:21, Ard Biesheuvel wrote: > > On Thu, 9 Jan 2025 at 17:36, Usama Arif wrote: > >> > >> > >> > >> On 09/01/2025 15:45, Ard Biesheuvel wrote: > >>> On Wed, 8 Jan 2025 at 23:00, Usama Arif wrote: > >>>> > >>>> The commit in [1] introduced a check to see if EFI memory attributes > >>>> table was corrupted. It assumed that efi.memmap.nr_map remains > >>>> constant, but it changes during late boot. > >>>> Hence, the check is valid during cold boot, but not in the subsequent > >>>> kexec boot. > >>>> > >>>> This is best explained with an exampled. At cold boot, for a test > >>>> machine: > >>>> efi.memmap.nr_map=91, > >>>> memory_attributes_table->num_entries=48, > >>>> desc_size = 48 > >>>> Hence, the check introduced in [1] where 3x the size of the > >>>> entire EFI memory map is a reasonable upper bound for the size of this > >>>> table is valid. > >>>> > >>>> In late boot __efi_enter_virtual_mode calls 2 functions that updates > >>>> efi.memmap.nr_map: > >>>> - efi_map_regions which reduces the `count` of map entries > >>>> (for e.g. if should_map_region returns false) and which is reflected > >>>> in efi.memmap by __efi_memmap_init. > >>>> At this point efi.memmap.nr_map becomes 46 in the test machine. > >>>> - efi_free_boot_services which also reduces the number of memory regions > >>>> available (for e.g. if md->type or md->attribute is not the right value). > >>>> At this point efi.memmap.nr_map becomes 9 in the test machine. > >>>> Hence when you kexec into a new kernel and pass efi.memmap, the > >>>> paramaters that are compared are: > >>>> efi.memmap.nr_map=9, > >>>> memory_attributes_table->num_entries=48, > >>>> desc_size = 48 > >>>> where the check in [1] is no longer valid with such a low efi.memmap.nr_map > >>>> as it was reduced due to efi_map_regions and efi_free_boot_services. > >>>> > >>>> A more appropriate check is to see if the description size reported by > >>>> efi and memory attributes table is the same. > >>>> > >>>> [1] https://lore.kernel.org/all/20241031175822.2952471-2-ardb+git@google.com/ > >>>> > >>>> Fixes: 8fbe4c49c0cc ("efi/memattr: Ignore table if the size is clearly bogus") > >>>> Reported-by: Breno Leitao > >>>> Signed-off-by: Usama Arif > >>>> --- > >>>> drivers/firmware/efi/memattr.c | 16 ++++++---------- > >>>> 1 file changed, 6 insertions(+), 10 deletions(-) > >>>> > >>> > >>> The more I think about this, the more I feel that kexec on x86 should > >>> simply discard this table, and run with the firmware code RWX (which > >>> is not the end of the world). > >> > >> > >> By discard this table, do you mean kexec not use e820_table_firmware? > > > > No, I mean kexec ignores the memory attributes table. > > > >> Also a very basic question, what do you mean by run with the firmware RWX? > >> > > > > The memory attributes table is an overlay for the EFI memory map that > > describes which runtime code regions may be mapped with restricted > > permissions. Without this table, everything will be mapped writable as > > well as executable, but only in the EFI page tables, which are only > > active when an EFI call is in progress. > > > > Thanks for explaining! > > So basically get rid of memattr.c :) > > Do you mean get rid of it only for kexec, or not do it for any > boot (including cold boot)? > I do like this idea! I couldn't find this in the git history, > but do you know if this was added in the linux kernel just > because EFI spec added support for it, or if there was a > specific security problem? > Usama, can you try the patch below? [ format is wrong due to webmail corruption. But if it works I can send a formal patch later ] $ git diff arch/x86 diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index 846bf49f2508..58dc77c5210e 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -561,6 +561,11 @@ int __init efi_reuse_config(u64 tables, int nr_tables) if (!efi_guidcmp(guid, SMBIOS_TABLE_GUID)) ((efi_config_table_64_t *)p)->table = data->smbios; + + /* Not bother to play with mem attr table across kexec */ + if (!efi_guidcmp(guid, EFI_MEMORY_ATTRIBUTES_TABLE_GUID)) + ((efi_config_table_64_t *)p)->table = EFI_INVALID_TABLE_ADDR; + p += sz; } -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#121015): https://edk2.groups.io/g/devel/message/121015 Mute This Topic: https://groups.io/mt/110517813/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-