Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

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: grub2Assignee: 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.9CC: djuarezg, fkrska, jaredz, knweiss, kpfleming, lnarvaez, mlewando, pjanda, release-test-team-automation, rharwood, rmetrich, sbroz, yoliynyk
Target Milestone: rcKeywords: 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
grub2 mainline in grub-core/kern/efi/efi.c has both, a reboot and
exit function.

The rhel-7.9 branch has only grub_exit. With the patch to fix
use-after-free it changed from exit to a reboot.

Is this intended? User was relying on the previous behaviour.

Comment 2 Daniel Juarez 2020-11-02 10:04:13 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

Comment 4 Daniel Juarez 2021-03-17 15:06:00 UTC
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.

Comment 7 Daniel Juarez 2021-08-31 12:31:52 UTC
No news?

Comment 30 Marta Lewandowska 2022-04-05 13:50:14 UTC
@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!

Comment 31 Daniel Juarez 2022-04-05 14:27:43 UTC
@mlewando We would also need access to the src rpm if possible. Thank you.

Comment 32 Petr Janda 2022-04-05 14:54:31 UTC
@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

Comment 33 Marta Lewandowska 2022-04-05 14:58:19 UTC
you can find the src rpm here: https://people.redhat.com/mlewando/grub2-2.02-0.87.el7_9.9.src.rpm

Comment 34 Daniel Juarez 2022-04-08 16:32:56 UTC
@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)

Comment 35 Marta Lewandowska 2022-04-11 13:42:38 UTC
@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...

Comment 36 Daniel Juarez 2022-04-11 14:06:25 UTC
@mlewando I can confirm that it behaves as expected when exiting, thanks.

Comment 37 Petr Janda 2022-04-11 17:37:06 UTC
(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

Comment 38 Daniel Juarez 2022-04-12 08:48:29 UTC
(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.

Comment 40 Petr Janda 2022-04-13 06:11:02 UTC
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.

Comment 45 errata-xmlrpc 2022-05-18 16:15:22 UTC
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

Comment 46 Red Hat Bugzilla 2023-09-15 01:31:09 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 365 days