public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marvin Häuser" <mhaeuser@posteo.de>
To: "Ni, Ray" <ray.ni@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Ma, Maurice" <maurice.ma@intel.com>,
	"Dong, Guo" <guo.dong@intel.com>,
	"You, Benjamin" <benjamin.you@intel.com>
Subject: Re: [edk2-devel] [PATCH v2 2/3] UefiPayloadPkg: Add PayloadLoaderPeim which can load ELF payload
Date: Thu, 10 Jun 2021 07:30:28 +0000	[thread overview]
Message-ID: <785b1d37-9314-4909-7d1f-efa343018238@posteo.de> (raw)
In-Reply-To: <CO1PR11MB49307462C346035757486B638C359@CO1PR11MB4930.namprd11.prod.outlook.com>

On 10.06.21 05:40, Ni, Ray wrote:
>>> Without the ParseStatus field, callee cannot know whether ParseElfImage()
>> is called.
>>
>> It can by function contracts, the caller guarantees it. I.e. with the PE
>> library I linked, no other function must be called before the init function.
>> Your "ParseElfImage" function is very similar. The context is
>> initialized by it, i.e. it is trash if it is not called, i.e. it must be
>> called before other functions.
>> If it is called, which we know, the caller has the return status. For
>> PE, it means the caller must not proceed with any further PE processing
>> and abort immediately.
>> Is there any scenario where this does not work for ELF? Sorry if I
>> missed something.
> Caller might call LoadElfImage() without firstly calling ParseElfImage() by mistake.
> ParseStatus is added to catch such mistake.

If ParseElfImage() is not called, nothing will initialize ParseStatus 
and the load function will read random data. If AllocateZeroPool was 
used for the context, a common pattern throughout the codebase to harden 
against memory initialization bugs, it would even report success at all 
times anyway. Sorry, but I think this is dead code.

Maybe for some context, my main issue at first was that the checks are 
all proper runtime checks with no ASSERTs at all, so I got confused how 
this situation could happen in a realistic scenario. I needed to trace 
the ParseStatus data flow to understand the idea is basically the same 
as in the PE library. Code in a way is self-documenting, and this 
personally gave me a hard time understanding why it is written this way. 
But thanks for clarifying your intention! :)

Best regards,
Marvin

>
> I don't trust the caller would follow the contracts properly😊.


  reply	other threads:[~2021-06-10  7:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03  6:22 [PATCH v2 0/3] Add PayloadLoaderPeim which can load ELF payload Ni, Ray
2021-06-03  6:22 ` [PATCH v2 1/3] MdeModulePkg/UniversalPayload: Add definition for extra info in payload Ni, Ray
2021-06-03  6:37   ` [edk2-devel] " Wu, Hao A
2021-06-04  1:01     ` Ni, Ray
2021-06-04  1:02       ` Wu, Hao A
2021-06-07  9:07         ` Ni, Ray
2021-06-07 23:25   ` Wu, Hao A
2021-06-03  6:22 ` [PATCH v2 2/3] UefiPayloadPkg: Add PayloadLoaderPeim which can load ELF payload Ni, Ray
2021-06-07  1:47   ` Guo Dong
2021-06-07 21:53   ` [edk2-devel] " Marvin Häuser
2021-06-08  2:06     ` Ni, Ray
2021-06-08  3:10     ` Ni, Ray
2021-06-08  8:12       ` Marvin Häuser
2021-06-09  9:49         ` Ni, Ray
2021-06-09 10:03           ` Marvin Häuser
2021-06-10  3:40             ` Ni, Ray
2021-06-10  7:30               ` Marvin Häuser [this message]
2021-06-10  9:39                 ` Ni, Ray
2021-06-10 10:13                   ` Marvin Häuser
2021-06-10 10:43                     ` Michael Brown
2021-06-10 11:37                       ` Ni, Ray
     [not found]                       ` <168735878F610E03.10233@groups.io>
2021-06-15 14:36                         ` Ni, Ray
2021-06-15 17:31                           ` Marvin Häuser
2021-06-03  6:22 ` [PATCH v2 3/3] PeiCore: Remove assertion when failing to load PE image Ni, Ray
2021-06-07 23:28   ` Wu, Hao A
2021-06-07 20:33 ` [edk2-devel] [PATCH v2 0/3] Add PayloadLoaderPeim which can load ELF payload Guo Dong

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=785b1d37-9314-4909-7d1f-efa343018238@posteo.de \
    --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