nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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