Received: from list by lists.gnu.org with archive (Exim 4.71) id 1dTxgj-0001m2-8l for mharc-grub-devel@gnu.org; Sat, 08 Jul 2017 17:54:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTxgg-0001lt-UZ for grub-devel@gnu.org; Sat, 08 Jul 2017 17:54:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTxgd-0000Yk-RJ for grub-devel@gnu.org; Sat, 08 Jul 2017 17:54:51 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:16620) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTxgd-0000W9-HI for grub-devel@gnu.org; Sat, 08 Jul 2017 17:54:47 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v68LseV8015422 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 8 Jul 2017 21:54:40 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v68LscFW015945 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 8 Jul 2017 21:54:39 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id v68LsaCg025204; Sat, 8 Jul 2017 21:54:37 GMT Received: from olila.local.net-space.pl (/10.175.230.11) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 08 Jul 2017 14:54:35 -0700 From: Daniel Kiper To: grub-devel@gnu.org, xen-devel@lists.xenproject.org Cc: andrew.cooper3@citrix.com, arvidjaar@gmail.com, konrad.wilk@oracle.com, phcoder@gmail.com Subject: [GRUB2 PATCH RFC 1/1] efi: Add EFI shim lock verifier Date: Sat, 8 Jul 2017 23:54:25 +0200 Message-Id: <1499550865-25721-1-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 X-Source-IP: userv0022.oracle.com [156.151.31.74] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 141.146.126.69 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Jul 2017 21:54:52 -0000 This is based on git://git.savannah.gnu.org/grub.git phcoder/verifiers branch. Just an RFC. TODO: - disable the GRUB2 modules load/unload, - disable the dangerous modules, e.g. iorw, memrw. Signed-off-by: Daniel Kiper --- grub-core/Makefile.core.def | 6 +++ grub-core/commands/efi/shim_lock.c | 100 ++++++++++++++++++++++++++++++++++++ 2 files changed, 106 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 16c4d0e..c38e4a8 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -905,6 +905,12 @@ module = { }; module = { + name = shim_lock; + common = commands/efi/shim_lock.c; + enable = x86_64_efi; +}; + +module = { name = hdparm; common = commands/hdparm.c; common = lib/hexdump.c; diff --git a/grub-core/commands/efi/shim_lock.c b/grub-core/commands/efi/shim_lock.c new file mode 100644 index 0000000..40d2b25 --- /dev/null +++ b/grub-core/commands/efi/shim_lock.c @@ -0,0 +1,100 @@ +/* + * 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 . + * + * EFI shim lock verifier. + * + */ + +#include +#include +#include +#include +#include + +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; +} + +static void +shim_lock_close (void *context __attribute__ ((unused))) +{ +} + +struct grub_file_verifier shim_lock = + { + .name = "shim_lock", + .init = shim_lock_init, + .write = shim_lock_write, + .close = shim_lock_close + }; + +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