2013-09-13 14:43:46 +02:00
|
|
|
|
From 29c89e27805f7a6a22bce11ed9bb430e19c972a9 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Colin Watson <cjwatson@ubuntu.com>
|
|
|
|
|
Date: Tue, 23 Oct 2012 10:40:49 -0400
|
|
|
|
|
Subject: [PATCH 449/482] Don't allow insmod when secure boot is enabled.
|
2012-11-28 10:34:03 +01:00
|
|
|
|
|
|
|
|
|
References: fate#314485
|
|
|
|
|
Patch-Mainline: no
|
|
|
|
|
|
|
|
|
|
Signed-off-by: Michael Chang <mchang@suse.com>
|
|
|
|
|
---
|
2013-09-13 14:43:46 +02:00
|
|
|
|
grub-core/kern/dl.c | 17 +++++++++++++++++
|
2012-11-28 10:34:03 +01:00
|
|
|
|
grub-core/kern/efi/efi.c | 28 ++++++++++++++++++++++++++++
|
|
|
|
|
include/grub/efi/efi.h | 1 +
|
2013-09-13 14:43:46 +02:00
|
|
|
|
3 files changed, 46 insertions(+)
|
2012-11-28 10:34:03 +01:00
|
|
|
|
|
2019-11-03 11:24:40 +01:00
|
|
|
|
Index: grub-2.04~rc1/grub-core/kern/dl.c
|
2012-11-28 10:34:03 +01:00
|
|
|
|
===================================================================
|
2019-11-03 11:24:40 +01:00
|
|
|
|
--- grub-2.04~rc1.orig/grub-core/kern/dl.c
|
|
|
|
|
+++ grub-2.04~rc1/grub-core/kern/dl.c
|
2014-01-10 21:19:21 +01:00
|
|
|
|
@@ -38,6 +38,10 @@
|
|
|
|
|
#define GRUB_MODULES_MACHINE_READONLY
|
2013-09-13 14:43:46 +02:00
|
|
|
|
#endif
|
2012-11-28 10:34:03 +01:00
|
|
|
|
|
|
|
|
|
+#ifdef GRUB_MACHINE_EFI
|
|
|
|
|
+#include <grub/efi/efi.h>
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
2013-09-13 14:43:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wcast-align"
|
2019-11-03 11:24:40 +01:00
|
|
|
|
@@ -688,6 +692,19 @@ grub_dl_load_file (const char *filename)
|
2014-01-10 21:19:21 +01:00
|
|
|
|
|
|
|
|
|
grub_boot_time ("Loading module %s", filename);
|
2012-11-28 10:34:03 +01:00
|
|
|
|
|
|
|
|
|
+#ifdef GRUB_MACHINE_EFI
|
2013-09-13 14:43:46 +02:00
|
|
|
|
+ if (grub_efi_secure_boot ())
|
|
|
|
|
+ {
|
|
|
|
|
+#if 0
|
|
|
|
|
+ /* This is an error, but grub2-mkconfig still generates a pile of
|
|
|
|
|
+ * insmod commands, so emitting it would be mostly just obnoxious. */
|
|
|
|
|
+ grub_error (GRUB_ERR_ACCESS_DENIED,
|
|
|
|
|
+ "Secure Boot forbids loading module from %s", filename);
|
|
|
|
|
+#endif
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
2012-11-28 10:34:03 +01:00
|
|
|
|
+#endif
|
|
|
|
|
+
|
2019-11-03 11:24:40 +01:00
|
|
|
|
file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE);
|
2013-09-13 14:43:46 +02:00
|
|
|
|
if (! file)
|
|
|
|
|
return 0;
|
2019-11-03 11:24:40 +01:00
|
|
|
|
Index: grub-2.04~rc1/grub-core/kern/efi/efi.c
|
2012-11-28 10:34:03 +01:00
|
|
|
|
===================================================================
|
2019-11-03 11:24:40 +01:00
|
|
|
|
--- grub-2.04~rc1.orig/grub-core/kern/efi/efi.c
|
|
|
|
|
+++ grub-2.04~rc1/grub-core/kern/efi/efi.c
|
|
|
|
|
@@ -273,6 +273,34 @@ grub_efi_get_variable (const char *var,
|
2012-11-28 10:34:03 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+grub_efi_boolean_t
|
|
|
|
|
+grub_efi_secure_boot (void)
|
|
|
|
|
+{
|
|
|
|
|
+ grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID;
|
|
|
|
|
+ grub_size_t datasize;
|
|
|
|
|
+ char *secure_boot = NULL;
|
|
|
|
|
+ char *setup_mode = NULL;
|
|
|
|
|
+ grub_efi_boolean_t ret = 0;
|
|
|
|
|
+
|
|
|
|
|
+ secure_boot = grub_efi_get_variable("SecureBoot", &efi_var_guid, &datasize);
|
|
|
|
|
+
|
|
|
|
|
+ if (datasize != 1 || !secure_boot)
|
|
|
|
|
+ goto out;
|
|
|
|
|
+
|
|
|
|
|
+ setup_mode = grub_efi_get_variable("SetupMode", &efi_var_guid, &datasize);
|
|
|
|
|
+
|
|
|
|
|
+ if (datasize != 1 || !setup_mode)
|
|
|
|
|
+ goto out;
|
|
|
|
|
+
|
|
|
|
|
+ if (*secure_boot && !*setup_mode)
|
|
|
|
|
+ ret = 1;
|
|
|
|
|
+
|
|
|
|
|
+ out:
|
|
|
|
|
+ grub_free (secure_boot);
|
|
|
|
|
+ grub_free (setup_mode);
|
|
|
|
|
+ return ret;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wcast-align"
|
|
|
|
|
|
|
|
|
|
/* Search the mods section from the PE32/PE32+ image. This code uses
|
2019-11-03 11:24:40 +01:00
|
|
|
|
Index: grub-2.04~rc1/include/grub/efi/efi.h
|
2012-11-28 10:34:03 +01:00
|
|
|
|
===================================================================
|
2019-11-03 11:24:40 +01:00
|
|
|
|
--- grub-2.04~rc1.orig/include/grub/efi/efi.h
|
|
|
|
|
+++ grub-2.04~rc1/include/grub/efi/efi.h
|
|
|
|
|
@@ -85,6 +85,7 @@ EXPORT_FUNC (grub_efi_set_variable) (con
|
2013-06-26 20:19:00 +02:00
|
|
|
|
const grub_efi_guid_t *guid,
|
|
|
|
|
void *data,
|
|
|
|
|
grub_size_t datasize);
|
2012-11-28 10:34:03 +01:00
|
|
|
|
+grub_efi_boolean_t EXPORT_FUNC (grub_efi_secure_boot) (void);
|
|
|
|
|
int
|
|
|
|
|
EXPORT_FUNC (grub_efi_compare_device_paths) (const grub_efi_device_path_t *dp1,
|
|
|
|
|
const grub_efi_device_path_t *dp2);
|