From 014d0e9f0be66e307f01ccc64b41b6b5c54d66ae4b96fc603b58596fc38c30ae Mon Sep 17 00:00:00 2001 From: Andrei Borzenkov Date: Thu, 2 Mar 2017 03:31:33 +0000 Subject: [PATCH] Accepting request 461364 from home:michael-chang:branches:Base:System - Fix for openQA UEFI USB Boot failure with upstream patch (bsc#1026344) * added 0001-efi-strip-off-final-NULL-from-File-Path-in-grub_efi_.patch * removed 0001-Revert-efi-properly-terminate-filepath-with-NULL-in-.patch OBS-URL: https://build.opensuse.org/request/show/461364 OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=259 --- ...rly-terminate-filepath-with-NULL-in-.patch | 39 ------------------ ...nal-NULL-from-File-Path-in-grub_efi_.patch | 41 +++++++++++++++++++ grub2.changes | 7 ++++ grub2.spec | 2 +- 4 files changed, 49 insertions(+), 40 deletions(-) delete mode 100644 0001-Revert-efi-properly-terminate-filepath-with-NULL-in-.patch create mode 100644 0001-efi-strip-off-final-NULL-from-File-Path-in-grub_efi_.patch diff --git a/0001-Revert-efi-properly-terminate-filepath-with-NULL-in-.patch b/0001-Revert-efi-properly-terminate-filepath-with-NULL-in-.patch deleted file mode 100644 index 0d7ab44..0000000 --- a/0001-Revert-efi-properly-terminate-filepath-with-NULL-in-.patch +++ /dev/null @@ -1,39 +0,0 @@ -From 28f83642deb777cce122c3629ddbd7b44a7f95b4 Mon Sep 17 00:00:00 2001 -From: Michael Chang -Date: Thu, 23 Feb 2017 22:39:37 +0800 -Subject: [PATCH] Revert "efi: properly terminate filepath with NULL in - chainloader" - -This reverts commit ce95549cc54b5d6f494608a7c390dba3aab4fba7. ---- - grub-core/loader/efi/chainloader.c | 6 +----- - 1 file changed, 1 insertion(+), 5 deletions(-) - -diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c -index adc8563..522a716 100644 ---- a/grub-core/loader/efi/chainloader.c -+++ b/grub-core/loader/efi/chainloader.c -@@ -122,8 +122,6 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, - if (*p == '/') - *p = '\\'; - -- /* File Path is NULL terminated */ -- fp->path_name[size++] = '\0'; - fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp); - } - -@@ -158,10 +156,8 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename) - d = GRUB_EFI_NEXT_DEVICE_PATH (d); - } - -- /* File Path is NULL terminated. Allocate space for 2 extra characters */ -- /* FIXME why we split path in two components? */ - file_path = grub_malloc (size -- + ((grub_strlen (dir_start) + 2) -+ + ((grub_strlen (dir_start) + 1) - * GRUB_MAX_UTF16_PER_UTF8 - * sizeof (grub_efi_char16_t)) - + sizeof (grub_efi_file_path_device_path_t) * 2); --- -2.6.6 - diff --git a/0001-efi-strip-off-final-NULL-from-File-Path-in-grub_efi_.patch b/0001-efi-strip-off-final-NULL-from-File-Path-in-grub_efi_.patch new file mode 100644 index 0000000..101e2ed --- /dev/null +++ b/0001-efi-strip-off-final-NULL-from-File-Path-in-grub_efi_.patch @@ -0,0 +1,41 @@ +From 892dfbe113d08c18e51d7c27eee5094f3da530ec Mon Sep 17 00:00:00 2001 +From: Andrei Borzenkov +Date: Sat, 25 Feb 2017 08:39:38 +0300 +Subject: [PATCH] efi: strip off final NULL from File Path in + grub_efi_get_filename + +UEFI 2.6 9.3.6.4 File Path Media Device Path says that Path Name is +"A NULL-terminated Path string including directory and file names". + +Strip final NULL from Path Name in each File Path node when constructing +full path. To be on safe side, strip all of them. + +Fixes failure chainloading grub from grub, when loaded grub truncates +image path and does not find its grub.cfg. + +https://bugzilla.opensuse.org/show_bug.cgi?id=1026344 + +This was triggered by commit ce95549cc54b5d6f494608a7c390dba3aab4fba7; +before it we built Path Name without trailing NULL, and apparently all +other bootloaders use single File Path node, thus not exposing this bug. +--- + grub-core/kern/efi/efi.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c +index caf9bcc..d467785 100644 +--- a/grub-core/kern/efi/efi.c ++++ b/grub-core/kern/efi/efi.c +@@ -366,6 +366,9 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) + len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) + / sizeof (grub_efi_char16_t)); + fp = (grub_efi_file_path_device_path_t *) dp; ++ /* According to EFI spec Path Name is NULL terminated */ ++ while (len > 0 && fp->path_name[len - 1] == 0) ++ len--; + + p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len); + } +-- +2.6.6 + diff --git a/grub2.changes b/grub2.changes index 6ce2086..18a47c7 100644 --- a/grub2.changes +++ b/grub2.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Wed Mar 1 10:29:46 UTC 2017 - mchang@suse.com + +- Fix for openQA UEFI USB Boot failure with upstream patch (bsc#1026344) + * added 0001-efi-strip-off-final-NULL-from-File-Path-in-grub_efi_.patch + * removed 0001-Revert-efi-properly-terminate-filepath-with-NULL-in-.patch + ------------------------------------------------------------------- Thu Feb 23 15:06:44 UTC 2017 - mchang@suse.com diff --git a/grub2.spec b/grub2.spec index 649d09c..1904d74 100644 --- a/grub2.spec +++ b/grub2.spec @@ -206,7 +206,7 @@ Patch77: grub2-s390x-08-workaround-part-to-disk.patch Patch78: grub2-commands-introduce-read_file-subcommand.patch Patch79: grub2-efi-chainload-harder.patch Patch80: grub2-emu-4-all.patch -Patch81: 0001-Revert-efi-properly-terminate-filepath-with-NULL-in-.patch +Patch81: 0001-efi-strip-off-final-NULL-from-File-Path-in-grub_efi_.patch # Btrfs snapshot booting related patches Patch101: grub2-btrfs-01-add-ability-to-boot-from-subvolumes.patch Patch102: grub2-btrfs-02-export-subvolume-envvars.patch