generate_path() seems to allocate memory for *PathName (with AllocatePool()) and for *grubpath (with FileDevicePath()).
The caller of generate_path(), start_image(), doesn't seem to make any use of *grubpath (called "path" there). It seems to be leaked. PathName is also leaked if load_image() succeeds but handle_image() fails.
But my main point is: I believe you should not overwrite the EFI_LOADED_IMAGE object (even temporarily) that you located for the shim binary itself with HandleProtocol() / LOADED_IMAGE_PROTOCOL. I suspect that, after you've loaded the grub binary from disk and verified / relocated it, you should install it with the LoadImage() boot service as a child image. LoadImage() can load an image from a preexistent memory buffer. (See the SourceBuffer/SourceSize parameters.)
Afterwards the grub image could be / should be started by the StartImage boot service.
LoadImage() might even do the entire relocation / verification automatically. What's the reason for manual relocation? Have you perhaps found specific circumstances that make LoadImage()/StartImage() unsuitable?
Power management, mobile and firmware developer on Linux. Security developer at Aurora. Ex-biologist. mjg59 on Twitter. Content here should not be interpreted as the opinion of my employer. Also on Mastodon.
Re start_image()
Date: 2012-10-31 11:04 pm (UTC)The caller of generate_path(), start_image(), doesn't seem to make any use of *grubpath (called "path" there). It seems to be leaked. PathName is also leaked if load_image() succeeds but handle_image() fails.
But my main point is: I believe you should not overwrite the EFI_LOADED_IMAGE object (even temporarily) that you located for the shim binary itself with HandleProtocol() / LOADED_IMAGE_PROTOCOL. I suspect that, after you've loaded the grub binary from disk and verified / relocated it, you should install it with the LoadImage() boot service as a child image. LoadImage() can load an image from a preexistent memory buffer. (See the SourceBuffer/SourceSize parameters.)
Afterwards the grub image could be / should be started by the StartImage boot service.
LoadImage() might even do the entire relocation / verification automatically. What's the reason for manual relocation? Have you perhaps found specific circumstances that make LoadImage()/StartImage() unsuitable?
Thanks
Laszlo