From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web11.1231.1582746235229368031 for ; Wed, 26 Feb 2020 11:43:55 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=rDnCWCpD; spf=pass (domain: linaro.org, ip: 209.85.221.68, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wr1-f68.google.com with SMTP id z3so243878wru.3 for ; Wed, 26 Feb 2020 11:43:54 -0800 (PST) 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=EH3GVtGq8OoMv8WgT1c0rlKWHdhlu2xPRBdBnQV2AQ0=; b=rDnCWCpDpcm8mmkOfFjVxJPB8ZO3P2VRSvPsawlfZdFs+TVJv5PGrD90821Qu35v5v i27/XWZi5nzEwYjGrvujP684vGzU29RLr8PNl41begjEoqlm8yV95q1todU3REuRuxLS lEa6XG+iOZEFhSIZULRLwVrxKKxm8ev7pSwhlFNzv5mEBHZB5EJcfVmVrQX+dBUGamqA 9yqn5MtsbRShYGpMfMj2VibV3JBlaxp9l4AVzbTar4GcyncF2Rl49szK0Yui9h3ZkO08 7M3JiBP+OuCuZ2tOl61pVtcZkm4mA6wLKFNPAW4MtJBDa4qvIM0jXo+jinW4GAIORCHv mrJQ== 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=EH3GVtGq8OoMv8WgT1c0rlKWHdhlu2xPRBdBnQV2AQ0=; b=iCaIzYG76+uG7INnr5TWnf6x7r9solIKQ+h5q2qh62wsSEP+q+5xUXjik4hIbPKYD2 zzbO2yg6n2x6CXksDawxfOPRSsCz78G9nq6yLMdhwSb80prDBDuvkVedc8/RPTUPTyni qXvy2HoUviqJsHNFJBdxmbt0Km5hqqNMdZMf0nue2ynY7tBa/YJQlLj+vVYhjLyYAArb nfEWg7vXZS7tBGtV/gXg3IYvzT8+ePkX9GOUwfc8g8mn1c+xyt2WSqi+XLSuJoGCgAf6 dJ0/L8WDVFVshZmroCYlDQxR3PLEN73vzcans74/jHXyWPh5sSgq6lr2nhbrPbEZw/1X EKwQ== X-Gm-Message-State: APjAAAWzS32V8JHpGAX6boIPvbJ3dYyo6Xnq6JM8jr0qPlsdXpmpMytE b6egVjknog2iZEhTO6ZILMkoGeDbvjjv6Q== X-Google-Smtp-Source: APXvYqxMVJA5b8s67Xn8TxMj/mh0bKGga/6Lcm96wiJFBQTVF644W14sxGbyRbK53uXJrRdRZKir3A== X-Received: by 2002:a5d:5044:: with SMTP id h4mr264021wrt.4.1582746233445; Wed, 26 Feb 2020 11:43:53 -0800 (PST) Return-Path: Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id c9sm4235162wmc.47.2020.02.26.11.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 11:43:52 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, michael.d.kinney@intel.com, jian.j.wang@intel.com, hao.a.wu@intel.com, ray.ni@intel.com, zhichao.gao@intel.com Subject: [PATCH v3 5/6] MdeModulePkg/DxeCore: defer PE/COFF emulator registration to StartImage Date: Wed, 26 Feb 2020 20:43:42 +0100 Message-Id: <20200226194343.2985-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200226194343.2985-1-ard.biesheuvel@linaro.org> References: <20200226194343.2985-1-ard.biesheuvel@linaro.org> EDK2's implementation of the LoadImage() boot service permits non-native binaries to be loaded (i.e., X64 images on IA32 firmware), but any attempts to start such an image using StartImage() will return EFI_UNSUPPORTED. The integration of the PE/COFF emulator protocol into the DXE core deviates slightly from this paradigm, given that its IsImageSupported hook as well as its RegisterImage hook are invoked from LoadImage, and by the time StartImage is called, no opportunity is given to the provider of the PE/COFF emulator protocol to prevent an image from being started if it only supports loading it. To address this disparity, let's move the invocation of RegisterImage() to the implementation of the StartImage() boot service, allowing the emulator to permit LoadImage() but reject StartImage() on images that turn out not to meet the requirements of the emulator as it is being started. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/Image/Image.c | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 22a87ecf6d7c..d86da89ee704 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -756,17 +756,6 @@ CoreLoadPeImage ( // Get the image entry point. // Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContext.EntryPoint; - if (Image->PeCoffEmu != NULL) { - Status = Image->PeCoffEmu->RegisterImage (Image->PeCoffEmu, - Image->ImageBasePage, - EFI_PAGES_TO_SIZE (Image->NumberOfPages), - &Image->EntryPoint); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_LOAD | DEBUG_ERROR, - "CoreLoadPeImage: Failed to register foreign image with emulator.\n")); - goto Done; - } - } // // Fill in the image information for the Loaded Image Protocol @@ -1603,6 +1592,19 @@ CoreStartImage ( return EFI_UNSUPPORTED; } + if (Image->PeCoffEmu != NULL) { + Status = Image->PeCoffEmu->RegisterImage (Image->PeCoffEmu, + Image->ImageBasePage, + EFI_PAGES_TO_SIZE (Image->NumberOfPages), + &Image->EntryPoint); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_LOAD | DEBUG_ERROR, + "CoreLoadPeImage: Failed to register foreign image with emulator - %r\n", + Status)); + return Status; + } + } + PERF_START_IMAGE_BEGIN (Handle); -- 2.17.1