Skip to content

Conversation

@rosslagerwall
Copy link
Contributor

No description provided.

If the EFI application exits, Shim will uninstall the protocols and then
free the image. If something (e.g. GRUB) calls UnloadImage at this
point, there is a double free because HandleProtocol() returns
EFI_INVALID_PARAMETER and then Shim frees the image again.
HandleProtocol() returns EFI_INVALID_PARAMETER because the handle is
automatically freed when all protocols are uninstalled.

Be robust against this and other errors by only freeing the image if
HandleProtocol() returns EFI_SUCCESS.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
This may happen if the image is loaded and then unloaded without calling
StartImage().

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
@vathpela
Copy link
Member

vathpela commented Aug 5, 2025

Sorry about the noise with the checks; @bluca and I were working on it when your PR landed.

else if (efi_status != EFI_SUCCESS)
return efi_status;

flush_cached_sections(ImageHandle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need to flush the cached sections in either case here?

Copy link
Contributor Author

@rosslagerwall rosslagerwall Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. If we hit the else if (efi_status != EFI_SUCCESS) case, either:

  • We were passed a previously valid handle that was freed by the UninstallMultipleProtocolInterfaces() call on line 389. In that case we have already called flush_cached_sections() on the handle (line 383) so nothing to do here.
  • We were passed NULL, garbage or an unknown handle, in which case we shouldn't call flush_cached_sections() on the handle.

@vathpela vathpela merged commit 6a1d1a9 into rhboot:main Aug 13, 2025
71 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants