Blame SOURCES/0218-efi-properly-terminate-filepath-with-NULL-in-chainlo.patch

f725e3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f725e3
From: Andrei Borzenkov <arvidjaar@gmail.com>
f725e3
Date: Thu, 15 Dec 2016 16:07:00 +0300
f725e3
Subject: [PATCH] efi: properly terminate filepath with NULL in chainloader
f725e3
f725e3
EFI File Path Media Device Path is defined as NULL terminated string;
f725e3
but chainloader built file paths without final NULL. This caused error
f725e3
with Secure Boot and Linux Foundation PreLoader on Acer with InsydeH20 BIOS.
f725e3
Apparently firmware failed verification with EFI_INVALID_PARAMETER which is
f725e3
considered fatal error by PreLoader.
f725e3
f725e3
Reported and tested by Giovanni Santini <itachi.sama.amaterasu@gmail.com>
f725e3
---
f725e3
 grub-core/loader/efi/chainloader.c | 6 +++++-
f725e3
 1 file changed, 5 insertions(+), 1 deletion(-)
f725e3
f725e3
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
f725e3
index 522a716e37d..adc85636633 100644
f725e3
--- a/grub-core/loader/efi/chainloader.c
f725e3
+++ b/grub-core/loader/efi/chainloader.c
f725e3
@@ -122,6 +122,8 @@ copy_file_path (grub_efi_file_path_device_path_t *fp,
f725e3
     if (*p == '/')
f725e3
       *p = '\\';
f725e3
 
f725e3
+  /* File Path is NULL terminated */
f725e3
+  fp->path_name[size++] = '\0';
f725e3
   fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp);
f725e3
 }
f725e3
 
f725e3
@@ -156,8 +158,10 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename)
f725e3
       d = GRUB_EFI_NEXT_DEVICE_PATH (d);
f725e3
     }
f725e3
 
f725e3
+  /* File Path is NULL terminated. Allocate space for 2 extra characters */
f725e3
+  /* FIXME why we split path in two components? */
f725e3
   file_path = grub_malloc (size
f725e3
-			   + ((grub_strlen (dir_start) + 1)
f725e3
+			   + ((grub_strlen (dir_start) + 2)
f725e3
 			      * GRUB_MAX_UTF16_PER_UTF8
f725e3
 			      * sizeof (grub_efi_char16_t))
f725e3
 			   + sizeof (grub_efi_file_path_device_path_t) * 2);