12.12.2016 14:06, Giovanni Santini пишет:
> As you can notice, I've disabled the second modification you said me
> (setting two parameters to 0) because that broke GRUB booting Windows in
> every condition.
> 

That was bug in grub. This bug may cause verification error (because it
resulted in incorrect file name passed to EFI). Please test attached
patch (on top of clean sources). If it does not work "as is", please set
two parameters to 0 and test again.
From: Andrei Borzenkov <[email protected]>
Subject: [PATCH] efi: fix off-by-one error in chainloader filepath

EFI File Path Media Device Path is defined as NULL terminated string;
but chainloader built file paths without final NULL. This caused error
with Secure Boot and Linux Foundation PreLoader. Apparently firmware
failed verification with EFI_INVALID_PARAMETER which is considered
fatal error by PreLoader.

Fix debug print of device path while on it.

Reported and tested by Giovanni Santini <[email protected]>

---
 grub-core/loader/efi/chainloader.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
index 522a716..3fc03a1 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -122,6 +122,8 @@ 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);
 }
 
@@ -156,8 +158,10 @@ 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) + 1)
+			   + ((grub_strlen (dir_start) + 2)
 			      * GRUB_MAX_UTF16_PER_UTF8
 			      * sizeof (grub_efi_char16_t))
 			   + sizeof (grub_efi_file_path_device_path_t) * 2);
@@ -169,7 +173,7 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename)
   /* Fill the file path for the directory.  */
   d = (grub_efi_device_path_t *) ((char *) file_path
 				  + ((char *) d - (char *) dp));
-  grub_efi_print_device_path (d);
+  grub_efi_print_device_path (dp);
   copy_file_path ((grub_efi_file_path_device_path_t *) d,
 		  dir_start, dir_end - dir_start);
 
-- 
tg: (a3e9da0..) u/efi-chainloader-filepath (depends on: master)
_______________________________________________
Help-grub mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-grub

Reply via email to