Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MdeModulePkg: Remove ASSERT which prevents VOLUME_CORRUPTED image status from being returned #58

Closed
wants to merge 1 commit into from

Conversation

mikebeaton
Copy link
Contributor

@mikebeaton mikebeaton commented Nov 16, 2023

When DEBUG_RAISE is disabled then PeCoffInitializeContext within BasePeCoffLib2 will return VOLUME_CORRUPTED for certain image errors. These errors then hit the ASSERT removed by this PR. Without it these status codes pass back out of gBS->LoadImage in DEBUG builds, as desired.

…being returned

When DEBUG_RAISE is disabled then PeCoffInitializeContext within
BasePeCoffLib2 will return VOLUME_CORRUPTED for certain image errors.
These errors then hit the removed ASSERT. Without it these status codes
pass back out of gBS->LoadImage as desired.
@mikebeaton mikebeaton requested review from mhaeuser, vit9696 and MikhailKrichanov and removed request for mhaeuser November 16, 2023 22:58
@mikebeaton
Copy link
Contributor Author

mikebeaton commented Nov 17, 2023

On reflection, there are several other recently added ASSERT (FALSE) statements in this file which should probably be changed into DEBUG_RAISE, for the same reason as the change of Pcd on DEBUG_RAISE which was just made: these are valid responses of the code to errors in images, not internal errors, so we only want them to ASSERT in specific debugging scenarios, not just generally (even in DEBUG builds).

@MikhailKrichanov
Copy link
Contributor

Desired by whom? I hope in the near future uefi-format branch will be merged and the behavior will change to the following 7d97eab#diff-7716cd945ce4a34439a613ef76374c82b389ac12470368e183138d48df361e73R1246

@mikebeaton
Copy link
Contributor Author

mikebeaton commented Nov 17, 2023

Desired by anyone who isn't debugging the internals of that particular module, but wants to be able to use a DEBUG or NOOPT build (e.g. so as to be able to step between external code and the library), only expecting the library code to stop and assert if it detects it's own unexpected internal state, not on valid responses to input (particularly, input - such as corrupt or invalid images - which the calling code might itself want to be testing it's own handling for - that's a specific case of what I take to be a general principle).

@mikebeaton
Copy link
Contributor Author

mikebeaton commented Nov 17, 2023

The commit you've referenced replaces the ASSERT with cpu_dead_loop and has a comment stating that the code in question should be unreachable. It's not unreachable, the new PeCoffInit correctly returns error statuses on corrupt images, which then get back to here (and should be allowed to percolate back out to the code which called gBS->LoadImage). (Exactly what this PR is trying to fix.)

The separated 32 bit and 64 bit slices of 10.4 in here are examples of such images: https://github.com/acidanthera/OpenCorePkg/tree/master/Utilities/AppleEfiSignTool/Samples

@vit9696
Copy link
Collaborator

vit9696 commented Nov 17, 2023

@MikhailKrichanov, the code in this pull request looks correct to me. Why should we freeze firmware upon trying to load a corrupted image from userspace? We should simply reject.

  • "ASSERTs" should become CpuDeadLoop when they were used by EDK II maintainers as a way to stop booting.
  • They should become DEBUG_RAISE or simply removed when they were used as a way to help debugging.

@mikebeaton mikebeaton changed the title MdeModulePkg: Remove ASSERT which prevents corrupt image status from being returned MdeModulePkg: Remove ASSERT which prevents VOLUME_CORRUPTED image status from being returned Nov 17, 2023
@vit9696
Copy link
Collaborator

vit9696 commented Nov 17, 2023

Just to be clear:

  • Images with violated requirements loaded from the firmware (i.e. BIOS) should indeed cause a dead loop, as it means we have corrupted firmware.
  • Images that come from the user should simply gracefully abort, as the user may supply anything and we should just reject without killing everything.

@mikebeaton
Copy link
Contributor Author

mikebeaton commented Nov 17, 2023

@MikhailKrichanov - Looking at the current uefi-format branch, I can see that the code should indeed exit cleanly - i.e. not hang - if the exit status of UefiImageInitializeContextPreHash is EFI_NOT_STARTED: https://github.com/acidanthera/audk/blob/uefi-format/MdeModulePkg/Core/Dxe/Image/Image.c#L1234-L1248 . But looking at the code for UefiImageInitializeContextPreHash
it appears to be written to return either EFI_SUCCESS or EFI_UNSUPPORTED: https://github.com/acidanthera/audk/blob/uefi-format/MdePkg/Library/BaseUefiImageLib/UefiImageLib.c#L114 . If I'm right, that may be a mistake?

If I'm right that that is the wrong status, then when fixed code here will already do what I'm aiming at, thank you.

@mikebeaton mikebeaton mentioned this pull request Nov 17, 2023
@MikhailKrichanov
Copy link
Contributor

@vit9696, the requirements are implemented in the latest fix.

@mikebeaton mikebeaton closed this Nov 20, 2023
MikhailKrichanov pushed a commit that referenced this pull request Dec 15, 2023
Azure should install code coverage tool (lcov), it didn't
exist on Fedora and Ubuntu by default.

Update docker setting, pick below solution between 47addc9 and 3b3eb8f
3b3eb8f Fixes and improvements to dev containers (#69)
54e5bd1 Enable GTK on Fedora QEMU (#63)
f1c7a20 Fedora: install code coverage tools for GCC (#62)
2ce82af Ubuntu-22: Add initial Ubuntu-22 image (#61)
14d2aba Add Fedora 37 image with gcc12 (#60)
5b8a008 Add dotnet runtime to fedora build (#57)
f5c874a Fix platform build file name for EDK2 change (#58)
48540ad Ubuntu-20: Fix dev image entrypoint (#55)
98e849d Fedora-35: Add Powershell to build image (#52)

Cc: Michael D Kinney <[email protected]>
Cc: Sean Brogan <[email protected]>
Cc: Michael Kubacki <[email protected]>
Cc: Oliver Steffen <[email protected]>
Cc: Chris Fernald <[email protected]>
Signed-off-by: Gua Guo <[email protected]>
Reviewed-by: Michael D Kinney <[email protected]>
Reviewed-by: Michael Kubacki <[email protected]>
Reviewed-by: Chris Fernald <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants