From patchwork Thu Sep 20 23:01:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147171 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp100075ljw; Thu, 20 Sep 2018 16:02:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZWWm1yWPRzWek6oTqxe2vOQZm0gruclQ0erd7R0Er1RFnF3TqUGWg/suZnHkS1mrjSvqz1 X-Received: by 2002:a17:902:bf43:: with SMTP id u3-v6mr41313834pls.88.1537484524274; Thu, 20 Sep 2018 16:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537484524; cv=none; d=google.com; s=arc-20160816; b=twHyI6nNxAM3x+cS2D6kSBiR5CfWuL5m93vVKP2RrZJZcoWyzY4LAoR5EZ27BBhJFO 2t9CTurCpj+mCHqE71opbrm7Nnf/Lieel54eRRs10P5D9G9ogM44Bkleukb1d+RGKuqF cwoR9/PKKO8kKzgPs/by2XcqwanFyDp0VDD2xEM6GNDmpw+23QHuoYlVHfEy6SfUI4Ia ulrk4+BEvNgwEq/tZQd6DBta4Ehfcabb/dDNdUqwKlYewQQtIZ0gXwAaGfBe/LzHA+T8 8iyEBagLJzknhOxvkCuucdLtDdjcJJnWCZNUuMIaZEY/gBzXEa9cIJMJI1cIwEWd9xWa X8Rw== 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=Awf1dD2iPMN65CnMnr4YUsLE6f2Grh9F7EZBNJH98iU=; b=d1yRAhtJ1ICNZKv+IiySUyNKrbpA3Pnb3QEN0yq6psRUaXmEk0XJGBc4zivrPRVjwk /q7n5/Kl6zfl8JIFq8U2db9VTA2f3DjqNFPotijBc+XwG0hUK8eGZMTGD6Z2ySCd8clh ChKNoqwJpcLwyuzXFm5lM+gWQ922BVYwW/n+pSQMBNu9lXZrGZGR+o/PXt7by5WrNTDN +Rrri2Jd5Bq5xsc66mMoh+VGxouHqRHtHQWa+eV9r9cYfhIlrDvlvNGkN3OzbpU51KsK E5rvFozUwQrRrdLsWKtdqeAWTIW/mder9LvDff12pMdk6XaPRdlWTKVvoBEiMHb1QJCl 7uQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Hrisa28h; 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 j10-v6si25992375plk.406.2018.09.20.16.02.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 16:02:04 -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=Hrisa28h; 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 CEEFA2114A6B6; Thu, 20 Sep 2018 16:01:59 -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=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-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 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: [edk2] [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: , 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 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(-) -- 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..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