[PATCH] efi: mm: Fix incorrect free size
From: Zhou JianFeng Memory freed by function grub_efi_free_pages() with wrong pages will not be removed from list efi_allocated_memory by function grub_efi_drop_alloc(), it will be freed again by function grub_efi_memory_fini() which is called by function grub_machine_fini()/grub_exit() when exit grub. Freeing memory twice may lead to unpredictable result. Cc: daniel.ki...@oracle.com Cc: alexander.burmas...@oracle.com Cc: phco...@gmail.com Signed-off-by: Zhou JianFeng --- grub-core/kern/efi/mm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 6a6fba891..49daa976f 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -643,7 +643,7 @@ grub_efi_mm_add_regions (grub_size_t required_bytes, unsigned int flags) /* Release the memory maps. */ grub_efi_free_pages ((grub_addr_t) memory_map, - 2 * BYTES_TO_PAGES (MEMORY_MAP_SIZE)); + 2 * BYTES_TO_PAGES (map_size)); return GRUB_ERR_NONE; } -- 2.25.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2] cryptodisk: allow the user to retry failed passphrases
On Mon, Apr 22, 2024 at 1:48 PM Forest wrote: > On Sun, 07 Apr 2024 14:52:32 -0700, Forest wrote: > > >Changes since last rev: > >- replace some spaces with tabs > >- better explain the clearing of grub_errno > >- let an environment variable override the number of passphrase tries > > As a new contributor, is there something I should do to ensure my patch > isn't overlooked? I'm not sure what the development cadence here is like, > and since new patches to the same code have arrived in the weeks since I > submitted this one, I'm starting to worry that I might have to start all > over again on a new code base. > > As another new contributor, I'm also curious about this. I've been waiting since january & febuary, for any update on my patch, though Patrick ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v2] cryptodisk: allow the user to retry failed passphrases
On Sun, 07 Apr 2024 14:52:32 -0700, Forest wrote: >Changes since last rev: >- replace some spaces with tabs >- better explain the clearing of grub_errno >- let an environment variable override the number of passphrase tries As a new contributor, is there something I should do to ensure my patch isn't overlooked? I'm not sure what the development cadence here is like, and since new patches to the same code have arrived in the weeks since I submitted this one, I'm starting to worry that I might have to start all over again on a new code base. ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 1/2] Allow "fallback" to include entries by title, not just number.
Selecting by title is deprecated and kept only for compatibility. Please use id instead Le lun. 22 avr. 2024, 17:56, Marek Marczykowski-Górecki < marma...@invisiblethingslab.com> a écrit : > From: Peter Jones > > Resolves: rhbz#1026084 > > Signed-off-by: Peter Jones > --- > grub-core/normal/menu.c | 85 -- > 1 file changed, 58 insertions(+), 27 deletions(-) > > diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c > index 6a90e09..6444ee6 100644 > --- a/grub-core/normal/menu.c > +++ b/grub-core/normal/menu.c > @@ -163,15 +163,40 @@ grub_menu_set_timeout (int timeout) > } > } > > +static int > +menuentry_eq (const char *id, const char *spec) > +{ > + const char *ptr1, *ptr2; > + ptr1 = id; > + ptr2 = spec; > + while (1) > +{ > + if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) > + return ptr2 - spec; > + if (*ptr2 == '>' && ptr2[1] != '>') > + return 0; > + if (*ptr2 == '>') > + ptr2++; > + if (*ptr1 != *ptr2) > + return 0; > + if (*ptr1 == 0) > + return ptr1 - id; > + ptr1++; > + ptr2++; > +} > + return 0; > +} > + > /* Get the first entry number from the value of the environment variable > NAME, > which is a space-separated list of non-negative integers. The entry > number > which is returned is stripped from the value of NAME. If no entry > number > can be found, -1 is returned. */ > static int > -get_and_remove_first_entry_number (const char *name) > +get_and_remove_first_entry_number (grub_menu_t menu, const char *name) > { >const char *val, *tail; >int entry; > + int sz = 0; > >val = grub_env_get (name); >if (! val) > @@ -181,9 +206,39 @@ get_and_remove_first_entry_number (const char *name) > >entry = (int) grub_strtoul (val, , 0); > > + if (grub_errno == GRUB_ERR_BAD_NUMBER) > +{ > + /* See if the variable matches the title of a menu entry. */ > + grub_menu_entry_t e = menu->entry_list; > + int i; > + > + for (i = 0; e; i++) > + { > + sz = menuentry_eq (e->title, val); > + if (sz < 1) > + sz = menuentry_eq (e->id, val); > + > + if (sz >= 1) > + { > + entry = i; > + break; > + } > + e = e->next; > + } > + > + if (sz > 0) > + grub_errno = GRUB_ERR_NONE; > + > + if (! e) > + entry = -1; > +} > + >if (grub_errno == GRUB_ERR_NONE) > { > - /* Skip whitespace to find the next digit. */ > + if (sz > 0) > + tail += sz; > + > + /* Skip whitespace to find the next entry. */ >while (*tail && grub_isspace (*tail)) > tail++; >grub_env_set (name, tail); > @@ -346,7 +401,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu, >grub_menu_execute_entry (entry, 1); > >/* Deal with fallback entries. */ > - while ((fallback_entry = get_and_remove_first_entry_number ("fallback")) > + while ((fallback_entry = get_and_remove_first_entry_number (menu, > "fallback")) > >= 0) > { >grub_print_error (); > @@ -464,30 +519,6 @@ grub_menu_register_viewer (struct grub_menu_viewer > *viewer) >viewers = viewer; > } > > -static int > -menuentry_eq (const char *id, const char *spec) > -{ > - const char *ptr1, *ptr2; > - ptr1 = id; > - ptr2 = spec; > - while (1) > -{ > - if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) > - return 1; > - if (*ptr2 == '>' && ptr2[1] != '>') > - return 0; > - if (*ptr2 == '>') > - ptr2++; > - if (*ptr1 != *ptr2) > - return 0; > - if (*ptr1 == 0) > - return 1; > - ptr1++; > - ptr2++; > -} > -} > - > - > /* Get the entry number from the variable NAME. */ > static int > get_entry_number (grub_menu_t menu, const char *name) > -- > git-series 0.9.1 > > ___ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel > ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/2] Fix menu entry selection based on ID and title
I'm unsure whether an id starting with a numeral should be considered valid at all. Variable named 0x would be incorrect Le lun. 22 avr. 2024, 17:57, Marek Marczykowski-Górecki < marma...@invisiblethingslab.com> a écrit : > From: Peter Jones > > Currently if grub_strtoul(saved_entry_value, NULL, 0) does not return an > error, we assume the value it has produced is a correct index into our > menu entry list, and do not try to interpret the value as the "id" or > "title" . In cases where "id" or "title" start with a numeral, this > makes them impossible to use as selection criteria. > > This patch splits the search into three phases - matching id, matching > title, and only once those have been exhausted, trying to interpret the > ID as a numeral. In that case, we also require that the entire string > is numeric, not merely a string with leading numeric characters. > > Resolves: rhbz#1640979 > > Signed-off-by: Peter Jones > [javierm: fix menu entry selection based on title] > Signed-off-by: Javier Martinez Canillas > --- > grub-core/normal/menu.c | 141 - > 1 file changed, 71 insertions(+), 70 deletions(-) > > diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c > index 6444ee6..b0cfa32 100644 > --- a/grub-core/normal/menu.c > +++ b/grub-core/normal/menu.c > @@ -164,12 +164,12 @@ grub_menu_set_timeout (int timeout) > } > > static int > -menuentry_eq (const char *id, const char *spec) > +menuentry_eq (const char *id, const char *spec, int limit) > { >const char *ptr1, *ptr2; >ptr1 = id; >ptr2 = spec; > - while (1) > + while (limit == -1 || ptr1 - id <= limit) > { >if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) > return ptr2 - spec; > @@ -178,7 +178,11 @@ menuentry_eq (const char *id, const char *spec) >if (*ptr2 == '>') > ptr2++; >if (*ptr1 != *ptr2) > - return 0; > + { > + if (limit > -1 && ptr1 - id == limit && !*ptr1 && > grub_isspace(*ptr2)) > + return ptr1 -id -1; > + return 0; > + } >if (*ptr1 == 0) > return ptr1 - id; >ptr1++; > @@ -187,6 +191,58 @@ menuentry_eq (const char *id, const char *spec) >return 0; > } > > +static int > +get_entry_number_helper(grub_menu_t menu, > + const char * const val, const char ** const tail) > +{ > + /* See if the variable matches the title of a menu entry. */ > + int entry = -1; > + grub_menu_entry_t e; > + int i; > + > + for (i = 0, e = menu->entry_list; e; i++) > +{ > + int l = 0; > + while (val[l] && !grub_isspace(val[l])) > + l++; > + > + if (menuentry_eq (e->id, val, l)) > + { > + if (tail) > + *tail = val + l; > + return i; > + } > + e = e->next; > +} > + > + for (i = 0, e = menu->entry_list; e; i++) > +{ > + > + if (menuentry_eq (e->title, val, -1)) > + { > + if (tail) > + *tail = NULL; > + return i; > + } > + e = e->next; > +} > + > + if (tail) > +*tail = NULL; > + > + entry = (int) grub_strtoul (val, tail, 0); > + if (grub_errno == GRUB_ERR_BAD_NUMBER || > + (*tail && **tail && !grub_isspace(**tail))) > +{ > + entry = -1; > + if (tail) > + *tail = NULL; > + grub_errno = GRUB_ERR_NONE; > +} > + > + return entry; > +} > + > /* Get the first entry number from the value of the environment variable > NAME, > which is a space-separated list of non-negative integers. The entry > number > which is returned is stripped from the value of NAME. If no entry > number > @@ -196,7 +252,6 @@ get_and_remove_first_entry_number (grub_menu_t menu, > const char *name) > { >const char *val, *tail; >int entry; > - int sz = 0; > >val = grub_env_get (name); >if (! val) > @@ -204,50 +259,24 @@ get_and_remove_first_entry_number (grub_menu_t menu, > const char *name) > >grub_error_push (); > > - entry = (int) grub_strtoul (val, , 0); > - > - if (grub_errno == GRUB_ERR_BAD_NUMBER) > -{ > - /* See if the variable matches the title of a menu entry. */ > - grub_menu_entry_t e = menu->entry_list; > - int i; > - > - for (i = 0; e; i++) > - { > - sz = menuentry_eq (e->title, val); > - if (sz < 1) > - sz = menuentry_eq (e->id, val); > - > - if (sz >= 1) > - { > - entry = i; > - break; > - } > - e = e->next; > - } > + entry = get_entry_number_helper(menu, val, ); > + if (!(*tail == 0 || grub_isspace(*tail))) > +entry = -1; > > - if (sz > 0) > - grub_errno = GRUB_ERR_NONE; > - > - if (! e) > - entry = -1; > -} > - > - if (grub_errno == GRUB_ERR_NONE) > + if (entry >= 0) > { > - if (sz > 0) > - tail += sz; > - >/* Skip whitespace to find the next entry. */ >while (*tail && grub_isspace
[PATCH 2/2] Fix menu entry selection based on ID and title
From: Peter Jones Currently if grub_strtoul(saved_entry_value, NULL, 0) does not return an error, we assume the value it has produced is a correct index into our menu entry list, and do not try to interpret the value as the "id" or "title" . In cases where "id" or "title" start with a numeral, this makes them impossible to use as selection criteria. This patch splits the search into three phases - matching id, matching title, and only once those have been exhausted, trying to interpret the ID as a numeral. In that case, we also require that the entire string is numeric, not merely a string with leading numeric characters. Resolves: rhbz#1640979 Signed-off-by: Peter Jones [javierm: fix menu entry selection based on title] Signed-off-by: Javier Martinez Canillas --- grub-core/normal/menu.c | 141 - 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index 6444ee6..b0cfa32 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -164,12 +164,12 @@ grub_menu_set_timeout (int timeout) } static int -menuentry_eq (const char *id, const char *spec) +menuentry_eq (const char *id, const char *spec, int limit) { const char *ptr1, *ptr2; ptr1 = id; ptr2 = spec; - while (1) + while (limit == -1 || ptr1 - id <= limit) { if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) return ptr2 - spec; @@ -178,7 +178,11 @@ menuentry_eq (const char *id, const char *spec) if (*ptr2 == '>') ptr2++; if (*ptr1 != *ptr2) - return 0; + { + if (limit > -1 && ptr1 - id == limit && !*ptr1 && grub_isspace(*ptr2)) + return ptr1 -id -1; + return 0; + } if (*ptr1 == 0) return ptr1 - id; ptr1++; @@ -187,6 +191,58 @@ menuentry_eq (const char *id, const char *spec) return 0; } +static int +get_entry_number_helper(grub_menu_t menu, + const char * const val, const char ** const tail) +{ + /* See if the variable matches the title of a menu entry. */ + int entry = -1; + grub_menu_entry_t e; + int i; + + for (i = 0, e = menu->entry_list; e; i++) +{ + int l = 0; + while (val[l] && !grub_isspace(val[l])) + l++; + + if (menuentry_eq (e->id, val, l)) + { + if (tail) + *tail = val + l; + return i; + } + e = e->next; +} + + for (i = 0, e = menu->entry_list; e; i++) +{ + + if (menuentry_eq (e->title, val, -1)) + { + if (tail) + *tail = NULL; + return i; + } + e = e->next; +} + + if (tail) +*tail = NULL; + + entry = (int) grub_strtoul (val, tail, 0); + if (grub_errno == GRUB_ERR_BAD_NUMBER || + (*tail && **tail && !grub_isspace(**tail))) +{ + entry = -1; + if (tail) + *tail = NULL; + grub_errno = GRUB_ERR_NONE; +} + + return entry; +} + /* Get the first entry number from the value of the environment variable NAME, which is a space-separated list of non-negative integers. The entry number which is returned is stripped from the value of NAME. If no entry number @@ -196,7 +252,6 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) { const char *val, *tail; int entry; - int sz = 0; val = grub_env_get (name); if (! val) @@ -204,50 +259,24 @@ get_and_remove_first_entry_number (grub_menu_t menu, const char *name) grub_error_push (); - entry = (int) grub_strtoul (val, , 0); - - if (grub_errno == GRUB_ERR_BAD_NUMBER) -{ - /* See if the variable matches the title of a menu entry. */ - grub_menu_entry_t e = menu->entry_list; - int i; - - for (i = 0; e; i++) - { - sz = menuentry_eq (e->title, val); - if (sz < 1) - sz = menuentry_eq (e->id, val); - - if (sz >= 1) - { - entry = i; - break; - } - e = e->next; - } + entry = get_entry_number_helper(menu, val, ); + if (!(*tail == 0 || grub_isspace(*tail))) +entry = -1; - if (sz > 0) - grub_errno = GRUB_ERR_NONE; - - if (! e) - entry = -1; -} - - if (grub_errno == GRUB_ERR_NONE) + if (entry >= 0) { - if (sz > 0) - tail += sz; - /* Skip whitespace to find the next entry. */ while (*tail && grub_isspace (*tail)) tail++; - grub_env_set (name, tail); + if (*tail) + grub_env_set (name, tail); + else + grub_env_unset (name); } else { grub_env_unset (name); grub_errno = GRUB_ERR_NONE; - entry = -1; } grub_error_pop (); @@ -524,6 +553,7 @@ static int get_entry_number (grub_menu_t menu, const char *name) { const char *val; + const char *tail; int entry; val = grub_env_get (name); @@ -531,38 +561,9 @@ get_entry_number (grub_menu_t menu, const char *name)
[PATCH 0/2] Two patches related to menu entries selection
Those are two patches from Fedora's grub package that are related to menu titles handling. I hope submiting them this way is okay and will help bringing Fedora and upstream grub versions together. See individual commit messages for details. Peter Jones (2): Allow "fallback" to include entries by title, not just number. Fix menu entry selection based on ID and title grub-core/normal/menu.c | 158 - 1 file changed, 95 insertions(+), 63 deletions(-) base-commit: 8719cc2040368d43ab2de0b6e1b850b2c9cfc5b7 -- git-series 0.9.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH 1/2] Allow "fallback" to include entries by title, not just number.
From: Peter Jones Resolves: rhbz#1026084 Signed-off-by: Peter Jones --- grub-core/normal/menu.c | 85 -- 1 file changed, 58 insertions(+), 27 deletions(-) diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c index 6a90e09..6444ee6 100644 --- a/grub-core/normal/menu.c +++ b/grub-core/normal/menu.c @@ -163,15 +163,40 @@ grub_menu_set_timeout (int timeout) } } +static int +menuentry_eq (const char *id, const char *spec) +{ + const char *ptr1, *ptr2; + ptr1 = id; + ptr2 = spec; + while (1) +{ + if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) + return ptr2 - spec; + if (*ptr2 == '>' && ptr2[1] != '>') + return 0; + if (*ptr2 == '>') + ptr2++; + if (*ptr1 != *ptr2) + return 0; + if (*ptr1 == 0) + return ptr1 - id; + ptr1++; + ptr2++; +} + return 0; +} + /* Get the first entry number from the value of the environment variable NAME, which is a space-separated list of non-negative integers. The entry number which is returned is stripped from the value of NAME. If no entry number can be found, -1 is returned. */ static int -get_and_remove_first_entry_number (const char *name) +get_and_remove_first_entry_number (grub_menu_t menu, const char *name) { const char *val, *tail; int entry; + int sz = 0; val = grub_env_get (name); if (! val) @@ -181,9 +206,39 @@ get_and_remove_first_entry_number (const char *name) entry = (int) grub_strtoul (val, , 0); + if (grub_errno == GRUB_ERR_BAD_NUMBER) +{ + /* See if the variable matches the title of a menu entry. */ + grub_menu_entry_t e = menu->entry_list; + int i; + + for (i = 0; e; i++) + { + sz = menuentry_eq (e->title, val); + if (sz < 1) + sz = menuentry_eq (e->id, val); + + if (sz >= 1) + { + entry = i; + break; + } + e = e->next; + } + + if (sz > 0) + grub_errno = GRUB_ERR_NONE; + + if (! e) + entry = -1; +} + if (grub_errno == GRUB_ERR_NONE) { - /* Skip whitespace to find the next digit. */ + if (sz > 0) + tail += sz; + + /* Skip whitespace to find the next entry. */ while (*tail && grub_isspace (*tail)) tail++; grub_env_set (name, tail); @@ -346,7 +401,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu, grub_menu_execute_entry (entry, 1); /* Deal with fallback entries. */ - while ((fallback_entry = get_and_remove_first_entry_number ("fallback")) + while ((fallback_entry = get_and_remove_first_entry_number (menu, "fallback")) >= 0) { grub_print_error (); @@ -464,30 +519,6 @@ grub_menu_register_viewer (struct grub_menu_viewer *viewer) viewers = viewer; } -static int -menuentry_eq (const char *id, const char *spec) -{ - const char *ptr1, *ptr2; - ptr1 = id; - ptr2 = spec; - while (1) -{ - if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0) - return 1; - if (*ptr2 == '>' && ptr2[1] != '>') - return 0; - if (*ptr2 == '>') - ptr2++; - if (*ptr1 != *ptr2) - return 0; - if (*ptr1 == 0) - return 1; - ptr1++; - ptr2++; -} -} - - /* Get the entry number from the variable NAME. */ static int get_entry_number (grub_menu_t menu, const char *name) -- git-series 0.9.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel