kaslr.c 996 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2016 Linaro Ltd <ard.biesheuvel@linaro.org>
  4. */
  5. #include <linux/cache.h>
  6. #include <linux/init.h>
  7. #include <linux/printk.h>
  8. #include <asm/cpufeature.h>
  9. #include <asm/memory.h>
  10. u16 __initdata memstart_offset_seed;
  11. bool __ro_after_init __kaslr_is_enabled = false;
  12. void __init kaslr_init(void)
  13. {
  14. if (kaslr_disabled_cmdline()) {
  15. pr_info("KASLR disabled on command line\n");
  16. return;
  17. }
  18. /*
  19. * The KASLR offset modulo MIN_KIMG_ALIGN is taken from the physical
  20. * placement of the image rather than from the seed, so a displacement
  21. * of less than MIN_KIMG_ALIGN means that no seed was provided.
  22. */
  23. if (kaslr_offset() < MIN_KIMG_ALIGN) {
  24. pr_warn("KASLR disabled due to lack of seed\n");
  25. return;
  26. }
  27. pr_info("KASLR enabled\n");
  28. __kaslr_is_enabled = true;
  29. }
  30. static int __init parse_nokaslr(char *unused)
  31. {
  32. /* nokaslr param handling is done by early cpufeature code */
  33. return 0;
  34. }
  35. early_param("nokaslr", parse_nokaslr);