From nobody Fri May 3 22:10:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=trmm.net ARC-Seal: i=1; a=rsa-sha256; t=1600357311; cv=none; d=zohomail.com; s=zohoarc; b=nPcq6IodqmtGs3TwAiadPLxPztJd5rVmREzUvoiBn7UAl1dS95TIizKFGE/ta4pH5liVxniX8hvTOufx+2ymltgHuYzHxVN2/Kig3OjimT1mY8nIk5MxFi5bHBl8v7AEfkf7ppXahhUSH2kuQBZPollnB4yiMMXyngEzdQ6Abp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600357311; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KoorgS5vb4I78/o+/MRn2hjj3862/RPntR69nDG6Ybc=; b=gpctURjfgSbighf5hSznplBb2eV9F9N2hH3MnHJyaZ10IwCFTSGUZYI1TRw8BioB6G9LSxMlrvM/7ekiy+Ipg7f+D7h+5MtyPWGk+QG3lbmt9Mkx2tySCLKspF5wxBY/+gT4KRl7zQnYjj0WdCYv96g6G/iA8nao5/mg3ebN+W4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1600357310910970.0210529865121; Thu, 17 Sep 2020 08:41:50 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2C-0003UI-Aa; Thu, 17 Sep 2020 15:41:20 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2B-0003Ts-GZ for xen-devel@lists.xenproject.org; Thu, 17 Sep 2020 15:41:19 +0000 Received: from mx1a.swcp.com (unknown [216.184.2.64]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 982583e6-9090-45cd-a74f-9fe08c7fd87e; Thu, 17 Sep 2020 15:41:14 +0000 (UTC) Received: from ame7.swcp.com (ame7.swcp.com [216.184.2.70]) by mx1a.swcp.com (8.14.4/8.14.4/Debian-4) with ESMTP id 08HFfDlw024942 for ; Thu, 17 Sep 2020 09:41:13 -0600 Received: from diamond.fritz.box (62-251-112-184.ip.xs4all.nl [62.251.112.184]) by ame7.swcp.com (8.15.2/8.15.2) with ESMTP id 08HFesRM024558 for ; Thu, 17 Sep 2020 09:41:10 -0600 (MDT) (envelope-from hudson@trmm.net) X-Inumbo-ID: 982583e6-9090-45cd-a74f-9fe08c7fd87e Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: neutral (ame7.swcp.com: 62.251.112.184 is neither permitted nor denied by domain of hudson@trmm.net) receiver=ame7.swcp.com; client-ip=62.251.112.184; helo=diamond.fritz.box; envelope-from=hudson@trmm.net; x-software=spfmilter 2.001 http://www.acme.com/software/spfmilter/ with libspf2-1.2.10; X-Authentication-Warning: ame7.swcp.com: Host 62-251-112-184.ip.xs4all.nl [62.251.112.184] claimed to be diamond.fritz.box From: Trammell Hudson To: xen-devel@lists.xenproject.org Subject: [PATCH v5 1/5] efi/boot.c: Make file->ptr const void* Date: Thu, 17 Sep 2020 11:40:44 -0400 Message-Id: <20200917154048.1140580-2-hudson@trmm.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200917154048.1140580-1-hudson@trmm.net> References: <20200917154048.1140580-1-hudson@trmm.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.83 X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.6.2 (ame7.swcp.com [216.184.2.128]); Thu, 17 Sep 2020 09:41:11 -0600 (MDT) X-Virus-Scanned: clamav-milter 0.100.2 at ame7 X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ame7.swcp.com X-Spam-Status: No, hits=0.7 tests=NO_RECEIVED,NO_RELAYS,SPF_NEUTRAL version=3.4.2 X-Spam-Level: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" Other than the config file parser that edits the image inplace, no other users of the file sections requires write access to the data. Signed-off-by: Trammell Hudson Reviewed-by: Jan Beulich --- xen/common/efi/boot.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 0ac80e47bb..157fe0e8c5 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -41,7 +41,7 @@ =20 typedef EFI_STATUS (/* _not_ EFIAPI */ *EFI_SHIM_LOCK_VERIFY) ( - IN VOID *Buffer, + IN const VOID *Buffer, IN UINT32 Size); =20 typedef struct { @@ -104,7 +104,8 @@ struct file { UINTN size; union { EFI_PHYSICAL_ADDRESS addr; - void *ptr; + char *str; + const void *ptr; }; }; =20 @@ -592,7 +593,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle= , CHAR16 *name, efi_arch_handle_module(file, name, options); } =20 - ret =3D FileHandle->Read(FileHandle, &file->size, file->ptr); + ret =3D FileHandle->Read(FileHandle, &file->size, file->str); if ( !EFI_ERROR(ret) && file->size !=3D size ) ret =3D EFI_ABORTED; if ( EFI_ERROR(ret) ) @@ -616,7 +617,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle= , CHAR16 *name, =20 static void __init pre_parse(const struct file *cfg) { - char *ptr =3D cfg->ptr, *end =3D ptr + cfg->size; + char *ptr =3D cfg->str, *end =3D ptr + cfg->size; bool start =3D true, comment =3D false; =20 for ( ; ptr < end; ++ptr ) @@ -645,7 +646,7 @@ static void __init pre_parse(const struct file *cfg) static char *__init get_value(const struct file *cfg, const char *section, const char *item) { - char *ptr =3D cfg->ptr, *end =3D ptr + cfg->size; + char *ptr =3D cfg->str, *end =3D ptr + cfg->size; size_t slen =3D section ? strlen(section) : 0, ilen =3D strlen(item); bool match =3D !slen; =20 --=20 2.25.1 From nobody Fri May 3 22:10:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=trmm.net ARC-Seal: i=1; a=rsa-sha256; t=1600357310; cv=none; d=zohomail.com; s=zohoarc; b=k8pduMNuEINl2NMOZ/N3PYg/Z0QApC0ck656wKMqkkAC12Fgcpft3Uemcik27VkluHjmm/pLgdl6LnR+DwXTY9JRlo6fMG3EDGnWjxe9tbgYVMJihKEq5wjKQ79t8Lbfa+MpzIWkKJBi2OuvI5xCYa8nFZuV+QjdnLRU2qGLCbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600357310; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fuqhvq9DYz+DJ+JlySpwZeaHQNhMvXmL/Y74/85/p/A=; b=Go3uI5yrauQy+2zOqu3NSo8te0GoNOy7y5GxhyAeUCyzjHWTpWeNvvy8xCrTvbJW2ULHMkCdb5zARxywGrxe2iiM1fwY50dXwtu588sZPNPgAqbpcF+rrn1abo71VdMgYfqm8OBpLVI/M+lXC3dEBOQB6GVPYAe+tW7VggyhjDc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1600357310820350.4202406423599; Thu, 17 Sep 2020 08:41:50 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2E-0003UY-Ig; Thu, 17 Sep 2020 15:41:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2C-0003UO-T2 for xen-devel@lists.xenproject.org; Thu, 17 Sep 2020 15:41:20 +0000 Received: from mx1a.swcp.com (unknown [216.184.2.64]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 234a3bb9-a91a-4af2-9c36-024649d30201; Thu, 17 Sep 2020 15:41:18 +0000 (UTC) Received: from ame7.swcp.com (ame7.swcp.com [216.184.2.70]) by mx1a.swcp.com (8.14.4/8.14.4/Debian-4) with ESMTP id 08HFfG42024951 for ; Thu, 17 Sep 2020 09:41:16 -0600 Received: from diamond.fritz.box (62-251-112-184.ip.xs4all.nl [62.251.112.184]) by ame7.swcp.com (8.15.2/8.15.2) with ESMTP id 08HFesRN024558 for ; Thu, 17 Sep 2020 09:41:14 -0600 (MDT) (envelope-from hudson@trmm.net) X-Inumbo-ID: 234a3bb9-a91a-4af2-9c36-024649d30201 Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: neutral (ame7.swcp.com: 62.251.112.184 is neither permitted nor denied by domain of hudson@trmm.net) receiver=ame7.swcp.com; client-ip=62.251.112.184; helo=diamond.fritz.box; envelope-from=hudson@trmm.net; x-software=spfmilter 2.001 http://www.acme.com/software/spfmilter/ with libspf2-1.2.10; X-Authentication-Warning: ame7.swcp.com: Host 62-251-112-184.ip.xs4all.nl [62.251.112.184] claimed to be diamond.fritz.box From: Trammell Hudson To: xen-devel@lists.xenproject.org Subject: [PATCH v5 2/5] efi/boot.c: add file.need_to_free Date: Thu, 17 Sep 2020 11:40:45 -0400 Message-Id: <20200917154048.1140580-3-hudson@trmm.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200917154048.1140580-1-hudson@trmm.net> References: <20200917154048.1140580-1-hudson@trmm.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.83 X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.6.2 (ame7.swcp.com [216.184.2.128]); Thu, 17 Sep 2020 09:41:15 -0600 (MDT) X-Virus-Scanned: clamav-milter 0.100.2 at ame7 X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ame7.swcp.com X-Spam-Status: No, hits=0.7 tests=NO_RECEIVED,NO_RELAYS,SPF_NEUTRAL version=3.4.2 X-Spam-Level: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" The config file, kernel, initrd, etc should only be freed if they are allocated with the UEFI allocator. Signed-off-by: Trammell Hudson --- xen/common/efi/boot.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 157fe0e8c5..77530a0595 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -102,6 +102,7 @@ union string { =20 struct file { UINTN size; + bool need_to_free; union { EFI_PHYSICAL_ADDRESS addr; char *str; @@ -280,13 +281,13 @@ void __init noreturn blexit(const CHAR16 *str) if ( !efi_bs ) efi_arch_halt(); =20 - if ( cfg.addr ) + if ( cfg.addr && cfg.need_to_free ) efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size)); - if ( kernel.addr ) + if ( kernel.addr && kernel.need_to_free ) efi_bs->FreePages(kernel.addr, PFN_UP(kernel.size)); - if ( ramdisk.addr ) + if ( ramdisk.addr && ramdisk.need_to_free ) efi_bs->FreePages(ramdisk.addr, PFN_UP(ramdisk.size)); - if ( xsm.addr ) + if ( xsm.addr && xsm.need_to_free ) efi_bs->FreePages(xsm.addr, PFN_UP(xsm.size)); =20 efi_arch_blexit(); @@ -573,6 +574,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handle= , CHAR16 *name, HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START); ret =3D efi_bs->AllocatePages(AllocateMaxAddress, EfiLoaderData, PFN_UP(size), &file->addr); + file->need_to_free =3D true; } if ( EFI_ERROR(ret) ) { --=20 2.25.1 From nobody Fri May 3 22:10:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=trmm.net ARC-Seal: i=1; a=rsa-sha256; t=1600357311; cv=none; d=zohomail.com; s=zohoarc; b=XnJ2Nf3TqyqKsObuAQy22/kelYeH9o9pofRAP1lcdvo96mbcgLuHDAs8C5CpDsUNAtx4m6gotQSuFUutmFD90gJ0SPJz7tdoMgfVr+hHgWabkWv8WnahUIIV17hxIkuriUtlWsBC+5oBhsmZqsP0boSXYdjgSGlU/WM2env4d9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600357311; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=x66D29HDpeaWzTsWFzouRRTbdIwBmlNjGo6+yAnIT0c=; b=G6izyTU6BncIPwQ0DnqK/d/HrIVPLYKXGYrKKsZnzLW96hDINkJUrd9qs4JAY2kCaZqHkTa8lzMICgSEIUVnyiwEFxTkbmqox35gwzOlGP2Q2kGo5DKFqAg8/8EU7HMF2arh8Aq5CMUZDTwhSYKkBamB71JxaQiD+lE3jGHbgtU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1600357311104320.89985286127353; Thu, 17 Sep 2020 08:41:51 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2H-0003V9-Rc; Thu, 17 Sep 2020 15:41:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2G-0003Ts-Gi for xen-devel@lists.xenproject.org; Thu, 17 Sep 2020 15:41:24 +0000 Received: from mx1a.swcp.com (unknown [216.184.2.64]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id bb120a2d-67c0-4f7e-a9af-0d3f4a3f24d7; Thu, 17 Sep 2020 15:41:20 +0000 (UTC) Received: from ame7.swcp.com (ame7.swcp.com [216.184.2.70]) by mx1a.swcp.com (8.14.4/8.14.4/Debian-4) with ESMTP id 08HFfKHP024954 for ; Thu, 17 Sep 2020 09:41:20 -0600 Received: from diamond.fritz.box (62-251-112-184.ip.xs4all.nl [62.251.112.184]) by ame7.swcp.com (8.15.2/8.15.2) with ESMTP id 08HFesRO024558 for ; Thu, 17 Sep 2020 09:41:17 -0600 (MDT) (envelope-from hudson@trmm.net) X-Inumbo-ID: bb120a2d-67c0-4f7e-a9af-0d3f4a3f24d7 Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: neutral (ame7.swcp.com: 62.251.112.184 is neither permitted nor denied by domain of hudson@trmm.net) receiver=ame7.swcp.com; client-ip=62.251.112.184; helo=diamond.fritz.box; envelope-from=hudson@trmm.net; x-software=spfmilter 2.001 http://www.acme.com/software/spfmilter/ with libspf2-1.2.10; X-Authentication-Warning: ame7.swcp.com: Host 62-251-112-184.ip.xs4all.nl [62.251.112.184] claimed to be diamond.fritz.box From: Trammell Hudson To: xen-devel@lists.xenproject.org Subject: [PATCH v5 3/5] efi/boot.c: add handle_file_info() Date: Thu, 17 Sep 2020 11:40:46 -0400 Message-Id: <20200917154048.1140580-4-hudson@trmm.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200917154048.1140580-1-hudson@trmm.net> References: <20200917154048.1140580-1-hudson@trmm.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.83 X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.6.2 (ame7.swcp.com [216.184.2.128]); Thu, 17 Sep 2020 09:41:18 -0600 (MDT) X-Virus-Scanned: clamav-milter 0.100.2 at ame7 X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ame7.swcp.com X-Spam-Status: No, hits=0.7 tests=NO_RECEIVED,NO_RELAYS,SPF_NEUTRAL version=3.4.2 X-Spam-Level: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" Add a separate function to display the address ranges used by the files and call `efi_arch_handle_module()` on the modules. Signed-off-by: Trammell Hudson --- xen/common/efi/boot.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 77530a0595..e0280f7a21 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -540,6 +540,22 @@ static char * __init split_string(char *s) return NULL; } =20 +static void __init handle_file_info(CHAR16 *name, + const struct file *file, const char *o= ptions) +{ + if ( file =3D=3D &cfg ) + return; + + PrintStr(name); + PrintStr(L": "); + DisplayUint(file->addr, 2 * sizeof(file->addr)); + PrintStr(L"-"); + DisplayUint(file->addr + file->size, 2 * sizeof(file->addr)); + PrintStr(newline); + + efi_arch_handle_module(file, name, options); +} + static bool __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, struct file *file, const char *options) { @@ -584,16 +600,7 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handl= e, CHAR16 *name, else { file->size =3D size; - if ( file !=3D &cfg ) - { - PrintStr(name); - PrintStr(L": "); - DisplayUint(file->addr, 2 * sizeof(file->addr)); - PrintStr(L"-"); - DisplayUint(file->addr + size, 2 * sizeof(file->addr)); - PrintStr(newline); - efi_arch_handle_module(file, name, options); - } + handle_file_info(name, file, options); =20 ret =3D FileHandle->Read(FileHandle, &file->size, file->str); if ( !EFI_ERROR(ret) && file->size !=3D size ) --=20 2.25.1 From nobody Fri May 3 22:10:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=trmm.net ARC-Seal: i=1; a=rsa-sha256; t=1600357316; cv=none; d=zohomail.com; s=zohoarc; b=RbwhkXLbAFnpGNu0RKmot75xr3dg5E+n04jGZ4Uca0A382d954u5uO+z/2tW/umLBj1UhuJwSWJ+bwXGDKAuKaKLWDd0u+/rxr6l26A1B/Ba+PeC+PnsRDpIJ0onPJZhrNJX4+MMuVzHJ18BGPYYL79jUTM3Xm2TFc19vYnNmIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600357316; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B+WZEXLufsvPIVzioc5IV5OOlYsIJRq/BN+JINLq6PM=; b=ZIU11RFF/PVBqg7TXboqArdNJqucNyJ8vDj4qqX23scocwZRd7zqWJ3DstaU1ISpZvccp6SL6BVPpr9kEnKRtvIXhzVwDh29KD95QZPOSpzdfZQNopl3coEYMe1XT/Tg3ebCBYwMZpcxOQTVghUgVmrDdeIgzwPPjHq4wa+Di5U= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1600357316685653.2194830493247; Thu, 17 Sep 2020 08:41:56 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2N-0003WX-3S; Thu, 17 Sep 2020 15:41:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2M-0003Vz-O6 for xen-devel@lists.xenproject.org; Thu, 17 Sep 2020 15:41:30 +0000 Received: from mx1a.swcp.com (unknown [216.184.2.64]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e9544947-6f11-4f06-be2a-7ae08ead4771; Thu, 17 Sep 2020 15:41:28 +0000 (UTC) Received: from ame7.swcp.com (ame7.swcp.com [216.184.2.70]) by mx1a.swcp.com (8.14.4/8.14.4/Debian-4) with ESMTP id 08HFfRnI024973; Thu, 17 Sep 2020 09:41:27 -0600 Received: from diamond.fritz.box (62-251-112-184.ip.xs4all.nl [62.251.112.184]) by ame7.swcp.com (8.15.2/8.15.2) with ESMTP id 08HFesRP024558; Thu, 17 Sep 2020 09:41:21 -0600 (MDT) (envelope-from hudson@trmm.net) X-Inumbo-ID: e9544947-6f11-4f06-be2a-7ae08ead4771 Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: neutral (ame7.swcp.com: 62.251.112.184 is neither permitted nor denied by domain of hudson@trmm.net) receiver=ame7.swcp.com; client-ip=62.251.112.184; helo=diamond.fritz.box; envelope-from=hudson@trmm.net; x-software=spfmilter 2.001 http://www.acme.com/software/spfmilter/ with libspf2-1.2.10; X-Authentication-Warning: ame7.swcp.com: Host 62-251-112-184.ip.xs4all.nl [62.251.112.184] claimed to be diamond.fritz.box From: Trammell Hudson To: xen-devel@lists.xenproject.org Cc: Trammell hudson Subject: [PATCH v5 4/5] efi: Enable booting unified hypervisor/kernel/initrd images Date: Thu, 17 Sep 2020 11:40:47 -0400 Message-Id: <20200917154048.1140580-5-hudson@trmm.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200917154048.1140580-1-hudson@trmm.net> References: <20200917154048.1140580-1-hudson@trmm.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.83 X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.6.2 (ame7.swcp.com [216.184.2.128]); Thu, 17 Sep 2020 09:41:22 -0600 (MDT) X-Virus-Scanned: clamav-milter 0.100.2 at ame7 X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ame7.swcp.com X-Spam-Status: No, hits=0.7 tests=NO_RECEIVED,NO_RELAYS,SPF_NEUTRAL version=3.4.2 X-Spam-Level: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" This patch adds support for bundling the xen.efi hypervisor, the xen.cfg configuration file, the Linux kernel and initrd, as well as the XSM, and architectural specific files into a single "unified" EFI executable. This allows an administrator to update the components independently without requiring rebuilding xen, as well as to replace the components in an existing image. The resulting EFI executable can be invoked directly from the UEFI Boot Manager, removing the need to use a separate loader like grub as well as removing dependencies on local filesystem access. And since it is a single file, it can be signed and validated by UEFI Secure Boot without requring the shim protocol. It is inspired by systemd-boot's unified kernel technique and borrows the function to locate PE sections from systemd's LGPL'ed code. During EFI boot, Xen looks at its own loaded image to locate the PE sections for the Xen configuration (`.config`), dom0 kernel (`.kernel`), dom0 initrd (`.ramdisk`), and XSM config (`.xsm`), which are included after building xen.efi using objcopy to add named sections for each input file. For x86, the CPU ucode can be included in a section named `.ucode`, which is loaded in the efi_arch_cfg_file_late() stage of the boot process. On ARM systems the Device Tree can be included in a section named `.dtb`, which is loaded during the efi_arch_cfg_file_early() stage of the boot process. Note that the system will fall back to loading files from disk if the named sections do not exist. This allows distributions to continue with the status quo if they want a signed kernel + config, while still allowing a user provided initrd (which is how the shim protocol currently works as well). Signed-off-by: Trammell hudson --- .gitignore | 1 + docs/misc/efi.pandoc | 49 +++++++++++++ xen/arch/arm/efi/efi-boot.h | 25 ++++--- xen/arch/x86/efi/Makefile | 2 +- xen/arch/x86/efi/efi-boot.h | 11 ++- xen/common/efi/boot.c | 73 +++++++++++++++----- xen/common/efi/efi.h | 3 + xen/common/efi/pe.c | 134 ++++++++++++++++++++++++++++++++++++ 8 files changed, 269 insertions(+), 29 deletions(-) create mode 100644 xen/common/efi/pe.c diff --git a/.gitignore b/.gitignore index 823f4743dc..d568017804 100644 --- a/.gitignore +++ b/.gitignore @@ -299,6 +299,7 @@ xen/arch/*/efi/boot.c xen/arch/*/efi/compat.c xen/arch/*/efi/ebmalloc.c xen/arch/*/efi/efi.h +xen/arch/*/efi/pe.c xen/arch/*/efi/runtime.c xen/common/config_data.S xen/common/config.gz diff --git a/docs/misc/efi.pandoc b/docs/misc/efi.pandoc index 23c1a2732d..ac3cd58cae 100644 --- a/docs/misc/efi.pandoc +++ b/docs/misc/efi.pandoc @@ -116,3 +116,52 @@ Filenames must be specified relative to the location o= f the EFI binary. =20 Extra options to be passed to Xen can also be specified on the command lin= e, following a `--` separator option. + +## Unified Xen kernel image + +The "Unified" kernel image can be generated by adding additional +sections to the Xen EFI executable with objcopy, similar to how +[systemd-boot uses the stub to add them to the Linux kernel](https://wiki.= archlinux.org/index.php/systemd-boot#Preparing_a_unified_kernel_image) + +The sections for the xen configuration file, the dom0 kernel, dom0 initrd, +XSM and CPU microcode should be added after the Xen `.pad` section, the +ending address of which can be located with: + +``` +objdump -h xen.efi \ + | perl -ane '/\.pad/ && printf "0x%016x\n", hex($F[2]) + hex($F[3])' +``` + +For all the examples the `.pad` section ended at 0xffff82d041000000. +All the sections are optional (`.config`, `.kernel`, `.ramdisk`, `.xsm`, +`.ucode` (x86) and `.dtb` (ARM)) and the order does not matter. +The virtual addresses do not need to be contiguous, although they should n= ot +be overlapping and should all be greater than the last virtual address of = the +hypervisor components. + +``` +objcopy \ + --add-section .config=3Dxen.cfg \ + --change-section-vma .config=3D0xffff82d041000000 + --add-section .ucode=3Ducode.bin \ + --change-section-vma .ucode=3D0xffff82d041010000 \ + --add-section .xsm=3Dxsm.cfg \ + --change-section-vma .xsm=3D0xffff82d041080000 \ + --add-section .kernel=3Dvmlinux \ + --change-section-vma .kernel=3D0xffff82d041100000 \ + --add-section .ramdisk=3Dinitrd.img \ + --change-section-vma .ramdisk=3D0xffff82d042000000 \ + xen.efi \ + xen.unified.efi +``` + +The unified executable can be signed with sbsigntool to make +it usable with UEFI secure boot: + +``` +sbsign \ + --key signing.key \ + --cert cert.pem \ + --output xen.signed.efi \ + xen.unified.efi +``` diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index 27dd0b1a94..47ced1db8d 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -375,27 +375,36 @@ static void __init noreturn efi_arch_post_exit_boot(v= oid) efi_xen_start(fdt, fdt_totalsize(fdt)); } =20 -static void __init efi_arch_cfg_file_early(EFI_FILE_HANDLE dir_handle, cha= r *section) +static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image, + EFI_FILE_HANDLE dir_handle, + const char *section) { union string name; =20 /* * The DTB must be processed before any other entries in the configura= tion - * file, as the DTB is updated as modules are loaded. + * file, as the DTB is updated as modules are loaded. Prefer the one + * stored as a PE section in a unified image, and fall back to a file + * on disk if the section is not present. */ - name.s =3D get_value(&cfg, section, "dtb"); - if ( name.s ) + if ( !read_section(image, ".dtb", &dtbfile, NULL) ) { - split_string(name.s); - read_file(dir_handle, s2w(&name), &dtbfile, NULL); - efi_bs->FreePool(name.w); + name.s =3D get_value(&cfg, section, "dtb"); + if ( name.s ) + { + split_string(name.s); + read_file(dir_handle, s2w(&name), &dtbfile, NULL); + efi_bs->FreePool(name.w); + } } fdt =3D fdt_increase_size(&dtbfile, cfg.size + EFI_PAGE_SIZE); if ( !fdt ) blexit(L"Unable to create new FDT"); } =20 -static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char= *section) +static void __init efi_arch_cfg_file_late(const EFI_LOADED_IMAGE *image, + EFI_FILE_HANDLE dir_handle, + const char *section) { } =20 diff --git a/xen/arch/x86/efi/Makefile b/xen/arch/x86/efi/Makefile index 770438a029..e857c0f2cc 100644 --- a/xen/arch/x86/efi/Makefile +++ b/xen/arch/x86/efi/Makefile @@ -8,7 +8,7 @@ cmd_objcopy_o_ihex =3D $(OBJCOPY) -I ihex -O binary $< $@ =20 boot.init.o: buildid.o =20 -EFIOBJ :=3D boot.init.o ebmalloc.o compat.o runtime.o +EFIOBJ :=3D boot.init.o pe.init.o ebmalloc.o compat.o runtime.o =20 $(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary= =3D4) $(EFIOBJ): CFLAGS-stack-boundary :=3D $(cflags-stack-boundary) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index eef3f52789..db3e29f573 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -272,14 +272,21 @@ static void __init noreturn efi_arch_post_exit_boot(v= oid) unreachable(); } =20 -static void __init efi_arch_cfg_file_early(EFI_FILE_HANDLE dir_handle, cha= r *section) +static void __init efi_arch_cfg_file_early(const EFI_LOADED_IMAGE *image, + EFI_FILE_HANDLE dir_handle, + const char *section) { } =20 -static void __init efi_arch_cfg_file_late(EFI_FILE_HANDLE dir_handle, char= *section) +static void __init efi_arch_cfg_file_late(const EFI_LOADED_IMAGE *image, + EFI_FILE_HANDLE dir_handle, + const char *section) { union string name; =20 + if ( read_section(image, ".ucode", &ucode, NULL) ) + return; + name.s =3D get_value(&cfg, section, "ucode"); if ( !name.s ) name.s =3D get_value(&cfg, "global", "ucode"); diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index e0280f7a21..c14e836640 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -122,6 +122,8 @@ static CHAR16 *s2w(union string *str); static char *w2s(const union string *str); static bool read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name, struct file *file, const char *options); +static bool read_section(const EFI_LOADED_IMAGE *image, + char *name, struct file *file, const char *option= s); static size_t wstrlen(const CHAR16 * s); static int set_color(u32 mask, int bpp, u8 *pos, u8 *sz); static bool match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2); @@ -624,6 +626,29 @@ static bool __init read_file(EFI_FILE_HANDLE dir_handl= e, CHAR16 *name, return true; } =20 +static bool __init read_section(const EFI_LOADED_IMAGE *image, + char *const name, struct file *file, + const char *options) +{ + /* skip the leading "." in the section name */ + union string name_string =3D { .s =3D name + 1 }; + + file->ptr =3D pe_find_section(image->ImageBase, image->ImageSize, + name, &file->size); + if ( !file->ptr ) + return false; + + file->need_to_free =3D false; + + if ( !s2w(&name_string) ) + return false; + + handle_file_info(name_string.w, file, options); + efi_bs->FreePool(name_string.w); + + return true; +} + static void __init pre_parse(const struct file *cfg) { char *ptr =3D cfg->str, *end =3D ptr + cfg->size; @@ -1208,9 +1233,11 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *= SystemTable) /* Get the file system interface. */ dir_handle =3D get_parent_handle(loaded_image, &file_name); =20 - /* Read and parse the config file. */ - if ( !cfg_file_name ) + if ( read_section(loaded_image, ".config", &cfg, NULL) ) + PrintStr(L"Using unified config file\r\n"); + else if ( !cfg_file_name ) { + /* Read and parse the config file. */ CHAR16 *tail; =20 while ( (tail =3D point_tail(file_name)) !=3D NULL ) @@ -1259,29 +1286,39 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE = *SystemTable) if ( !name.s ) blexit(L"No Dom0 kernel image specified."); =20 - efi_arch_cfg_file_early(dir_handle, section.s); + efi_arch_cfg_file_early(loaded_image, dir_handle, section.s); =20 option_str =3D split_string(name.s); - read_file(dir_handle, s2w(&name), &kernel, option_str); - efi_bs->FreePool(name.w); - - if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL, - (void **)&shim_lock)) && - (status =3D shim_lock->Verify(kernel.ptr, kernel.size)) !=3D = EFI_SUCCESS ) - PrintErrMesg(L"Dom0 kernel image could not be verified", statu= s); =20 - name.s =3D get_value(&cfg, section.s, "ramdisk"); - if ( name.s ) + if ( !read_section(loaded_image, ".kernel", &kernel, option_str) ) { - read_file(dir_handle, s2w(&name), &ramdisk, NULL); + read_file(dir_handle, s2w(&name), &kernel, option_str); efi_bs->FreePool(name.w); + + if ( !EFI_ERROR(efi_bs->LocateProtocol(&shim_lock_guid, NULL, + (void **)&shim_lock)) && + (status =3D shim_lock->Verify(kernel.ptr, kernel.size)) != =3D EFI_SUCCESS ) + PrintErrMesg(L"Dom0 kernel image could not be verified", s= tatus); } =20 - name.s =3D get_value(&cfg, section.s, "xsm"); - if ( name.s ) + if ( !read_section(loaded_image, ".ramdisk", &ramdisk, NULL) ) { - read_file(dir_handle, s2w(&name), &xsm, NULL); - efi_bs->FreePool(name.w); + name.s =3D get_value(&cfg, section.s, "ramdisk"); + if ( name.s ) + { + read_file(dir_handle, s2w(&name), &ramdisk, NULL); + efi_bs->FreePool(name.w); + } + } + + if ( !read_section(loaded_image, ".xsm", &xsm, NULL) ) + { + name.s =3D get_value(&cfg, section.s, "xsm"); + if ( name.s ) + { + read_file(dir_handle, s2w(&name), &xsm, NULL); + efi_bs->FreePool(name.w); + } } =20 /* @@ -1317,7 +1354,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *S= ystemTable) } } =20 - efi_arch_cfg_file_late(dir_handle, section.s); + efi_arch_cfg_file_late(loaded_image, dir_handle, section.s); =20 efi_bs->FreePages(cfg.addr, PFN_UP(cfg.size)); cfg.addr =3D 0; diff --git a/xen/common/efi/efi.h b/xen/common/efi/efi.h index 4845d84913..c9d3752121 100644 --- a/xen/common/efi/efi.h +++ b/xen/common/efi/efi.h @@ -47,3 +47,6 @@ const CHAR16 *wmemchr(const CHAR16 *s, CHAR16 c, UINTN n); /* EFI boot allocator. */ void *ebmalloc(size_t size); void free_ebmalloc_unused_mem(void); + +const void *pe_find_section(const void *image_base, const size_t image_siz= e, + const char *section_name, UINTN *size_out); diff --git a/xen/common/efi/pe.c b/xen/common/efi/pe.c new file mode 100644 index 0000000000..568f0823bb --- /dev/null +++ b/xen/common/efi/pe.c @@ -0,0 +1,134 @@ +/* + * xen/common/efi/pe.c + * + * PE executable header parser. + * + * Derived from https://github.com/systemd/systemd/blob/master/src/boot/ef= i/pe.c + * commit 07d5ed536ec0a76b08229c7a80b910cb9acaf6b1 + * + * Copyright (C) 2015 Kay Sievers + * Copyright (C) 2020 Trammell Hudson + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ + + +#include "efi.h" + +struct DosFileHeader { + UINT8 Magic[2]; + UINT16 LastSize; + UINT16 nBlocks; + UINT16 nReloc; + UINT16 HdrSize; + UINT16 MinAlloc; + UINT16 MaxAlloc; + UINT16 ss; + UINT16 sp; + UINT16 Checksum; + UINT16 ip; + UINT16 cs; + UINT16 RelocPos; + UINT16 nOverlay; + UINT16 reserved[4]; + UINT16 OEMId; + UINT16 OEMInfo; + UINT16 reserved2[10]; + UINT32 ExeHeader; +}; + +#if defined(__arm__) || defined (__aarch64__) +#define PE_HEADER_MACHINE 0xaa64 +#elif defined(__x86_64__) +#define PE_HEADER_MACHINE 0x8664 +#else +#error "Unknown architecture" +#endif + +struct PeFileHeader { + UINT16 Machine; + UINT16 NumberOfSections; + UINT32 TimeDateStamp; + UINT32 PointerToSymbolTable; + UINT32 NumberOfSymbols; + UINT16 SizeOfOptionalHeader; + UINT16 Characteristics; +}; + +struct PeHeader { + UINT8 Magic[4]; + struct PeFileHeader FileHeader; +}; + +struct PeSectionHeader { + CHAR8 Name[8]; + UINT32 VirtualSize; + UINT32 VirtualAddress; + UINT32 SizeOfRawData; + UINT32 PointerToRawData; + UINT32 PointerToRelocations; + UINT32 PointerToLinenumbers; + UINT16 NumberOfRelocations; + UINT16 NumberOfLinenumbers; + UINT32 Characteristics; +}; + +const void *__init pe_find_section(const void *image, const UINTN image_si= ze, + const char *section_name, UINTN *size_o= ut) +{ + const struct DosFileHeader *dos =3D image; + const struct PeHeader *pe; + const struct PeSectionHeader *sect; + const UINTN name_len =3D strlen(section_name); + UINTN offset, i; + + if ( name_len > sizeof(sect->Name) || + image_size < sizeof(*dos) || + memcmp(dos->Magic, "MZ", 2) !=3D 0 ) + return NULL; + + offset =3D dos->ExeHeader; + pe =3D image + offset; + + offset +=3D sizeof(*pe); + if ( image_size < offset || + memcmp(pe->Magic, "PE\0\0", 4) !=3D 0 ) + return NULL; + + /* PE32+ Subsystem type */ + if ( pe->FileHeader.Machine !=3D PE_HEADER_MACHINE ) + return NULL; + + offset +=3D pe->FileHeader.SizeOfOptionalHeader; + + for ( i =3D 0; i < pe->FileHeader.NumberOfSections; i++ ) + { + sect =3D image + offset; + if ( image_size < offset + sizeof(*sect) ) + return NULL; + + if ( memcmp(sect->Name, section_name, name_len) !=3D 0 ) + { + offset +=3D sizeof(*sect); + continue; + } + + if ( image_size < sect->VirtualSize + sect->VirtualAddress ) + blexit(L"PE invalid section size + address"); + + if ( size_out ) + *size_out =3D sect->VirtualSize; + + return image + sect->VirtualAddress; + } + + return NULL; +} --=20 2.25.1 From nobody Fri May 3 22:10:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=trmm.net ARC-Seal: i=1; a=rsa-sha256; t=1600357313; cv=none; d=zohomail.com; s=zohoarc; b=cdec93EEo+TsnJDCWuENwI829Cxw7YNJnKYwYzzmc/w4J8OESpOIoYVc5jHt2Vsx0hmf7W0kPvJIOa7m5/GGtA3LHmwCVkt2ILtzNnIlNZks0lUjC6KfN/uHid7WH3mPRnOPAhSiFeioLkNcUoUNyfx3YKDKGIj4GSqYuGU2/Cs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600357313; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IdcZXqlHs5+EZNM22o6e1rKnN9WlSfpq/mEMv5WGsAU=; b=Og5JQMHqGiq915rUFuw6JB3QYAyhXSjJbqZbRIHKgxlpbbI8FfcFy2EyuFLUi4xdPiHeY6yLKLBSeI2Y61UuPdS1ZO14FiT5ytDp7tKrS0ESPIGA2BU6Lt1E7o1nS5mKfgSvJFplkX4S9iwUlQcVl43Ru3Dl0pqFgDj+dH5YACo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1600357313152443.932205641009; Thu, 17 Sep 2020 08:41:53 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2T-0003ZK-GC; Thu, 17 Sep 2020 15:41:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kIw2S-0003Z7-Jm for xen-devel@lists.xenproject.org; Thu, 17 Sep 2020 15:41:36 +0000 Received: from mx1a.swcp.com (unknown [216.184.2.64]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cbbd5b5b-d89d-431b-9d2b-edb4508d8af6; Thu, 17 Sep 2020 15:41:35 +0000 (UTC) Received: from ame7.swcp.com (ame7.swcp.com [216.184.2.70]) by mx1a.swcp.com (8.14.4/8.14.4/Debian-4) with ESMTP id 08HFfYjE024992 for ; Thu, 17 Sep 2020 09:41:34 -0600 Received: from diamond.fritz.box (62-251-112-184.ip.xs4all.nl [62.251.112.184]) by ame7.swcp.com (8.15.2/8.15.2) with ESMTP id 08HFesRQ024558 for ; Thu, 17 Sep 2020 09:41:28 -0600 (MDT) (envelope-from hudson@trmm.net) X-Inumbo-ID: cbbd5b5b-d89d-431b-9d2b-edb4508d8af6 Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: neutral (ame7.swcp.com: 62.251.112.184 is neither permitted nor denied by domain of hudson@trmm.net) receiver=ame7.swcp.com; client-ip=62.251.112.184; helo=diamond.fritz.box; envelope-from=hudson@trmm.net; x-software=spfmilter 2.001 http://www.acme.com/software/spfmilter/ with libspf2-1.2.10; X-Authentication-Warning: ame7.swcp.com: Host 62-251-112-184.ip.xs4all.nl [62.251.112.184] claimed to be diamond.fritz.box From: Trammell Hudson To: xen-devel@lists.xenproject.org Subject: [PATCH v5 5/5] efi: Do not use command line if unified config is included Date: Thu, 17 Sep 2020 11:40:48 -0400 Message-Id: <20200917154048.1140580-6-hudson@trmm.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200917154048.1140580-1-hudson@trmm.net> References: <20200917154048.1140580-1-hudson@trmm.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.83 X-Greylist: Message whitelisted by DRAC access database, not delayed by milter-greylist-4.6.2 (ame7.swcp.com [216.184.2.128]); Thu, 17 Sep 2020 09:41:29 -0600 (MDT) X-Virus-Scanned: clamav-milter 0.100.2 at ame7 X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ame7.swcp.com X-Spam-Status: No, hits=0.7 tests=NO_RECEIVED,NO_RELAYS,SPF_NEUTRAL version=3.4.2 X-Spam-Level: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Type: text/plain; charset="utf-8" If a unified Xen image is used, then the bundled configuration, Xen command line, dom0 kernel, and ramdisk are prefered over any files listed in the config file or provided on the command line. Unlike the shim based verification, the PE signature on a unified image covers all of the Xen+config+kernel+initrd modules linked into the unified image. This also ensures that, on properly configured UEFI Secure B= oot platforms, the entire runtime will be measured into the TPM for unsealing secrets or remote attestation. Signed-off-by: Trammell Hudson --- xen/common/efi/boot.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index c14e836640..6dc3f5ac94 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -952,6 +952,35 @@ static void __init setup_efi_pci(void) efi_bs->FreePool(handles); } =20 +/* + * Logic should remain sync'ed with linux/arch/x86/xen/efi.c + * Secure Boot is enabled iff 'SecureBoot' is set and the system is + * not in Setup Mode. + */ +static bool __init efi_secure_boot(void) +{ + static __initdata EFI_GUID global_guid =3D EFI_GLOBAL_VARIABLE; + uint8_t secboot, setupmode; + UINTN secboot_size =3D sizeof(secboot); + UINTN setupmode_size =3D sizeof(setupmode); + EFI_STATUS rc; + + rc =3D efi_rs->GetVariable(L"SecureBoot", &global_guid, + NULL, &secboot_size, &secboot); + if ( rc !=3D EFI_SUCCESS ) + return false; + + rc =3D efi_rs->GetVariable(L"SetupMode", &global_guid, + NULL, &setupmode_size, &setupmode); + if ( rc !=3D EFI_SUCCESS ) + return false; + + if ( secboot > 1 || setupmode > 1 ) + blexit(L"Invalid SecureBoot/SetupMode variables"); + + return secboot =3D=3D 1 && setupmode =3D=3D 0; +} + static void __init efi_variables(void) { EFI_STATUS status; @@ -1128,15 +1157,15 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE = *SystemTable) static EFI_GUID __initdata shim_lock_guid =3D SHIM_LOCK_PROTOCOL_GUID; EFI_LOADED_IMAGE *loaded_image; EFI_STATUS status; - unsigned int i, argc; - CHAR16 **argv, *file_name, *cfg_file_name =3D NULL, *options =3D NULL; + unsigned int i, argc =3D 0; + CHAR16 **argv =3D NULL, *file_name, *cfg_file_name =3D NULL, *options = =3D NULL; UINTN gop_mode =3D ~0; EFI_SHIM_LOCK_PROTOCOL *shim_lock; EFI_GRAPHICS_OUTPUT_PROTOCOL *gop =3D NULL; union string section =3D { NULL }, name; bool base_video =3D false; const char *option_str; - bool use_cfg_file; + bool use_cfg_file, secure; =20 __set_bit(EFI_BOOT, &efi_flags); __set_bit(EFI_LOADER, &efi_flags); @@ -1155,8 +1184,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *= SystemTable) PrintErrMesg(L"No Loaded Image Protocol", status); =20 efi_arch_load_addr_check(loaded_image); + secure =3D efi_secure_boot(); =20 - if ( use_cfg_file ) + if ( use_cfg_file && + !read_section(loaded_image, ".config", &cfg, NULL)) { UINTN offset =3D 0; =20 @@ -1214,6 +1245,8 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *S= ystemTable) =20 PrintStr(L"Xen " __stringify(XEN_VERSION) "." __stringify(XEN_SUBVERSI= ON) XEN_EXTRAVERSION " (c/s " XEN_CHANGESET ") EFI loader\r\n"); + if ( secure ) + PrintStr(L"UEFI Secure Boot enabled\r\n"); =20 efi_arch_relocate_image(0); =20 @@ -1233,7 +1266,7 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *S= ystemTable) /* Get the file system interface. */ dir_handle =3D get_parent_handle(loaded_image, &file_name); =20 - if ( read_section(loaded_image, ".config", &cfg, NULL) ) + if ( cfg.ptr ) PrintStr(L"Using unified config file\r\n"); else if ( !cfg_file_name ) { --=20 2.25.1