[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC v2 5/5] efi: Add EFI shim lock verifier
From: |
Daniel Kiper |
Subject: |
[PATCH RFC v2 5/5] efi: Add EFI shim lock verifier |
Date: |
Fri, 3 Aug 2018 15:39:58 +0200 |
Just an RFC.
TODO:
- disable the GRUB2 modules load/unload,
- disable the dangerous modules, e.g. iorw, memrw.
Signed-off-by: Daniel Kiper <address@hidden>
---
grub-core/Makefile.core.def | 6 +++
grub-core/commands/efi/shim_lock.c | 93 ++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+)
create mode 100644 grub-core/commands/efi/shim_lock.c
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index dfcc95d..a2dda5f 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -900,6 +900,12 @@ module = {
};
module = {
+ name = shim_lock;
+ common = commands/efi/shim_lock.c;
+ enable = x86_64_efi;
+};
+
+module = {
name = hdparm;
common = commands/hdparm.c;
enable = pci;
diff --git a/grub-core/commands/efi/shim_lock.c
b/grub-core/commands/efi/shim_lock.c
new file mode 100644
index 0000000..a977768
--- /dev/null
+++ b/grub-core/commands/efi/shim_lock.c
@@ -0,0 +1,93 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2017 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * EFI shim lock verifier.
+ */
+
+#include <grub/dl.h>
+#include <grub/efi/efi.h>
+#include <grub/err.h>
+#include <grub/file.h>
+#include <grub/verify.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+#define GRUB_EFI_SHIM_LOCK_GUID \
+ { 0x605dab50, 0xe046, 0x4300, \
+ { 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 } \
+ }
+
+struct grub_efi_shim_lock_protocol
+{
+ grub_efi_status_t
+ (*verify) (void *buffer,
+ grub_uint32_t size);
+};
+typedef struct grub_efi_shim_lock_protocol grub_efi_shim_lock_protocol_t;
+
+static grub_efi_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
+static grub_efi_shim_lock_protocol_t *sl;
+
+static grub_err_t
+shim_lock_init (grub_file_t io __attribute__ ((unused)), enum grub_file_type
type,
+ void **context __attribute__ ((unused)), enum grub_verify_flags
*flags)
+{
+ *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION;
+
+ if (!sl)
+ return GRUB_ERR_NONE;
+
+ switch (type & GRUB_FILE_TYPE_MASK)
+ {
+ case GRUB_FILE_TYPE_LINUX_KERNEL:
+ case GRUB_FILE_TYPE_MULTIBOOT_KERNEL:
+ case GRUB_FILE_TYPE_BSD_KERNEL:
+ case GRUB_FILE_TYPE_XNU_KERNEL:
+ case GRUB_FILE_TYPE_PLAN9_KERNEL:
+ *flags = GRUB_VERIFY_FLAGS_SINGLE_CHUNK;
+
+ default:
+ return GRUB_ERR_NONE;
+ }
+}
+
+static grub_err_t
+shim_lock_write (void *context __attribute__ ((unused)), void *buf,
grub_size_t size)
+{
+ if (sl->verify (buf, size) != GRUB_EFI_SUCCESS)
+ return grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad shim signature"));
+
+ return GRUB_ERR_NONE;
+}
+
+struct grub_file_verifier shim_lock =
+ {
+ .name = "shim_lock",
+ .init = shim_lock_init,
+ .write = shim_lock_write
+ };
+
+GRUB_MOD_INIT(shim_lock)
+{
+ sl = grub_efi_locate_protocol (&shim_lock_guid, 0);
+ grub_verifier_register (&shim_lock);
+}
+
+GRUB_MOD_FINI(shim_lock)
+{
+ grub_verifier_unregister (&shim_lock);
+}
--
1.7.10.4
- [PATCH RFC v2 0/5] verifiers: Framework and EFI shim lock verifier, Daniel Kiper, 2018/08/03
- [PATCH RFC v2 2/5] verifiers: Framework core, Daniel Kiper, 2018/08/03
- [PATCH RFC v2 4/5] verifiers: Add the documentation, Daniel Kiper, 2018/08/03
- [PATCH RFC v2 1/5] verifiers: File type for fine-grained signature-verification controlling, Daniel Kiper, 2018/08/03
- [PATCH RFC v2 3/5] verifiers: Add possibility to verify kernel and modules command lines, Daniel Kiper, 2018/08/03
- [PATCH RFC v2 5/5] efi: Add EFI shim lock verifier,
Daniel Kiper <=
- Re: [PATCH RFC v2 0/5] verifiers: Framework and EFI shim lock verifier, Matthew Garrett, 2018/08/03