public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: devel@edk2.groups.io, mikuback@linux.microsoft.com
Cc: gaoliming@byosoft.com.cn, michael.kubacki@microsoft.com
Subject: Re: [edk2-devel] [PATCH] MdePkg/BasePeCoffLib: Deal with broken debug directories
Date: Fri, 5 May 2023 10:12:10 +0200	[thread overview]
Message-ID: <CAMj1kXEFRhaVw0o7ky6QZ-XEd2=JOj-nMCw5epYxof6kyfNouQ@mail.gmail.com> (raw)
In-Reply-To: <7122d2bc-2e7e-d189-1cee-adb2465621d7@linux.microsoft.com>

On Fri, 5 May 2023 at 03:56, Michael Kubacki
<mikuback@linux.microsoft.com> wrote:
>
> Acked-by: Michael Kubacki <michael.kubacki@microsoft.com>
>

Merged as #4340

Thanks all


> On 5/4/2023 10:47 AM, Ard Biesheuvel wrote:
> > 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=4425
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> > ---
> >   MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 14 ++++++++++++++
> >   1 file changed, 14 insertions(+)
> >
> > diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/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 += DebugEntry.SizeOfData;
> >
> >               }
> >
> >
> >
> > +            //
> >
> > +            // Implementations of GenFw before commit 60e85a39fe49071 will
> >
> > +            // concatenate the debug directory entry and the codeview entry,
> >
> > +            // and erroneously put the combined size into the debug directory
> >
> > +            // entry's size field. If this is the case, no other relevant
> >
> > +            // directory entries can exist, and we can terminate here.
> >
> > +            //
> >
> > +            NextIndex = Index + sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);
> >
> > +            if ((NextIndex < DebugDirectoryEntry->Size) &&
> >
> > +                (DebugEntry.FileOffset == (DebugDirectoryEntryFileOffset + NextIndex))) {
> >
> > +              break;
> >
> > +            }
> >
> > +
> >
> >               continue;
> >
> >             }
> >
> >
> >
>
>
> 
>
>

      reply	other threads:[~2023-05-05  8:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04 14:47 [PATCH] MdePkg/BasePeCoffLib: Deal with broken debug directories Ard Biesheuvel
2023-05-05  1:54 ` 回复: " gaoliming
2023-05-05  1:56 ` [edk2-devel] " Michael Kubacki
2023-05-05  8:12   ` Ard Biesheuvel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMj1kXEFRhaVw0o7ky6QZ-XEd2=JOj-nMCw5epYxof6kyfNouQ@mail.gmail.com' \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox