Skip to contentSkip to conversation

broken ESC navigation if authentication is used

PATCH In review Florian Kaiser 3 participants 9 messages Jun 10, 2015 – Nov 12, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 broken ESC navigation if authentication is used

Hi,

we are using grub2 with authentication enabled and multiple submenus. Unfortunately it is not possible to return to a previous menu with ESC without triggering a superuser password prompt. This is not the desired behavior in my opinion.
I attached a patch to this email, which removes the password prompt when pressing escape.

Thank you very much in advance

Florian Kaiser
Microkernel Systems
tel +49 89 991950 - 0
[email protected]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
genua
Gesellschaft für Netzwerk - und Unix-Administration mbH Domagkstr. 7, D-85551 Kirchheim. http://www.genua.de
Tel: (089) 99 19 50-0, Fax: (089) 99 19 50 - 999

Geschäftsführer: Dr. Magnus Harlander, Dr. Michaela Harlander, Bernhard Schneck. Amtsgericht München HRB 98238
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From 1c4129d2f1751ae387fc5fd4073d70a3fa80f1e2 Mon Sep 17 00:00:00 2001
From: Florian Kaiser <[email protected]>
Date: Tue, 9 Jun 2015 19:01:03 +0200
Subject: [PATCH] grub: fix broken authorization behavior when pressing ESC

This change removes a superfluous authorization request, which prevented the user from navigating backwards through the menu tree using the ESC Key.

Change-Id: Ia4cd9ce45241e70758a6eeac4a2b33a9d73c0c6e

---
 contrib/grub2/grub-core/normal/menu.c |   25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)
contrib/grub2/grub-core/normal/menu.c +4 -21
index b47991a..27978a6 100644
@@ -886,27 +886,10 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
 grub_err_t
 grub_show_menu (grub_menu_t menu, int nested, int autoboot)
 {
-  grub_err_t err1, err2;
+  grub_err_t err;
 
-  while (1)
-    {
-      err1 = show_menu (menu, nested, autoboot);
-      autoboot = 0;
-      grub_print_error ();
-
-      if (grub_normal_exit_level)
-	break;
-
-      err2 = grub_auth_check_authentication (NULL);
-      if (err2)
-	{
-	  grub_print_error ();
-	  grub_errno = GRUB_ERR_NONE;
-	  continue;
-	}
-
-      break;
-    }
+  err = show_menu (menu, nested, autoboot);
+  grub_print_error ();
 
-  return err1;
+  return err;
 }
Signature · 1 line
1.7.10.4
#1 lore raw

Please fix mime type. I can't view your attachment on the phone

Quoted 39 lines · Florian Kaiser

Hi,

we are using grub2 with authentication enabled and multiple submenus. Unfortunately it is not possible to return to a previous menu with ESC without
triggering a superuser password prompt. This is not the desired behavior in my opinion.
I attached a patch to this email, which removes the password prompt when pressing escape.

Thank you very much in advance

Florian Kaiser
Microkernel Systems
tel +49 89 991950 - 0
[email protected]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
genua
Gesellschaft für Netzwerk - und Unix-Administration mbH Domagkstr. 7, D-85551 Kirchheim. http://www.genua.de
Tel: (089) 99 19 50-0, Fax: (089) 99 19 50 - 999

Geschäftsführer: Dr. Magnus Harlander, Dr. Michaela Harlander, Bernhard Schneck. Amtsgericht München HRB 98238
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
In reply to Florian Kaiser

В Wed, 10 Jun 2015 18:29:59 +0200
Florian Kaiser <[email protected]> пишет:

Quoted 9 lines

Hi,

we are using grub2 with authentication enabled and multiple submenus. Unfortunately it is not possible to return to a previous menu with ESC without triggering a superuser password prompt. This is not the desired behavior in my opinion.
I attached a patch to this email, which removes the password prompt when pressing escape.

