From nobody Tue Feb 10 03:40:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55333+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55333+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583244092; cv=none; d=zohomail.com; s=zohoarc; b=gbcpyGwAUXbU+hzAL0paoYFrNW4i4pjdZowmdz4RPNvUNupXnz/AvdgYkig51/ledKkOYqxeoEHAbfflwtTmjGkWKf48W2aOh4EXmqZY+swiI/8c3ulbtX3EGGm/c7wJkGsZACjYcdBTBH1UULhfj/a02QIbEFoMP5tBIanwXnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583244092; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=KEuqMqswBlD6L2EG+CfeSiE4n6kr274XIddG3+Dqvs4=; b=bA6DE0ZL4rpTogJxJ91nIWrPRYdQm8tgLcp3ZSQCr83M+dUPwY/jJDtJuSsoT3IWTvHgccoYVDQYzR7BTXjdmgRLWBwSL6GHYoklhWbq8x7FduiuMQg/9YZFpBu2xBGbjGSfGQt/t1waFc3gzl8TxPISVefCQX7S4rN9Nqr3dEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55333+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 158324409210157.20324655695515; Tue, 3 Mar 2020 06:01:32 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id LM0HYY1788612x3oZVC9Pta9; Tue, 03 Mar 2020 06:01:31 -0800 X-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 X-Received: by mail-wr1-f65.google.com with SMTP id j7so4395608wrp.13 for ; Tue, 03 Mar 2020 06:01:30 -0800 (PST) X-Gm-Message-State: hAlHt8rlkCZyKplI5h5fXAJkx1787277AA= 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) X-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: [edk2-devel] [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> In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583244091; bh=tsCVpTya+0uXpJaKCPUUv9LwaTwR+65mH+WojjpiaqM=; h=Cc:Date:From:Reply-To:Subject:To; b=TpCk6QLdAXS5cxvvtTJJepwEVtqNW/rC2nRWF2oPm5CpDxZEpVDgcowSy97PZVyUKo4 AS7AxcPR0saKEf9gsim+xb7f79Sga9wQdAszVm12KeZgnvcTAMvHFx5QzOgRDN6shjASP T9XHqeJI1oTppuN8GDQkZxmOQYCkZKrlnNM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3D2564 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/Im= age/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 =3D (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContex= t.EntryPoint; - if (Image->PeCoffEmu !=3D NULL) { - Status =3D 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; - } - } =20 // // Fill in the image information for the Loaded Image Protocol @@ -1603,6 +1592,19 @@ CoreStartImage ( return EFI_UNSUPPORTED; } =20 + if (Image->PeCoffEmu !=3D NULL) { + Status =3D 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); =20 =20 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55333): https://edk2.groups.io/g/devel/message/55333 Mute This Topic: https://groups.io/mt/71700587/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-