dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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