From nobody Fri May 3 05:47:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104027+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104027+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1683211674; cv=none; d=zohomail.com; s=zohoarc; b=F/yYPjkQb6eAtl/Iiv6YCud8Bwv1xkZ0wYntlyJ2lgWvp0PiO3ymZyG72mtnH4BBnGPHtQXxyc1hrGeT+jKEOd4Qc57cjIng0d1a9lssQisDt/jROsBcjFZo3SHqquR/GxqOehD4BTCsC5cdpK6ksmUpEiVleoGKcMarsOLAFM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683211674; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=Bk6H5Pjee8ORG8KvQ1m+v8vIev8cmRGpQ8WPNDL0ePA=; b=OuykW6KAX2URUwXRICr+NTT7WvigMj76I/ZHKPSOHJlESBHpCn3Pxoo0/HsABvQW4Ve6Aug3cg7CoMYQbBvHc/g+bT5qunCHyJ1mjRQg2Bp4F6EEeL8BF2/VrdwqFgde6rRXYGGuN6BSSh1bmdQci7VDFB4NeZj7PL6MD591RIc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104027+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683211674229230.83734085237916; Thu, 4 May 2023 07:47:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DNeAYY1788612xLDTfwPAfSV; Thu, 04 May 2023 07:47:53 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.51667.1683211673168794122 for ; Thu, 04 May 2023 07:47:53 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 485FA6122C; Thu, 4 May 2023 14:47:52 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF523C433EF; Thu, 4 May 2023 14:47:50 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: gaoliming@byosoft.com.cn, michael.kubacki@microsoft.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH] MdePkg/BasePeCoffLib: Deal with broken debug directories Date: Thu, 4 May 2023 16:47:39 +0200 Message-Id: <20230504144739.3912103-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,ardb@kernel.org X-Gm-Message-State: oseI0cM4NVRDB3Ym6gXgKenax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683211673; bh=VThNS4r5z9WVUzG2FV1ngEbJ0KyDM0sbEk17kgpH23g=; h=Cc:Date:From:Reply-To:Subject:To; b=IraCvzGqAfMICMByoBpDBaj6ZSNhm0fuQCxIngdaFpyLAaK9oiJ/m0UibNm4jLTEbSJ sToE42C1gURI5C6bsw5miMhDEb1fOIIUA5CqLLBcJ3bfa5iObnB3ttr4pJrCMdo6Dfzgk 2a3ItGc+BNSgaAl1B2e9AHwA4N6SMo0VHF8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683211674577100001 Content-Type: text/plain; charset="utf-8" Older versions of GenFw put the wrong value in the debug directory size field in the PE/COFF header: instead of putting the combined size of all the entries, it puts the size of the only entry it creates, but adds the size of the NB10 payload that the entry points to. This confuses the loader now that we started using additional debug directory entries to describe DLL characteristics. GenFw was fixed in commit 60e85a39fe49071, but the binaries that were generated with it still need to be supported. So let's detect this condition, and check whether the size of the debug directory is consistent with the NB10 payload: if we should expect additional directory entries where we observe the NB10 payload, the size field is clearly wrong, and we can break from the loop. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4425 Signed-off-by: Ard Biesheuvel Acked-by: Michael Kubacki Reviewed-by: Liming Gao Tested-by: Liming Gao --- MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/Bas= ePeCoffLib/BasePeCoff.c index 4b71176a0c7c2ed0..27f8526370fa3859 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -585,6 +585,7 @@ PeCoffLoaderGetImageInfo ( UINTN Size; UINTN ReadSize; UINTN Index; + UINTN NextIndex; UINTN DebugDirectoryEntryRva; UINTN DebugDirectoryEntryFileOffset; UINTN SectionHeaderOffset; @@ -755,6 +756,19 @@ PeCoffLoaderGetImageInfo ( ImageContext->ImageSize +=3D DebugEntry.SizeOfData; } =20 + // + // Implementations of GenFw before commit 60e85a39fe49071 will + // concatenate the debug directory entry and the codeview entr= y, + // and erroneously put the combined size into the debug direct= ory + // entry's size field. If this is the case, no other relevant + // directory entries can exist, and we can terminate here. + // + NextIndex =3D Index + sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + if ((NextIndex < DebugDirectoryEntry->Size) && + (DebugEntry.FileOffset =3D=3D (DebugDirectoryEntryFileOffs= et + NextIndex))) { + break; + } + continue; } =20 --=20 2.39.2 -=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 (#104027): https://edk2.groups.io/g/devel/message/104027 Mute This Topic: https://groups.io/mt/98685272/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-