]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
arm64: kaslr: ignore modulo offset when validating virtual displacement
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 18 Aug 2017 17:42:30 +0000 (18:42 +0100)
committerWill Deacon <will.deacon@arm.com>
Tue, 22 Aug 2017 17:15:42 +0000 (18:15 +0100)
In the KASLR setup routine, we ensure that the early virtual mapping
of the kernel image does not cover more than a single table entry at
the level above the swapper block level, so that the assembler routines
involved in setting up this mapping can remain simple.

In this calculation we add the proposed KASLR offset to the values of
the _text and _end markers, and reject it if they would end up falling
in different swapper table sized windows.

However, when taking the addresses of _text and _end, the modulo offset
(the physical displacement modulo 2 MB) is already accounted for, and
so adding it again results in incorrect results. So disregard the modulo
offset from the calculation.

Fixes: 08cdac619c81 ("arm64: relocatable: deal with physically misaligned ...")
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
arch/arm64/kernel/head.S
arch/arm64/kernel/kaslr.c

index 973df7de7bf8d3e4fcde6dc2ba1590fa051964a2..adb0910b88f5f26c1562a7fef6f00f29ee9ec391 100644 (file)
@@ -354,7 +354,6 @@ __primary_switched:
        tst     x23, ~(MIN_KIMG_ALIGN - 1)      // already running randomized?
        b.ne    0f
        mov     x0, x21                         // pass FDT address in x0
-       mov     x1, x23                         // pass modulo offset in x1
        bl      kaslr_early_init                // parse FDT for KASLR options
        cbz     x0, 0f                          // KASLR disabled? just proceed
        orr     x23, x23, x0                    // record KASLR offset
index a9710efb8c017a735f9aa6518463d11b8d6264c9..1d95c204186b40f8e8225fd1885136db0dd0928b 100644 (file)
@@ -75,7 +75,7 @@ extern void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size,
  * containing function pointers) to be reinitialized, and zero-initialized
  * .bss variables will be reset to 0.
  */
-u64 __init kaslr_early_init(u64 dt_phys, u64 modulo_offset)
+u64 __init kaslr_early_init(u64 dt_phys)
 {
        void *fdt;
        u64 seed, offset, mask, module_range;
@@ -133,9 +133,15 @@ u64 __init kaslr_early_init(u64 dt_phys, u64 modulo_offset)
         * boundary (for 4KB/16KB/64KB granule kernels, respectively). If this
         * happens, increase the KASLR offset by the size of the kernel image
         * rounded up by SWAPPER_BLOCK_SIZE.
+        *
+        * NOTE: The references to _text and _end below will already take the
+        *       modulo offset (the physical displacement modulo 2 MB) into
+        *       account, given that the physical placement is controlled by
+        *       the loader, and will not change as a result of the virtual
+        *       mapping we choose.
         */
-       if ((((u64)_text + offset + modulo_offset) >> SWAPPER_TABLE_SHIFT) !=
-           (((u64)_end + offset + modulo_offset) >> SWAPPER_TABLE_SHIFT)) {
+       if ((((u64)_text + offset) >> SWAPPER_TABLE_SHIFT) !=
+           (((u64)_end + offset) >> SWAPPER_TABLE_SHIFT)) {
                u64 kimg_sz = _end - _text;
                offset = (offset + round_up(kimg_sz, SWAPPER_BLOCK_SIZE))
                                & mask;