From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::242; helo=mail-wm0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A08C22112B1C4 for ; Wed, 12 Sep 2018 06:22:46 -0700 (PDT) Received: by mail-wm0-x242.google.com with SMTP id t25-v6so2387473wmi.3 for ; Wed, 12 Sep 2018 06:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S3nLKLfL07G6P4WtOTyogrPlvnV+9rWMIzQYOQ2BRu4=; b=JxYuvLcuQymVAv9A0xhgbyf/C75AD5XAczzjMvD/fFVA2ZWOjGx0TLRa+FmEMcUFsA DSIMzTshd84AC26Tf70mFZSrG+XIQyvO3NtO3yaPI0CsYXDNBBrKNZWjbZis6c7BSaT5 FTpnTfN6vSFnZbpaXyn+8MOvdPYwVcurvXH9c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S3nLKLfL07G6P4WtOTyogrPlvnV+9rWMIzQYOQ2BRu4=; b=Xvprt5xudknmaF4e6/2UaLUs1l2KItuuk+VvUpsMv7PZI41WViwxijny1l4Bc7lWyE Z+HqXjI9UO5l1zCFMTFOZYCIK/Gfpx+ElgVuBiYWOg3ji91jZf/p2l1pkt8StxpotGbp 7IAg7HRvFBv0IW0ajra18RqEVNnVcDbt3DMYCREfgR50EMe3E+jod6Wlrz7hoAOTx/8f 7XLDC6UhnKp0EnSMJcQLPUVn+xBX65TzIZZ4JocEZhKROFm0hEs9I3wViHlvlw5OhYwW Hkd66scZQ4CQLeERSZzLBMwoa1b+Rk/T5guVdprrtBWHZwSpbznLRQo1RMN9KlEoNh83 tT/Q== X-Gm-Message-State: APzg51BNWZLCJtElw6LUETNSwczyDurSb5gnRuU66BQfw9EeX/nWCk+/ X+0N6Pfk71DfGNbOYR31juLJr5WQYWZTtg== X-Google-Smtp-Source: ANB0VdbITG2/rNLrAojdCV1R5/Ybs8OSAhLVmSY+kmKDduj3tKHKMC+RgaEtugbNuZfRhvuMZcVFKQ== X-Received: by 2002:a1c:148f:: with SMTP id 137-v6mr1589695wmu.61.1536758564972; Wed, 12 Sep 2018 06:22:44 -0700 (PDT) Received: from mba13.kuq.prv ([2001:a62:605:90f4:1f3:d690:1764:36ca]) by smtp.gmail.com with ESMTPSA id e133-v6sm1985129wma.33.2018.09.12.06.22.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 06:22:44 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: agraf@suse.de, Ard Biesheuvel , Zimmer Vincent , Brian Richardson , Michael D Kinney , Andrew Fish , Laszlo Ersek , Leif Lindholm , Star Zeng , Eric Dong , Ruiyu Ni Date: Wed, 12 Sep 2018 15:21:51 +0200 Message-Id: <20180912132151.4258-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180912132151.4258-1-ard.biesheuvel@linaro.org> References: <20180912132151.4258-1-ard.biesheuvel@linaro.org> Subject: [PATCH 4/4] MdeModulePkg/UefiBootManagerLib: allow foreign Driver#### images X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Sep 2018 13:22:47 -0000 Allow PE/COFF images that must execute under emulation for Driver#### options, by relaxing the machine type check to include support for machine types that is provided by the emulator. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c | 26 +++++++++++++++++++- MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h | 1 + MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c index 7bf96646c690..67e3dfd7e9e1 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c @@ -1185,6 +1185,29 @@ EfiBootManagerFreeLoadOptions ( return EFI_SUCCESS; } +STATIC +BOOLEAN +BmIsImageTypeSupported ( + IN UINT16 MachineType, + IN UINT16 SubSystem + ) +{ + EFI_STATUS Status; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emu; + + if (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (MachineType)) { + return TRUE; + } + + Status = gBS->LocateProtocol (&gEdkiiPeCoffImageEmulatorProtocolGuid, + NULL, (VOID **)&Emu); + if (EFI_ERROR (Status)) { + return FALSE; + } + + return Emu->IsImageSupported (Emu, MachineType, SubSystem); +} + /** Return whether the PE header of the load option is valid or not. @@ -1235,7 +1258,8 @@ BmIsLoadOptionPeHeaderValid ( OptionalHeader = (EFI_IMAGE_OPTIONAL_HEADER32 *) &PeHeader->Pe32.OptionalHeader; if ((OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC || OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) && - EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeHeader->Pe32.FileHeader.Machine) + BmIsImageTypeSupported (PeHeader->Pe32.FileHeader.Machine, + OptionalHeader->Subsystem) ) { // // Check the Subsystem: diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h index 978fbff966f6..5f64ef304b87 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h +++ b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h @@ -47,6 +47,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include diff --git a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf index 72c5ca1cd59e..09e2134acf8e 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf +++ b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf @@ -104,6 +104,7 @@ gEfiDevicePathProtocolGuid ## SOMETIMES_CONSUMES gEfiBootLogoProtocolGuid ## SOMETIMES_CONSUMES gEfiSimpleTextInputExProtocolGuid ## SOMETIMES_CONSUMES + gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES -- 2.17.1