Adjustments for EFI "linux" command and
v4 cover Adjustments for EFI "linux" command and
The series started from the issue that LoadOptions, if providing just command line arguments should be NUL-terminated.
But this carried some updates to adjust the code properly.
Changes since v3:
- use proper length converting args string;
- added Reviewed-by comments.
Frediano Ziglio (6):
loader/efi/linux: Remove useless assignment include/grub/charset.h: Update documentation loader/efi/linux: Do not pass excessive size for source string loader/efi/linux: Use proper type for "len" variable loader/efi/linux: Use sizeof instead of constant loader/efi/linux: Correctly terminate LoadOptions field
grub-core/loader/efi/linux.c | 15 +++++++++------ include/grub/charset.h | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-)
Signature · 7 lines
2.49.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v4 1/6 loader/efi/linux: Remove useless assignment
If the following allocation fails this would leave "load_options" NULL while "load_options_size" not valid.
If the allocation succeed "load_options_size" is overwritten.
--- grub-core/loader/efi/linux.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
grub-core/loader/efi/linux.c +1 -2
@@ -223,8 +223,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)grub_error (GRUB_ERR_BAD_FIRMWARE ,"missing loaded_image proto" ); goto unload; } - loaded_image->load_options_size = len = - (grub_strlen (args) +1 ) *sizeof (grub_efi_char16_t); + len = (grub_strlen (args) +1 ) *sizeof (grub_efi_char16_t); loaded_image->load_options =grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (len));if (!loaded_image->load_options)
Signature · 7 lines
2.49.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v4 2/6 include/grub/charset.h: Update documentation
In reply to Frediano Ziglio via Grub-devel(grub_size_t) -1 is never returned, the function always return a not negative values. This is important for overflows considerations.
--- include/grub/charset.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/grub/charset.h +2 -1
@@ -117,7 +117,8 @@ grub_utf8_process (grub_uint8_t c, grub_uint32_t *code, int *count)/* Convert a (possibly null-terminated) UTF-8 string of at most SRCSIZE bytes (if SRCSIZE is -1, it is ignored) in length to a UTF-16 string. Return the number of characters converted. DEST must be able to hold -at least DESTSIZE characters. If an invalid sequence is found, return -1. +at least DESTSIZE characters. If an invalid sequence is found, it is +replaced by a question mark ('?'). If SRCEND is not NULL, then *SRCEND is set to the next byte after the last byte used in SRC. */ static inline grub_size_t
Signature · 7 lines
2.49.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v4 3/6 loader/efi/linux: Do not pass excessive size for source string
In reply to Frediano Ziglio via Grub-develThe size passed to grub_utf8_to_utf16 for the source string is used as a limit for the string if NUL character is not encountered however len, which is strlen(src)*2+2 is surely greater than strlen(src).
Pass the exact correct length.
---
Changes since v3:
- pass exact size, not -1.
--- grub-core/loader/efi/linux.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
grub-core/loader/efi/linux.c +4 -2
@@ -191,6 +191,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)grub_efi_status_t status;grub_efi_loaded_image_t *loaded_image;int len; +grub_size_t args_len; mempath =grub_malloc (2 *sizeof (grub_efi_memory_mapped_device_path_t));if (!mempath)
@@ -223,7 +224,8 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)grub_error (GRUB_ERR_BAD_FIRMWARE ,"missing loaded_image proto" ); goto unload; } - len = (grub_strlen (args) +1 ) *sizeof (grub_efi_char16_t); + args_len =grub_strlen (args); + len = (args_len +1 ) *sizeof (grub_efi_char16_t); loaded_image->load_options =grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (len));if (!loaded_image->load_options)
@@ -231,7 +233,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) loaded_image->load_options_size =2 *grub_utf8_to_utf16 (loaded_image->load_options, len, - (grub_uint8_t *) args, len,NULL ); + (grub_uint8_t *) args, args_len,NULL );grub_dprintf ("linux" ,"starting image %p\n" , image_handle); status = b->start_image (image_handle,0 ,NULL );
Signature · 7 lines
2.49.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v4 4/6 loader/efi/linux: Use proper type for "len" variable
In reply to Frediano Ziglio via Grub-develAlthough the length should not exceed 2^31 grub_size_t is more suitable for that variable. "len" is used to compute the size of buffers which in C is a size_t, not a int. It is used for GRUB_EFI_BYTES_TO_PAGES which expects unsigned values. It is assigned to load_options_size which is unsigned, not signed.
--- grub-core/loader/efi/linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/loader/efi/linux.c +1 -1
@@ -190,7 +190,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)grub_efi_boot_services_t *b;grub_efi_status_t status;grub_efi_loaded_image_t *loaded_image; -int len; +grub_size_t len;grub_size_t args_len; mempath =grub_malloc (2 *sizeof (grub_efi_memory_mapped_device_path_t));
Signature · 7 lines
2.49.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v4 5/6 loader/efi/linux: Use sizeof instead of constant
In reply to Frediano Ziglio via Grub-develThis is more consistent with the above code using
sizeof (grub_efi_char16_t).
--- grub-core/loader/efi/linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
grub-core/loader/efi/linux.c +2 -2
@@ -231,9 +231,9 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)if (!loaded_image->load_options)return grub_errno; - loaded_image->load_options_size = -2 *grub_utf8_to_utf16 (loaded_image->load_options, len, + len =grub_utf8_to_utf16 (loaded_image->load_options, len, (grub_uint8_t *) args, args_len,NULL ); + loaded_image->load_options_size = len *sizeof (grub_efi_char16_t);grub_dprintf ("linux" ,"starting image %p\n" , image_handle); status = b->start_image (image_handle,0 ,NULL );
Signature · 7 lines
2.49.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH v4 6/6 loader/efi/linux: Correctly terminate LoadOptions field
In reply to Frediano Ziglio via Grub-develIf a simple string for arguments are passed it should be NUL terminated. This is true for other code but not for "linux" command.
---
Changes since v1
- remove useless assignment.
Changes since v2
- split changes;
- correct spacing.
--- grub-core/loader/efi/linux.c | 2 ++ 1 file changed, 2 insertions(+)
grub-core/loader/efi/linux.c +2 -0
@@ -233,6 +233,8 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) len =grub_utf8_to_utf16 (loaded_image->load_options, len, (grub_uint8_t *) args, args_len,NULL ); +/* NUL terminate */ + ((grub_efi_char16_t *) loaded_image->load_options)[len++] =0 ; loaded_image->load_options_size = len *sizeof (grub_efi_char16_t);grub_dprintf ("linux" ,"starting image %p\n" , image_handle);
Signature · 7 lines
2.49.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 8 lines · Frediano Ziglio via Grub-devel
The series started from the issue that LoadOptions, if providing just command line arguments should be NUL-terminated.
But this carried some updates to adjust the code properly.Changes since v3:
- use proper length converting args string;
- added Reviewed-by comments.
Quoted 7 lines
Frediano Ziglio (6):
loader/efi/linux: Remove useless assignmentinclude/grub/charset.h: Update documentation loader/efi/linux: Do not pass excessive size for source string loader/efi/linux: Use proper type for "len" variable loader/efi/linux: Use sizeof instead of constant loader/efi/linux: Correctly terminate LoadOptions field
For all patches Reviewed-by: Daniel Kiper <[email protected]>...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel