nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0539-efi-Add-a-function-to-read-EFI-variables-with-attrib.patch

0ccc47
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
0ccc47
From: Daniel Kiper <daniel.kiper@oracle.com>
0ccc47
Date: Thu, 3 Dec 2020 16:01:47 +0100
0ccc47
Subject: [PATCH] efi: Add a function to read EFI variables with attributes
0ccc47
0ccc47
It will be used to properly detect and report UEFI Secure Boot status to
0ccc47
the x86 Linux kernel. The functionality will be added by subsequent patches.
0ccc47
0ccc47
Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
0ccc47
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
0ccc47
Signed-off-by: Marco A Benatto <mbenatto@redhat.com>
0ccc47
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
0ccc47
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
0ccc47
(cherry picked from commit ac5c9367548750e75ed1e7fc4354a3d20186d733)
0ccc47
---
0ccc47
 grub-core/kern/efi/efi.c | 16 +++++++++++++---
0ccc47
 include/grub/efi/efi.h   |  5 +++++
0ccc47
 2 files changed, 18 insertions(+), 3 deletions(-)
0ccc47
0ccc47
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
0ccc47
index 335033975d..fccea20a01 100644
0ccc47
--- a/grub-core/kern/efi/efi.c
0ccc47
+++ b/grub-core/kern/efi/efi.c
0ccc47
@@ -242,8 +242,11 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
0ccc47
 }
0ccc47
 
0ccc47
 grub_efi_status_t
0ccc47
-grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
0ccc47
-		       grub_size_t *datasize_out, void **data_out)
0ccc47
+grub_efi_get_variable_with_attributes (const char *var,
0ccc47
+				       const grub_efi_guid_t *guid,
0ccc47
+				       grub_size_t *datasize_out,
0ccc47
+				       void **data_out,
0ccc47
+				       grub_efi_uint32_t *attributes)
0ccc47
 {
0ccc47
   grub_efi_status_t status;
0ccc47
   grub_efi_uintn_t datasize = 0;
0ccc47
@@ -280,7 +283,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
0ccc47
       return GRUB_EFI_OUT_OF_RESOURCES;
0ccc47
     }
0ccc47
 
0ccc47
-  status = efi_call_5 (r->get_variable, var16, guid, NULL, &datasize, data);
0ccc47
+  status = efi_call_5 (r->get_variable, var16, guid, attributes, &datasize, data);
0ccc47
   grub_free (var16);
0ccc47
 
0ccc47
   if (status == GRUB_EFI_SUCCESS)
0ccc47
@@ -294,6 +297,13 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
0ccc47
   return status;
0ccc47
 }
0ccc47
 
0ccc47
+grub_efi_status_t
0ccc47
+grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid,
0ccc47
+		       grub_size_t *datasize_out, void **data_out)
0ccc47
+{
0ccc47
+  return grub_efi_get_variable_with_attributes (var, guid, datasize_out, data_out, NULL);
0ccc47
+}
0ccc47
+
0ccc47
 #pragma GCC diagnostic ignored "-Wcast-align"
0ccc47
 
0ccc47
 /* Search the mods section from the PE32/PE32+ image. This code uses
0ccc47
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
0ccc47
index 90a85d7d9a..7af979b184 100644
0ccc47
--- a/include/grub/efi/efi.h
0ccc47
+++ b/include/grub/efi/efi.h
0ccc47
@@ -113,6 +113,11 @@ grub_err_t EXPORT_FUNC (grub_efi_set_virtual_address_map) (grub_efi_uintn_t memo
0ccc47
 							   grub_efi_uintn_t descriptor_size,
0ccc47
 							   grub_efi_uint32_t descriptor_version,
0ccc47
 							   grub_efi_memory_descriptor_t *virtual_map);
0ccc47
+grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable_with_attributes) (const char *variable,
0ccc47
+								       const grub_efi_guid_t *guid,
0ccc47
+								       grub_size_t *datasize_out,
0ccc47
+								       void **data_out,
0ccc47
+								       grub_efi_uint32_t *attributes);
0ccc47
 grub_efi_status_t EXPORT_FUNC (grub_efi_get_variable) (const char *variable,
0ccc47
 						       const grub_efi_guid_t *guid,
0ccc47
 						       grub_size_t *datasize_out,