Fix double free and leak in the loader protocol#769
Merged
vathpela merged 2 commits intorhboot:mainfrom Aug 13, 2025
Merged
Conversation
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>
Member
|
Sorry about the noise with the checks; @bluca and I were working on it when your PR landed. |
bluca
reviewed
Aug 5, 2025
| else if (efi_status != EFI_SUCCESS) | ||
| return efi_status; | ||
|
|
||
| flush_cached_sections(ImageHandle); |
Contributor
There was a problem hiding this comment.
don't we need to flush the cached sections in either case here?
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.