Looks OK; I'm not sure why this was needed in the first place - it does not look like it is even possible to exit primary menu.

Vladimir, OK to commit?

#3 lore raw

This patch may allow to escape to shell if menu was called from context without menu entries. This may happen inadvertently I.a. when using configfile. You need to add an additional parameter to indicate whether it's OK to break from menu

Quoted 25 lines · Andrei Borzenkov

В Wed, 10 Jun 2015 18:29:59 +0200
Florian Kaiser <[email protected]> пишет:

Quoted 4 lines

Hi,

we are using grub2 with authentication enabled and multiple submenus. Unfortunately it is not possible to return to a previous menu with ESC

without

Quoted 1 line

triggering a superuser password prompt. This is not the desired behavior

in

Quoted 4 lines

my opinion.
I attached a patch to this email, which removes the password prompt when pressing escape.

Looks OK; I'm not sure why this was needed in the first place - it does not look like it is even possible to exit primary menu.

Vladimir, OK to commit?

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw

В Wed, 10 Jun 2015 21:35:51 +0200
"Vladimir 'phcoder' Serbinenko" <[email protected]> пишет:

Quoted 4 lines

This patch may allow to escape to shell if menu was called from context without menu entries. This may happen inadvertently I.a. when using configfile. You need to add an additional parameter to indicate whether it's OK to break from menu

Could you explain? Grub does

grub_enter_normal
grub_normal_execute
grub_show_menu
grub_cmdline_run

if after processing config file there are no menu entries we do not even call grub_show_menu. And even if we do, after return from it there is mandatory authentication in grub_cmdline_run.

I see how it could happen in original commit when authentication was added, but I miss code path that cause it now.

Quoted 27 lines · Andrei Borzenkov
Quoted 26 lines

В Wed, 10 Jun 2015 18:29:59 +0200
Florian Kaiser <[email protected]> пишет:

Quoted 4 lines

Hi,

we are using grub2 with authentication enabled and multiple submenus. Unfortunately it is not possible to return to a previous menu with ESC

without

Quoted 1 line

triggering a superuser password prompt. This is not the desired behavior

in

Quoted 4 lines

my opinion.
I attached a patch to this email, which removes the password prompt when pressing escape.

Looks OK; I'm not sure why this was needed in the first place - it does not look like it is even possible to exit primary menu.

Vladimir, OK to commit?

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw
Quoted 10 lines · Andrei Borzenkov

В Wed, 10 Jun 2015 21:35:51 +0200
"Vladimir 'phcoder' Serbinenko" <[email protected]> пишет:

Quoted 4 lines

This patch may allow to escape to shell if menu was called from context without menu entries. This may happen inadvertently I.a. when using configfile. You need to add an additional parameter to indicate whether it's OK to break from menu

Could you explain? Grub does

Quoted 9 lines

grub_enter_normal
grub_normal_execute
grub_show_menu
grub_cmdline_run

if after processing config file there are no menu entries we do not even call grub_show_menu. And even if we do, after return from it there is mandatory authentication in grub_cmdline_run.

Imagine something like following:
grub.cfg:
# Use another config file
configfile grub2.cfg
grub2.cfg:
superusers=root
....
Then pressing escape would lead you to the parent context where there is no password protection.
Question is whether this is a misconfiguration on grub.cfg side (i.a. should have been source, not configfile) or something to deal on code side.

Quoted 37 lines

I see how it could happen in original commit when authentication was added, but I miss code path that cause it now.

Quoted 20 lines · Andrei Borzenkov
Quoted 19 lines

В Wed, 10 Jun 2015 18:29:59 +0200
Florian Kaiser <[email protected]> пишет:

Quoted 4 lines

Hi,

we are using grub2 with authentication enabled and multiple submenus. Unfortunately it is not possible to return to a previous menu with ESC

without

Quoted 1 line

triggering a superuser password prompt. This is not the desired behavior

in

Quoted 4 lines

