lock_down.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Lock down the kernel
  2. *
  3. * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/security.h>
  12. #include <linux/export.h>
  13. #include <linux/efi.h>
  14. static __ro_after_init bool kernel_locked_down;
  15. /*
  16. * Put the kernel into lock-down mode.
  17. */
  18. static void __init lock_kernel_down(const char *where)
  19. {
  20. if (!kernel_locked_down) {
  21. kernel_locked_down = true;
  22. pr_notice("Kernel is locked down from %s; see https://wiki.debian.org/SecureBoot\n",
  23. where);
  24. }
  25. }
  26. static int __init lockdown_param(char *ignored)
  27. {
  28. lock_kernel_down("command line");
  29. return 0;
  30. }
  31. early_param("lockdown", lockdown_param);
  32. /*
  33. * Lock the kernel down from very early in the arch setup. This must happen
  34. * prior to things like ACPI being initialised.
  35. */
  36. void __init init_lockdown(void)
  37. {
  38. #ifdef CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT
  39. if (efi_enabled(EFI_SECURE_BOOT))
  40. lock_kernel_down("EFI secure boot");
  41. #endif
  42. }
  43. /**
  44. * kernel_is_locked_down - Find out if the kernel is locked down
  45. * @what: Tag to use in notice generated if lockdown is in effect
  46. */
  47. bool __kernel_is_locked_down(const char *what, bool first)
  48. {
  49. if (what && first && kernel_locked_down)
  50. pr_notice("Lockdown: %s is restricted; see https://wiki.debian.org/SecureBoot\n",
  51. what);
  52. return kernel_locked_down;
  53. }
  54. EXPORT_SYMBOL(__kernel_is_locked_down);