Bug 1892860
| Summary: | The fix use after free in halt/reboot patch changed exit into reboot | |||
|---|---|---|---|---|
| Product: | Red Hat Enterprise Linux 7 | Reporter: | Paulo Andrade <pandrade> | |
| Component: | grub2 | Assignee: | Bootloader engineering team <bootloader-eng-team> | |
| Status: | CLOSED ERRATA | QA Contact: | Release Test Team <release-test-team-automation> | |
| Severity: | urgent | Docs Contact: | ||
| Priority: | urgent | |||
| Version: | 7.9 | CC: | djuarezg, fkrska, jaredz, knweiss, kpfleming, lnarvaez, mlewando, pjanda, release-test-team-automation, rharwood, rmetrich, sbroz, yoliynyk | |
| Target Milestone: | rc | Keywords: | ZStream | |
| Target Release: | --- | Flags: | tpopela:
mirror+
|
|
| Hardware: | All | |||
| OS: | Linux | |||
| Whiteboard: | ||||
| Fixed In Version: | grub2-2.02-0.87.el7_9.9 | Doc Type: | Bug Fix | |
| Doc Text: |
Cause: Backport of a security fix.
Consequence: grub2's exit command caused a reboot instead of an exit
Fix: Fix the code
Result: exit command works as expected
|
Story Points: | --- | |
| Clone Of: | ||||
| : | 2018338 (view as bug list) | Environment: | ||
| Last Closed: | 2022-05-18 16:15:22 UTC | Type: | Bug | |
| Regression: | --- | Mount Type: | --- | |
| Documentation: | --- | CRM: | ||
| Verified Versions: | Category: | --- | ||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | ||
| Cloudforms Team: | --- | Target Upstream Version: | ||
| Embargoed: | ||||
| Bug Depends On: | ||||
| Bug Blocks: | 2018338 | |||
|
Description
Paulo Andrade
2020-10-29 19:24:10 UTC
For reference, RHEL8 branches seem to be just fine. Only RHEL7 branches show this issue. https://github.com/rhboot/grub2/blob/rhel-8.2/grub-core/kern/efi/efi.c Adding my RH customer case info here as well :) GRUB2's code allows to exit grub so it can then continue booting the next boot option in the saved boot order. This was the case before but apparently a wrong patch from Red Hat changed the code responsible for this matter. The related patch "[PATCH 325/336] efi: Fix use-after-free in halt/reboot path" seems to be specified here: https://github.com/rhboot/grub2/commit/f7bd9986f607a924bf23b813900a8595f2815f0c (Please correct me if I am wrong about the source of this and point me to the appropriate source code instead) When applying the patches in your source rpms (downloaded from your customer portal), we see that the patch does the following: ``` diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index 42c68307f3f..6c4099a685d 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -162,9 +162,10 @@ grub_exit (int retval) if (retval == 0) rc = GRUB_EFI_SUCCESS; - grub_machine_fini (GRUB_LOADER_FLAG_NORETURN); - efi_call_4 (grub_efi_system_table->boot_services->exit, - grub_efi_image_handle, rc, 0, 0); + grub_machine_fini (GRUB_LOADER_FLAG_NORETURN | + GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY); + efi_call_4 (grub_efi_system_table->runtime_services->reset_system, + GRUB_EFI_RESET_COLD, rc, 0, NULL); for (;;) ; } ``` As you can see the exit function is being changed to do a reset_system, and at the same time the grub_reboot is no longer appearing after applying the patches. If you check the diff and the commit, it seems like the patch creation was wrongly created and both exit and reboot functions got mixed. This issue is relevant in our case as we use grub2-mkimage to create a bootable image we use in our PXE network installations, and these images behave differently to what they did in older versions. Both grub2-2.02-0.87.el7.x86_64.rpm and grub2-2.02-0.86.el7_8.x86_64.rpm present this issue. No news? @lnarvaez you can find the build here: https://people.redhat.com/mlewando/grub2-2.02-0.87.el7_9.9/ Please ask your customer for testing and let us know the results. thanks! @mlewando We would also need access to the src rpm if possible. Thank you. @djuarezg https://people.redhat.com/~pjanda/grub2-2.02-0.87.el7_9.9/ should contain it. In case you want to use a remote repository direcly, repo file for you: https://people.redhat.com/~pjanda/grub2-2.02-0.87.el7_9.9.repo you can find the src rpm here: https://people.redhat.com/mlewando/grub2-2.02-0.87.el7_9.9.src.rpm @mlewando Although The grub_exit function seems to be fine now, the grub_reboot one is still nowhere to be found, which is still present on https://github.com/rhboot/grub2/blob/rhel-8.6.0/grub-core/kern/efi/efi.c as the aforementioned patch affected not only one function but two. I will nonetheless test on a physical machine the provided RPMs to see if for the time being it makes it work as before (from what I saw inspecting the code, it should as it matches our local patches) @djuarezg Please do test on a physical machine and let us know if you have the expected functionality. You are right, though, that grub_reboot is not in 7.9... @mlewando I can confirm that it behaves as expected when exiting, thanks. (In reply to Daniel Juarez from comment #34) > @mlewando Although The grub_exit function seems to be fine now, > the grub_reboot one is still nowhere to be found, which is still present on > https://github.com/rhboot/grub2/blob/rhel-8.6.0/grub-core/kern/efi/efi.c as > the aforementioned patch affected not only one function but two. > Hello @djuarezg I'm sorry but now I'm unsure if the build provided works for you (comment 36) or not (comment 34). I've checked it in virtual machine * grub2-2.02-0.87.el7 - both commands reboot and exit in grub command line reboot the system * grub2-2.02-0.87.el7_9.9 - command reboot restarts system, command exit exits grub and next loader in boot order is executed (In reply to Petr Janda from comment #37) > (In reply to Daniel Juarez from comment #34) > > @mlewando Although The grub_exit function seems to be fine now, > > the grub_reboot one is still nowhere to be found, which is still present on > > https://github.com/rhboot/grub2/blob/rhel-8.6.0/grub-core/kern/efi/efi.c as > > the aforementioned patch affected not only one function but two. > > > > Hello @djuarezg > I'm sorry but now I'm unsure if the build provided works for you (comment > 36) or not (comment 34). > > I've checked it in virtual machine > * grub2-2.02-0.87.el7 - both commands reboot and exit in grub command line > reboot the system > * grub2-2.02-0.87.el7_9.9 - command reboot restarts system, command exit > exits grub and next loader in boot order is executed grub_exit behaves as it should, but grub_reboot is not fixed. For our use case the issue is solved, but the underlying bug is not completely fixed, that is what I meant. If this patch is going to fix one issue it would better fix both. Hello Daniel. As it works for you and nobody else complains I consider it fixed enough. Agree it is not 100% proper fix, but I prefer to have changes as small as possible. In newer RHEL releases this behavior should work as expected. Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (grub2 bug fix and enhancement update), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2022:4640 The needinfo request[s] on this closed bug have been removed as they have been unresolved for 365 days |