From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by mx.groups.io with SMTP id smtpd.web11.4061.1583244090519517761 for ; Tue, 03 Mar 2020 06:01:30 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=Mfj+gzYm; spf=pass (domain: linaro.org, ip: 209.85.221.65, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wr1-f65.google.com with SMTP id j7so4395608wrp.13 for ; Tue, 03 Mar 2020 06:01:30 -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=1kjmBGGHtZ3//rsb1Vf+kZU+La9ELaLZai5TuI5LnKw=; b=Mfj+gzYmSHDwN3z4NLf6DyILfzf0oR5cPvf5mJpr8dKwjwwx3qyqwumEWCiuQxAoHM +gYatYlskXbgvSClWnh3HEVQMJH1ikjVao5tLkOq32Mam6FV0Uh9HjdDL4vdhaIekqii s7v78DTGndyKnOQ3QoWd1NDUxyTyc2CPMyfDxPVm4nr4B7r8w3rYgpvN5Tpmcseo6qk9 3qNPMLrU+ynyvIpOD0yF/3IXvU906RBX+dkNr0rDTTyt3A0/lnXrxOeyOJG7mEva9a7h T1cJ8eE1lxUw4pfNGyANsYSxaCOtTmQAuSewr9edmZw5lI6SGKUQIyBOSWg6fFyoKJkx r0iA== 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=1kjmBGGHtZ3//rsb1Vf+kZU+La9ELaLZai5TuI5LnKw=; b=Wj76YgyhOU8R/h1qJweI0N6Z5xWb0yKRfyaPJWVsV/iltUuVl+hvdkw5H0CkYpUGTo 2IhpRQptgxqbPgCrLt1yjxif6LkY1/51KrWox44ZuvuZ4Q+sjX3DUD52CtIDJ2udohuT yP0fEO1vJROYenTkfqSdNwmhmX3MfiO9ICUpJY5UUgWNEL5I7Z09twWdFW1DLZRNkI+f 6f42U71WhnkuYQL52L2M4U2+CSLzxQ5jDInslRy/ygjcO2EIWWrzVTydszYoHo/mUhyg iwa6FCGgimLxCbjv+uzwBUGI4/BJFyYSQDTTk9IHGPVyblJxkJLCyUjo19zYYPL75tEr ov/A== X-Gm-Message-State: ANhLgQ03ocRtX0G8O+qxusKnxIeB7X60vck3o+IiaQvtrTAUv3yn4+cq 7rUUzc8wdVkp44k1co2vaNHaTtEKoZm37A== X-Google-Smtp-Source: ADFU+vtjW0RynelW6Z6fSVVIEuHtfYryu72XafQBZZYaeaMbhDaULi/z1nmmuwiZ2NkUHd7WB43tZA== X-Received: by 2002:adf:de85:: with SMTP id w5mr5290876wrl.323.1583244088692; Tue, 03 Mar 2020 06:01:28 -0800 (PST) Return-Path: Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id i10sm27575122wrn.53.2020.03.03.06.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:01:27 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, Liming Gao Subject: [PATCH v4 5/7] MdeModulePkg/DxeCore: defer PE/COFF emulator registration to StartImage Date: Tue, 3 Mar 2020 15:01:15 +0100 Message-Id: <20200303140117.7288-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-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. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2564 Signed-off-by: Ard Biesheuvel Acked-by: Liming Gao --- 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