resuce: allow disabling of the grub resuce shell
PATCH 1/1 resuce: allow disabling of the grub resuce shell
From: Andreas Rammhold <[email protected]>
Kindly requesting your feedback on the below diff.
In some setups it might be desirable to disable access to the grub rescue shell. One of those environments is when your all your filesystems - besides a small EFI partition - are encrypted and you are using secure boot to restrict the payloads that UEFI accepts.
The current implementation adds a new variable to the embedded configuration sections. If the variable is present and starts with a 'y'-character the option is considered to be active. Upon entering the rescue shell it will just spin in circles (while(1);) if the said option is active. If the option is not set or set to a value that does not start with a 'y' the old behaviour is unchanged.
I hacked this together very quickly and do not consider it fit for merging yet. I would at least want a way to tell grub-install to toggle the new environment variable. And it probably requires some kind of documentation.
--- grub-core/kern/rescue_reader.c | 34 +++++++++++++++++++++++----------- util/grub-install.c | 1 + 2 files changed, 24 insertions(+), 11 deletions(-)
grub-core/kern/rescue_reader.c +23 -11
@@ -78,21 +78,33 @@ grub_rescue_read_line (char **line, int cont,void __attribute__ ((noreturn))grub_rescue_run (void ) { -grub_printf ("Entering rescue mode...\n" ); +const char *disable_rescue_mode; -while (1 ) + disable_rescue_mode =grub_env_get ("disable_rescue_mode" ); + +if (!disable_rescue_mode || disable_rescue_mode[0 ] !='y' ) { -char *line; +grub_printf ("Entering rescue mode...\n" ); + +while (1 ) + { +char *line; -/* Print an error, if any. */ -grub_print_error (); - grub_errno =GRUB_ERR_NONE ; +/* Print an error, if any. */ +grub_print_error (); + grub_errno =GRUB_ERR_NONE ; -grub_rescue_read_line (&line,0 ,NULL ); -if (! line || line[0 ] =='\0' ) -continue ; +grub_rescue_read_line (&line,0 ,NULL ); +if (! line || line[0 ] =='\0' ) +continue ; -grub_rescue_parse_line (line, grub_rescue_read_line,NULL ); -grub_free (line); +grub_rescue_parse_line (line, grub_rescue_read_line,NULL ); +grub_free (line); + } + } +else + { +grub_printf ("Not entering rescue mode.\n" ); +while (1 ); } }
util/grub-install.c +1 -0
@@ -530,6 +530,7 @@ probe_cryptodisk_uuid (grub_disk_t disk) load_cfg_f =grub_util_fopen (load_cfg,"wb" ); have_load_cfg =1 ; +fprintf (load_cfg_f,"set disable_rescue_mode=yes\n" );fprintf (load_cfg_f,"cryptomount -u %s\n" , uuid); }
Signature · 1 line
2.21.0
Quoted 8 lines · On Thu, May 02, 2019 at 12:06:56AM +0200, [email protected] wrote:
From: Andreas Rammhold <[email protected]>
Kindly requesting your feedback on the below diff.
In some setups it might be desirable to disable access to the grub rescue shell. One of those environments is when your all your filesystems - besides a small EFI partition - are encrypted and you are using secure boot to restrict the payloads that UEFI accepts.
I am OK with the idea but the patch requires polishing and maybe splitting into two or more. And certainly it is not a release material.
Daniel
Quoted 2 lines · Daniel Kiper
I am OK with the idea but the patch requires polishing and maybe splitting into two or more. And certainly it is not a release material.
Thanks for the feedback. Do you have some specific points that you would like to see addressed? I certainly want the mentioned command line switches to opt-in to the feature and write the documentation pieces.
Andi
Quoted 6 lines · On Sat, May 11, 2019 at 08:41:20PM +0200, [email protected] wrote:
Quoted 2 lines · Daniel Kiper
I am OK with the idea but the patch requires polishing and maybe splitting into two or more. And certainly it is not a release material.
Thanks for the feedback. Do you have some specific points that you would like to see addressed? I certainly want the mentioned command line
Nothing in particular. Just the patch seems to simple for me... OK, this is an RFC, so, maybe that is a problem. Anyway, please post full version and then I will take a closer look.
Quoted 1 line
switches to opt-in to the feature and write the documentation pieces.
Yeah, that is good idea.
Daniel