Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hLyah-0005GA-88 for mharc-grub-devel@gnu.org; Wed, 01 May 2019 19:24:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLxOd-0001H1-I8 for grub-devel@gnu.org; Wed, 01 May 2019 18:08:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLxOb-0006RI-MS for grub-devel@gnu.org; Wed, 01 May 2019 18:08:11 -0400 Received: from mx.h4ck.space ([136.243.22.202]:39574 helo=mail.h4ck.space) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLxOZ-0006HZ-TC for grub-devel@gnu.org; Wed, 01 May 2019 18:08:09 -0400 Received: from localhost (p200300E53F0FF903C6DF402CEF5F7DBE.dip0.t-ipconnect.de [IPv6:2003:e5:3f0f:f903:c6df:402c:ef5f:7dbe]) by mail.h4ck.space (Postfix) with ESMTPSA id EABF738A89D; Wed, 1 May 2019 22:07:58 +0000 (UTC) From: andreas@rammhold.de To: grub-devel@gnu.org Cc: Andreas Rammhold Subject: [PATCH requesting feedback] resuce: allow disabling of the grub resuce shell Date: Thu, 2 May 2019 00:06:56 +0200 Message-Id: <20190501220656.19712-1-andreas@rammhold.de> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 136.243.22.202 X-Mailman-Approved-At: Wed, 01 May 2019 19:24:41 -0400 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 May 2019 22:08:12 -0000 From: Andreas Rammhold 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(-) diff --git a/grub-core/kern/rescue_reader.c b/grub-core/kern/rescue_reade= r.c index dcd7d4439..03a4e2852 100644 --- a/grub-core/kern/rescue_reader.c +++ b/grub-core/kern/rescue_reader.c @@ -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; =20 - while (1) + disable_rescue_mode =3D grub_env_get ("disable_rescue_mode"); + + if (!disable_rescue_mode || disable_rescue_mode[0] !=3D 'y') { - char *line; + grub_printf ("Entering rescue mode...\n"); + + while (1) + { + char *line; =20 - /* Print an error, if any. */ - grub_print_error (); - grub_errno =3D GRUB_ERR_NONE; + /* Print an error, if any. */ + grub_print_error (); + grub_errno =3D GRUB_ERR_NONE; =20 - grub_rescue_read_line (&line, 0, NULL); - if (! line || line[0] =3D=3D '\0') - continue; + grub_rescue_read_line (&line, 0, NULL); + if (! line || line[0] =3D=3D '\0') + continue; =20 - 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); } } diff --git a/util/grub-install.c b/util/grub-install.c index 4a0a66168..16eda74c3 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -530,6 +530,7 @@ probe_cryptodisk_uuid (grub_disk_t disk) load_cfg_f =3D grub_util_fopen (load_cfg, "wb"); have_load_cfg =3D 1; =20 + fprintf (load_cfg_f, "set disable_rescue_mode=3Dyes\n"); fprintf (load_cfg_f, "cryptomount -u %s\n", uuid); } --=20 2.21.0