From patchwork Sat Sep 15 13:28:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 146772 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1805103ljw; Sat, 15 Sep 2018 06:29:18 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYKB1usOJkkNCiWJ/e4+GO1XKvNHHqRKL6mxs9C8PipzJr9ic/D/AYoTOf97a9/9WtHghPY X-Received: by 2002:a63:e255:: with SMTP id y21-v6mr16189412pgj.160.1537018158004; Sat, 15 Sep 2018 06:29:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537018157; cv=none; d=google.com; s=arc-20160816; b=VAYlJViKkaRve/qYWVrkASehlDkVQK410Wr+v8IadtBzTSAvP2xxa52ZvX0Uv7ynsp fA496bNAzZ3oYGs0KaCBk1/k+4s1rppM8c8ns1aHCheiLxb6+m4CREl3fO2/wirt5HsV 7P/XlH4myGLvK5YpDE7VjyemsE61jf3SGgRjc3oqce/qdSZOVAvtl2LGdyite0dN6uAs Ra57sQfyk3+JAOYjC9bIgCZ5BgQQV+a6HYPcMn3TycapIwp6D7m09p+iOgIvFyyfFSw9 5J/5GjBE4IB87vCrGOSwjxNqLTaEqan8vY/DGufEG7ICvLOj8QmdKwtU0ebU+aHnPfPF tzXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=6HiaoUWDN3L3Nwj4HMMV5okD33MR/jo5sB0f3crbIPg=; b=BmeNDFR9VOBwTDNFcSLPYDoYukq8K0ODUu4bXCA75q5gySbq7m1bNHXHjQoP0M30cA L7qW/Am8KIhVeyGD8MP3R8++BQJ+w/yKAIpXZlHTVdNPuiCGpZ04PtsZ/iS802Az1VeI H9+xADY+979oBcagV1Mascq7Gxzp/z7V8mq06h1e9cRXL+APYuhEEMrxWVQrm/f3oDUU jfZoM584FKAKKPTfvRgvhXOwgyaHKJAPcv9jkuHnjNk4Hgqiv2OrNV8Sua82pQNWe07D jJr+QbLjT6NMuNOwLgJssVpUFpOv/K88+VlJp7SSD5DKTDqsOPnf7R05bAS+6G2vHImx 7uBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jNCYC63r; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id 1-v6si9594020plv.28.2018.09.15.06.29.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jNCYC63r; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8C5C6211350F4; Sat, 15 Sep 2018 06:29:14 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::544; helo=mail-ed1-x544.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) (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 9F3C02194D387 for ; Sat, 15 Sep 2018 06:29:12 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id k14-v6so9472956edr.13 for ; Sat, 15 Sep 2018 06:29:12 -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=mfP/CMMmtQmCdyuMC7VkUiLdmXv4uBEe+9Q0sLkcMfU=; b=jNCYC63reuWidpLbeZAvxYAkHP4PMK9q4Mn2w73KhA6+Nx45fhDuLRvPEjRixgBXrP QSeD9tMCQoEXaemXbdEjnt5xbAZLpv8QC/5HUw4ENamLp1mfrIaBMZGFxbcEnBmW8LZS UIorcaV6zFt4T91j5V698bYpwCDNaawEBFG+Q= 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=mfP/CMMmtQmCdyuMC7VkUiLdmXv4uBEe+9Q0sLkcMfU=; b=plYQkguJdmVve41lGcaSfkAG4Qxe23jsz2y0PTxgQ5euWFeXlBuNDcPY4r7Xq7g0Sj w6KwqDbx/9a1nHLP6zQIARX9h8P6sefaZIIxJOqxLU6Q2u//0XkB84iQRCZA1Li2/da1 IGnrgGNoN69TMr23+BtpyvAqlMn3AfbiFr7FJRGRdujENInhhNwlwM0j47UxLU23Dc0d wK3hTvO/iIqDA7LOvnrbbgJSdw0zhUpT0gRk8Y8+Hj5NFm64jLvJfn59KVAj7mdJAge6 PCAXhwPynz3+gMJVRC8X4UOFqaT0jWvg5eATr6xj8jTSUWITRuuifXpPwtB/marzQ/T9 5uFg== X-Gm-Message-State: APzg51Ava9tItPkXqpZkZ7U+EBzEetlyH06wE3N7gnaM9o0OFDkg9MbI VILASQCwinCeyRSo96hJInte2rAl0eR/iA== X-Received: by 2002:aa7:ca51:: with SMTP id j17-v6mr29759103edt.45.1537018150930; Sat, 15 Sep 2018 06:29:10 -0700 (PDT) Received: from mba13.kuq.prv ([194.138.39.100]) by smtp.gmail.com with ESMTPSA id j23-v6sm4449262edh.29.2018.09.15.06.29.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Sep 2018 06:29:10 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Sat, 15 Sep 2018 15:28:56 +0200 Message-Id: <20180915132859.25727-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180915132859.25727-1-ard.biesheuvel@linaro.org> References: <20180915132859.25727-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 4/7] 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: , Cc: Ruiyu Ni , Vincent Zimmer , Eric Dong , Andrew Fish , Jaben Carsey , Brian Richardson , Liming Gao , Michael D Kinney , Star Zeng MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 | 51 +++++++++++++++++++- MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h | 1 + MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c index 7bf96646c690..9bd8bbcf0bf1 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c @@ -1185,6 +1185,54 @@ EfiBootManagerFreeLoadOptions ( return EFI_SUCCESS; } +STATIC +BOOLEAN +BmIsImageTypeSupported ( + IN UINT16 MachineType, + IN UINT16 SubSystem + ) +{ + EFI_STATUS Status; + EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emu; + UINTN HandleCount; + EFI_HANDLE *HandleBuffer; + BOOLEAN ReturnValue; + UINTN Index; + + if (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (MachineType)) { + return TRUE; + } + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEdkiiPeCoffImageEmulatorProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return FALSE; + } + + ReturnValue = FALSE; + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol ( + HandleBuffer[Index], + &gEdkiiPeCoffImageEmulatorProtocolGuid, + (VOID **)&Emu + ); + ASSERT_EFI_ERROR (Status); + + if (Emu->IsImageSupported (Emu, MachineType, SubSystem)) { + ReturnValue = TRUE; + break; + } + } + + FreePool (HandleBuffer); + return ReturnValue; +} + /** Return whether the PE header of the load option is valid or not. @@ -1235,7 +1283,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