my opinion.
I attached a patch to this email, which removes the password prompt when pressing escape.

Looks OK; I'm not sure why this was needed in the first place - it does not look like it is even possible to exit primary menu.

Quoted 7 lines
Quoted 7 lines

Vladimir, OK to commit?

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#6 lore raw
Quoted 20 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Quoted 10 lines · Andrei Borzenkov

В Wed, 10 Jun 2015 21:35:51 +0200
"Vladimir 'phcoder' Serbinenko" <[email protected]> пишет:

Quoted 4 lines

This patch may allow to escape to shell if menu was called from context without menu entries. This may happen inadvertently I.a. when using configfile. You need to add an additional parameter to indicate whether it's OK to break from menu

Could you explain? Grub does

Quoted 9 lines

grub_enter_normal
grub_normal_execute
grub_show_menu
grub_cmdline_run

if after processing config file there are no menu entries we do not even call grub_show_menu. And even if we do, after return from it there is mandatory authentication in grub_cmdline_run.

Quoted 11 lines

Imagine something like following:
grub.cfg:
# Use another config file
configfile grub2.cfg
grub2.cfg:
superusers=root
....
Then pressing escape would lead you to the parent context where there is no password protection.
Question is whether this is a misconfiguration on grub.cfg side (i.a. should have been source, not configfile) or something to deal on code side.

We already have "nested" argument. We probably can convert this into enum or bit field to differentiate between new scope (normal/configfile) or submenu. Does it sound sane?

Quoted 25 lines
Quoted 25 lines

I see how it could happen in original commit when authentication was added, but I miss code path that cause it now.

Quoted 22 lines · Andrei Borzenkov
Quoted 21 lines

В Wed, 10 Jun 2015 18:29:59 +0200
Florian Kaiser <[email protected]> пишет:

Quoted 4 lines

Hi,

we are using grub2 with authentication enabled and multiple submenus. Unfortunately it is not possible to return to a previous menu with ESC

without

Quoted 1 line

triggering a superuser password prompt. This is not the desired behavior

in

Quoted 4 lines

my opinion.
I attached a patch to this email, which removes the password prompt when pressing escape.

Looks OK; I'm not sure why this was needed in the first place - it does not look like it is even possible to exit primary menu.

Vladimir, OK to commit?

#7 lore raw
In reply to Vladimir 'φ-coder/phcoder' Serbinenko

08.11.2015 23:55, Vladimir 'φ-coder/phcoder' Serbinenko пишет:

Quoted 20 lines · Andrei Borzenkov
Quoted 10 lines

В Wed, 10 Jun 2015 21:35:51 +0200
"Vladimir 'phcoder' Serbinenko" <[email protected]> пишет:

Quoted 4 lines

This patch may allow to escape to shell if menu was called from context without menu entries. This may happen inadvertently I.a. when using configfile. You need to add an additional parameter to indicate whether it's OK to break from menu

Could you explain? Grub does

Quoted 9 lines

grub_enter_normal
grub_normal_execute
grub_show_menu
grub_cmdline_run

if after processing config file there are no menu entries we do not even call grub_show_menu. And even if we do, after return from it there is mandatory authentication in grub_cmdline_run.

Quoted 11 lines

Imagine something like following:
grub.cfg:
# Use another config file
configfile grub2.cfg
grub2.cfg:
superusers=root
....
Then pressing escape would lead you to the parent context where there is no password protection.
Question is whether this is a misconfiguration on grub.cfg side (i.a. should have been source, not configfile) or something to deal on code side.

OK what about attached patch? it moves authentication where it belongs - to return from nested configfile.

From: Andrei Borzenkov <[email protected]>
Subject: [PATCH] normal: allow return from submenu without authentication

This change removes a superfluous authorization request, which prevented the user from navigating backwards through the menu tree using the ESC Key.

To preserve current semantic, require authentication when returning from menu in nested configfile.

