0041-commands-Restrict-commands-that-can-load-BIOS-or-DT-.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From 468a5699b249fe6816b4e7e86c5dc9d325c9b09e Mon Sep 17 00:00:00 2001
  2. From: Javier Martinez Canillas <javierm@redhat.com>
  3. Date: Wed, 24 Feb 2021 09:00:05 +0100
  4. Subject: [PATCH] commands: Restrict commands that can load BIOS or DT blobs
  5. when locked down
  6. There are some more commands that should be restricted when the GRUB is
  7. locked down. Following is the list of commands and reasons to restrict:
  8. * fakebios: creates BIOS-like structures for backward compatibility with
  9. existing OSes. This should not be allowed when locked down.
  10. * loadbios: reads a BIOS dump from storage and loads it. This action
  11. should not be allowed when locked down.
  12. * devicetree: loads a Device Tree blob and passes it to the OS. It replaces
  13. any Device Tree provided by the firmware. This also should
  14. not be allowed when locked down.
  15. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
  16. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  17. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  18. ---
  19. docs/grub.texi | 3 +++
  20. grub-core/commands/efi/loadbios.c | 16 ++++++++--------
  21. grub-core/loader/arm/linux.c | 6 +++---
  22. grub-core/loader/efi/fdt.c | 4 ++--
  23. 4 files changed, 16 insertions(+), 13 deletions(-)
  24. diff --git a/docs/grub.texi b/docs/grub.texi
  25. index f2fe149..79f58c5 100644
  26. --- a/docs/grub.texi
  27. +++ b/docs/grub.texi
  28. @@ -4235,6 +4235,9 @@ hour, minute, and second unchanged.
  29. Load a device tree blob (.dtb) from a filesystem, for later use by a Linux
  30. kernel. Does not perform merging with any device tree supplied by firmware,
  31. but rather replaces it completely.
  32. +
  33. +Note: The command is not allowed when lockdown is enforced (@pxref{Lockdown}).
  34. + This is done to prevent subverting various security mechanisms.
  35. @ref{GNU/Linux}.
  36. @end deffn
  37. diff --git a/grub-core/commands/efi/loadbios.c b/grub-core/commands/efi/loadbios.c
  38. index d41d521..5c7725f 100644
  39. --- a/grub-core/commands/efi/loadbios.c
  40. +++ b/grub-core/commands/efi/loadbios.c
  41. @@ -205,14 +205,14 @@ static grub_command_t cmd_fakebios, cmd_loadbios;
  42. GRUB_MOD_INIT(loadbios)
  43. {
  44. - cmd_fakebios = grub_register_command ("fakebios", grub_cmd_fakebios,
  45. - 0, N_("Create BIOS-like structures for"
  46. - " backward compatibility with"
  47. - " existing OS."));
  48. -
  49. - cmd_loadbios = grub_register_command ("loadbios", grub_cmd_loadbios,
  50. - N_("BIOS_DUMP [INT10_DUMP]"),
  51. - N_("Load BIOS dump."));
  52. + cmd_fakebios = grub_register_command_lockdown ("fakebios", grub_cmd_fakebios,
  53. + 0, N_("Create BIOS-like structures for"
  54. + " backward compatibility with"
  55. + " existing OS."));
  56. +
  57. + cmd_loadbios = grub_register_command_lockdown ("loadbios", grub_cmd_loadbios,
  58. + N_("BIOS_DUMP [INT10_DUMP]"),
  59. + N_("Load BIOS dump."));
  60. }
  61. GRUB_MOD_FINI(loadbios)
  62. diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
  63. index d70c174..ed23dc7 100644
  64. --- a/grub-core/loader/arm/linux.c
  65. +++ b/grub-core/loader/arm/linux.c
  66. @@ -493,9 +493,9 @@ GRUB_MOD_INIT (linux)
  67. 0, N_("Load Linux."));
  68. cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd,
  69. 0, N_("Load initrd."));
  70. - cmd_devicetree = grub_register_command ("devicetree", grub_cmd_devicetree,
  71. - /* TRANSLATORS: DTB stands for device tree blob. */
  72. - 0, N_("Load DTB file."));
  73. + cmd_devicetree = grub_register_command_lockdown ("devicetree", grub_cmd_devicetree,
  74. + /* TRANSLATORS: DTB stands for device tree blob. */
  75. + 0, N_("Load DTB file."));
  76. my_mod = mod;
  77. current_fdt = (const void *) grub_arm_firmware_get_boot_data ();
  78. machine_type = grub_arm_firmware_get_machine_type ();
  79. diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
  80. index ee9c559..003d07c 100644
  81. --- a/grub-core/loader/efi/fdt.c
  82. +++ b/grub-core/loader/efi/fdt.c
  83. @@ -165,8 +165,8 @@ static grub_command_t cmd_devicetree;
  84. GRUB_MOD_INIT (fdt)
  85. {
  86. cmd_devicetree =
  87. - grub_register_command ("devicetree", grub_cmd_devicetree, 0,
  88. - N_("Load DTB file."));
  89. + grub_register_command_lockdown ("devicetree", grub_cmd_devicetree, 0,
  90. + N_("Load DTB file."));
  91. }
  92. GRUB_MOD_FINI (fdt)
  93. --
  94. 2.14.2