linux-zen-desktop/arch/arm64/kernel/kaslr.c

39 lines
957 B
C
Raw Normal View History

2023-08-30 17:31:07 +02:00
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2016 Linaro Ltd <ard.biesheuvel@linaro.org>
*/
#include <linux/cache.h>
#include <linux/init.h>
2023-10-24 12:59:35 +02:00
#include <linux/printk.h>
2023-08-30 17:31:07 +02:00
2023-10-24 12:59:35 +02:00
#include <asm/cpufeature.h>
2023-08-30 17:31:07 +02:00
#include <asm/memory.h>
u16 __initdata memstart_offset_seed;
2023-10-24 12:59:35 +02:00
bool __ro_after_init __kaslr_is_enabled = false;
2023-08-30 17:31:07 +02:00
2023-10-24 12:59:35 +02:00
void __init kaslr_init(void)
2023-08-30 17:31:07 +02:00
{
2023-10-24 12:59:35 +02:00
if (cpuid_feature_extract_unsigned_field(arm64_sw_feature_override.val &
arm64_sw_feature_override.mask,
ARM64_SW_FEATURE_OVERRIDE_NOKASLR)) {
2023-08-30 17:31:07 +02:00
pr_info("KASLR disabled on command line\n");
2023-10-24 12:59:35 +02:00
return;
2023-08-30 17:31:07 +02:00
}
/*
2023-10-24 12:59:35 +02:00
* The KASLR offset modulo MIN_KIMG_ALIGN is taken from the physical
* placement of the image rather than from the seed, so a displacement
* of less than MIN_KIMG_ALIGN means that no seed was provided.
2023-08-30 17:31:07 +02:00
*/
2023-10-24 12:59:35 +02:00
if (kaslr_offset() < MIN_KIMG_ALIGN) {
pr_warn("KASLR disabled due to lack of seed\n");
return;
2023-08-30 17:31:07 +02:00
}
2023-10-24 12:59:35 +02:00
pr_info("KASLR enabled\n");
__kaslr_is_enabled = true;
2023-08-30 17:31:07 +02:00
}