From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::641; helo=mail-pl1-x641.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (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 CC30821148ED9 for ; Thu, 20 Sep 2018 16:01:55 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id t20-v6so1587701ply.13 for ; Thu, 20 Sep 2018 16:01:55 -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=Puva7D6n7qs6A7mDCY6+0VGyWDnCuLuLCTtGt47XCTA=; b=Hrisa28hAjUTrhAJEOjl0Sw2ZNZ4i5JH/zt3QrcQsNOjntm0j/46jZ3TrQmfarDW+J CQM+q+JVmO1GkMpyx9Y6b3T+/vrvk+vuY38QGjyuZY2l+eo1o8HgkK4vHXAhaCtVnK7t hEfn+bXwebUWn1jreJrtb4oTU4J6hKzvBtjGU= 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=Puva7D6n7qs6A7mDCY6+0VGyWDnCuLuLCTtGt47XCTA=; b=QCksZRyb1+iaKtcTo5eGgS3iscrSAAp2y0EFZ8KhCD7SOpIndwV9hEXX+hHpwPOET9 yVwuL2SkPcR5GvVTBiwSjEOhZJikuH4R+yAJtOqsazUmMUeWH1qpFTC0RWNY6oa5oT4q aEeZ549vC3OBRsRQLzrj9pn7hha4Z6y2ZLZaIIqK5C+UuN5citqfgK4l6avWKJLMrboV hcYboU/gcZh1bP0qGp0lg8Sl0Wxu3bEJbxXyq0IzDeNb12SMJxLbLwM7bHAf1B8oaki3 per9DI6oZRaDJhywLyXIDFM4/EPZSCsNcde24pHeiRQAYOjyxpMUZmnaG44lUUJ6NRGz D9Vg== X-Gm-Message-State: APzg51BXyTKXeeYqQAchTcy+N09Pm4aGVRWfYhjhsgCZFB/WrwTEtlqh y2x1vy5qWQ55FMZLvra/gH3KsBphuKk= X-Google-Smtp-Source: ANB0VdZrb5y1fRWr1naI5O7KA8T2orxLU1xt3kWXX979ZyDRDFqvQCb7ZGP7EnR+0STLB3mhbsUsgA== X-Received: by 2002:a17:902:7587:: with SMTP id j7-v6mr41747185pll.256.1537484515349; Thu, 20 Sep 2018 16:01:55 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id p4-v6sm37507823pfd.65.2018.09.20.16.01.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:01:54 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: Ard Biesheuvel , Vincent Zimmer , Brian Richardson , Michael D Kinney , Andrew Fish , Leif Lindholm , Star Zeng , Eric Dong , Ruiyu Ni , Liming Gao , Jaben Carsey , Steven Shi Date: Thu, 20 Sep 2018 16:01:42 -0700 Message-Id: <20180920230145.7565-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180920230145.7565-1-ard.biesheuvel@linaro.org> References: <20180920230145.7565-1-ard.biesheuvel@linaro.org> Subject: [PATCH v3 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: , X-List-Received-Date: Thu, 20 Sep 2018 23:01:56 -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 an 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(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c index 7bf96646c690..f6fda8f2c3f7 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, NULL)) { + 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 -- 2.17.1