lockdown.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2020 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #include <grub/dl.h>
  20. #include <grub/env.h>
  21. #include <grub/file.h>
  22. #include <grub/lockdown.h>
  23. #include <grub/verify.h>
  24. static int lockdown = GRUB_LOCKDOWN_DISABLED;
  25. static grub_err_t
  26. lockdown_verifier_init (grub_file_t io __attribute__ ((unused)),
  27. enum grub_file_type type,
  28. void **context __attribute__ ((unused)),
  29. enum grub_verify_flags *flags)
  30. {
  31. *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION;
  32. switch (type & GRUB_FILE_TYPE_MASK)
  33. {
  34. case GRUB_FILE_TYPE_GRUB_MODULE:
  35. case GRUB_FILE_TYPE_LINUX_KERNEL:
  36. case GRUB_FILE_TYPE_MULTIBOOT_KERNEL:
  37. case GRUB_FILE_TYPE_XEN_HYPERVISOR:
  38. case GRUB_FILE_TYPE_BSD_KERNEL:
  39. case GRUB_FILE_TYPE_XNU_KERNEL:
  40. case GRUB_FILE_TYPE_PLAN9_KERNEL:
  41. case GRUB_FILE_TYPE_NTLDR:
  42. case GRUB_FILE_TYPE_TRUECRYPT:
  43. case GRUB_FILE_TYPE_FREEDOS:
  44. case GRUB_FILE_TYPE_PXECHAINLOADER:
  45. case GRUB_FILE_TYPE_PCCHAINLOADER:
  46. case GRUB_FILE_TYPE_COREBOOT_CHAINLOADER:
  47. case GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE:
  48. case GRUB_FILE_TYPE_ACPI_TABLE:
  49. case GRUB_FILE_TYPE_DEVICE_TREE_IMAGE:
  50. case GRUB_FILE_TYPE_FONT:
  51. *flags = GRUB_VERIFY_FLAGS_DEFER_AUTH;
  52. /* Fall through. */
  53. default:
  54. return GRUB_ERR_NONE;
  55. }
  56. }
  57. struct grub_file_verifier lockdown_verifier =
  58. {
  59. .name = "lockdown_verifier",
  60. .init = lockdown_verifier_init,
  61. };
  62. void
  63. grub_lockdown (void)
  64. {
  65. lockdown = GRUB_LOCKDOWN_ENABLED;
  66. grub_verifier_register (&lockdown_verifier);
  67. grub_env_set ("lockdown", "y");
  68. grub_env_export ("lockdown");
  69. }
  70. int
  71. grub_is_lockdown (void)
  72. {
  73. return lockdown;
  74. }