Based on patch suggested by Florian Kaiser <[email protected]>

---
 grub-core/normal/main.c | 21 ++++++++++++++++++---
 grub-core/normal/menu.c | 34 ++--------------------------------
 include/grub/normal.h   |  2 +-
 3 files changed, 21 insertions(+), 36 deletions(-)
grub-core/normal/main.c +18 -3
index 78a70a8..dc675ae 100644
@@ -287,9 +287,24 @@ grub_normal_execute (const char *config, int nested, int batch)
 	{
 
 	  grub_boot_time ("Entering menu");
-	  grub_show_menu (menu, nested, 0);
-	  if (nested)
-	    grub_normal_free_menu (menu);
+	  while (1)
+	    {
+	      grub_show_menu (menu, nested, 0);
+	      if (grub_normal_exit_level)
+		break;
+	      if (nested)
+		{
+		  if (grub_auth_check_authentication (NULL))
+		    {
+		      grub_print_error ();
+		      grub_errno = GRUB_ERR_NONE;
+		      grub_wait_after_message ();
+		      continue;
+		    }
+		  grub_normal_free_menu (menu);
+		  break;
+		}
+	    }
 	}
     }
 }
grub-core/normal/menu.c +2 -32
index 719e2fb..d93c19e 100644
@@ -852,8 +852,8 @@ static struct grub_menu_execute_callback execution_callback =
   .notify_failure = notify_execution_failure
 };
 
-static grub_err_t
-show_menu (grub_menu_t menu, int nested, int autobooted)
+void
+grub_show_menu (grub_menu_t menu, int nested, int autobooted)
 {
   while (1)
     {
@@ -879,34 +879,4 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
       if (autobooted)
 	break;
     }
-
-  return GRUB_ERR_NONE;
-}
-
-grub_err_t
-grub_show_menu (grub_menu_t menu, int nested, int autoboot)
-{
-  grub_err_t err1, err2;
-
-  while (1)
-    {
-      err1 = show_menu (menu, nested, autoboot);
-      autoboot = 0;
-      grub_print_error ();
-
-      if (grub_normal_exit_level)
-	break;
-
-      err2 = grub_auth_check_authentication (NULL);
-      if (err2)
-	{
-	  grub_print_error ();
-	  grub_errno = GRUB_ERR_NONE;
-	  continue;
-	}
-
-      break;
-    }
-
-  return err1;
 }
include/grub/normal.h +1 -1
index 218cbab..ae2e0dd 100644
@@ -112,7 +112,7 @@ void grub_print_message_indented (const char *msg, int margin_left,
 				  struct grub_term_output *term);
 void
 grub_menu_text_register_instances (int entry, grub_menu_t menu, int nested);
-grub_err_t
+void
 grub_show_menu (grub_menu_t menu, int nested, int autobooted);
 
 /* Defined in `handler.c'.  */
Signature · 1 line
tg: (c899d9f..) u/submenu-without-authentication (depends on: master)
#8 lore raw

Escape to CLI (was: Re: [PATCH] broken ESC navigation if authentication is used)

In reply to Florian Kaiser

10.06.2015 19:29, Florian Kaiser пишет:

Quoted 9 lines

Hi,

we are using grub2 with authentication enabled and multiple submenus. Unfortunately it is not possible to return to a previous menu with ESC without triggering a superuser password prompt. This is not the desired behavior in my opinion.
I attached a patch to this email, which removes the password prompt when pressing escape.

Actually I could not even reproduce it at first. The problem is, new submenu opens new context and unless `superusers' is exported as soon as we enter submenu no authentication is required at all (including entering CLI).

I am not sure whether this is intentional, but this is definitely unexpected. And due to complete lack of description of variable scoping in GRUB it is also undocumented.

Options are

- simply document variable scoping and mention it in authentication description

- propagate superusers to submenus, rely on normal export in nested config. Still needs documentation what export actually does.

- export superusers by default and document it in description.