Skip to content

Fix the fallback mechanism when menu entries fail to boot#195

Closed
chewi wants to merge 2 commits intorhboot:fedora-43from
chewi:execute-return-code
Closed

Fix the fallback mechanism when menu entries fail to boot#195
chewi wants to merge 2 commits intorhboot:fedora-43from
chewi:execute-return-code

Conversation

@chewi
Copy link
Copy Markdown
Contributor

@chewi chewi commented Oct 24, 2024

@martinezjavier's c3fcfe5 commit accidentally broke the fallback mechanism, although it also exposed another bug in upstream GRUB.

We cannot rely on grub_errno in grub_menu_execute_entry() because grub_script_execute_new_scope() calls grub_print_error(), which always resets grub_errno back to GRUB_ERR_NONE. It may also get reset by grub_wait_after_message().

grub_script_execute_sourcecode() parses and executes code one line at a time, updating the return code each time because only the last line determines the final status. However, trailing new lines were also executed, masking any failure on the previous line. Fix this by only trying to execute the command when there is actually one present. A new test case is included.

See the commit messages for further details.

I can send the first change upstream, although it's unlikely to cause issues without your change, hence why it went unnoticed for so long. I gather you are starting to upstream some of your changes, so perhaps I can leave it with you?

chewi added 2 commits March 21, 2025 11:15
grub_script_execute_sourcecode() parses and executes code one line at a
time, updating the return code each time because only the last line
determines the final status. However, trailing new lines were also
executed, masking any failure on the previous line. Fix this by only
trying to execute the command when there is actually one present.

This has presumably never been noticed because this code is not used by
regular functions, only in special cases like eval and menu entries. The
latter generally don't return at all, having booted an OS. When failing
to boot, upstream GRUB triggers the fallback mechanism regardless of the
return code.

We noticed the problem while using Red Hat's patches, which change this
behaviour to take account of the return code. In that case, a failure
takes you back to the menu rather than triggering a fallback.

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
Don't rely on grub_errno here because grub_script_execute_new_scope()
calls grub_print_error(), which always resets grub_errno back to
GRUB_ERR_NONE. It may also get reset by grub_wait_after_message().

This problem was observed when a "bad signature" error resulted in the
menu being redisplayed rather than the fallback mechanism being
triggered, although another change was also needed to fix it. This only
happens with Red Hat's patches because upstream GRUB triggers the
fallback mechanism regardless of the return code.

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
@chewi chewi force-pushed the execute-return-code branch from 93eedb6 to fb595c3 Compare March 21, 2025 11:16
@chewi
Copy link
Copy Markdown
Contributor Author

chewi commented Mar 21, 2025

Rebased on fedora-43. Upstream has merged the first change now, but you don't have it yet.

@lsandov1
Copy link
Copy Markdown
Contributor

@chewi do you mind creating a patch but on the srpm fedora repository? Once patches land on that repo, we then sync this repository (manually at the moment)

srpm

@chewi
Copy link
Copy Markdown
Contributor Author

chewi commented Mar 24, 2025

Done. Hope I got that right.

@chewi chewi closed this Mar 24, 2025
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.

2 participants