Skip to content

Commit 6425c12

Browse files
author
Daniel Kiper
committed
efi: Fallback to legacy mode if shim is loaded on x86 archs
The LoadImage() provided by the shim does not consult MOK when loading an image. So, simply signature verification fails when it should not. This means we cannot use Linux EFI stub to start the kernel when the shim is loaded. We have to fallback to legacy mode on x86 architectures. This is not possible on other architectures due to lack of legacy mode. This is workaround which should disappear when the shim provides LoadImage() which looks up MOK during signature verification. On the occasion align constants in include/grub/efi/sb.h. Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com> Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 7082a5c commit 6425c12

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

grub-core/kern/efi/sb.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
static grub_guid_t shim_lock_guid = GRUB_EFI_SHIM_LOCK_GUID;
3434

35+
static bool shim_lock_enabled = false;
36+
3537
/*
3638
* Determine whether we're in secure boot mode.
3739
*
@@ -215,6 +217,14 @@ grub_shim_lock_verifier_setup (void)
215217
/* Enforce shim_lock_verifier. */
216218
grub_verifier_register (&shim_lock_verifier);
217219

220+
shim_lock_enabled = true;
221+
218222
grub_env_set ("shim_lock", "y");
219223
grub_env_export ("shim_lock");
220224
}
225+
226+
bool
227+
grub_is_shim_lock_enabled (void)
228+
{
229+
return shim_lock_enabled;
230+
}

grub-core/loader/efi/linux.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <grub/efi/fdtload.h>
3030
#include <grub/efi/memory.h>
3131
#include <grub/efi/pe32.h>
32+
#include <grub/efi/sb.h>
3233
#include <grub/i18n.h>
3334
#include <grub/lib/cmdline.h>
3435
#include <grub/verify.h>
@@ -458,6 +459,22 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
458459

459460
grub_dl_ref (my_mod);
460461

462+
if (grub_is_shim_lock_enabled () == true)
463+
{
464+
#if defined(__i386__) || defined(__x86_64__)
465+
grub_dprintf ("linux", "shim_lock enabled, falling back to legacy Linux kernel loader\n");
466+
467+
err = grub_cmd_linux_x86_legacy (cmd, argc, argv);
468+
469+
if (err == GRUB_ERR_NONE)
470+
return GRUB_ERR_NONE;
471+
else
472+
goto fail;
473+
#else
474+
grub_dprintf ("linux", "shim_lock enabled, trying Linux kernel EFI stub loader\n");
475+
#endif
476+
}
477+
461478
if (argc == 0)
462479
{
463480
grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));

include/grub/efi/sb.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <grub/types.h>
2323
#include <grub/dl.h>
2424

25-
#define GRUB_EFI_SECUREBOOT_MODE_UNSET 0
25+
#define GRUB_EFI_SECUREBOOT_MODE_UNSET 0
2626
#define GRUB_EFI_SECUREBOOT_MODE_UNKNOWN 1
2727
#define GRUB_EFI_SECUREBOOT_MODE_DISABLED 2
2828
#define GRUB_EFI_SECUREBOOT_MODE_ENABLED 3
@@ -31,6 +31,9 @@
3131
extern grub_uint8_t
3232
EXPORT_FUNC (grub_efi_get_secureboot) (void);
3333

34+
extern bool
35+
EXPORT_FUNC (grub_is_shim_lock_enabled) (void);
36+
3437
extern void
3538
grub_shim_lock_verifier_setup (void);
3639
#else

0 commit comments

Comments
 (0)