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

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