Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: Prepare for randomized task_struct

With the new task struct randomization, we can run into a build
failure for certain random seeds, which will place fields beyond
the allow immediate size in the assembly:

arch/arm/kernel/entry-armv.S: Assembler messages:
arch/arm/kernel/entry-armv.S:803: Error: bad immediate value for offset (4096)

Only two constants in asm-offset.h are affected, and I'm changing
both of them here to work correctly in all configurations.

One more macro has the problem, but is currently unused, so this
removes it instead of adding complexity.

Suggested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
[kees: Adjust commit log slightly]
Signed-off-by: Kees Cook <keescook@chromium.org>

authored by

Arnd Bergmann and committed by
Kees Cook
ffa47aa6 1854c19c

+10 -7
+2
arch/arm/include/asm/assembler.h
··· 87 87 #define CALGN(code...) 88 88 #endif 89 89 90 + #define IMM12_MASK 0xfff 91 + 90 92 /* 91 93 * Enable and disable interrupts 92 94 */
+4 -1
arch/arm/kernel/entry-armv.S
··· 797 797 #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP) 798 798 ldr r7, [r2, #TI_TASK] 799 799 ldr r8, =__stack_chk_guard 800 - ldr r7, [r7, #TSK_STACK_CANARY] 800 + .if (TSK_STACK_CANARY > IMM12_MASK) 801 + add r7, r7, #TSK_STACK_CANARY & ~IMM12_MASK 802 + .endif 803 + ldr r7, [r7, #TSK_STACK_CANARY & IMM12_MASK] 801 804 #endif 802 805 #ifdef CONFIG_CPU_USE_DOMAINS 803 806 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
+4 -6
arch/arm/mm/proc-macros.S
··· 25 25 ldr \rd, [\rn, #VMA_VM_FLAGS] 26 26 .endm 27 27 28 - .macro tsk_mm, rd, rn 29 - ldr \rd, [\rn, #TI_TASK] 30 - ldr \rd, [\rd, #TSK_ACTIVE_MM] 31 - .endm 32 - 33 28 /* 34 29 * act_mm - get current->active_mm 35 30 */ ··· 32 37 bic \rd, sp, #8128 33 38 bic \rd, \rd, #63 34 39 ldr \rd, [\rd, #TI_TASK] 35 - ldr \rd, [\rd, #TSK_ACTIVE_MM] 40 + .if (TSK_ACTIVE_MM > IMM12_MASK) 41 + add \rd, \rd, #TSK_ACTIVE_MM & ~IMM12_MASK 42 + .endif 43 + ldr \rd, [\rd, #TSK_ACTIVE_MM & IMM12_MASK] 36 44 .endm 37 45 38 46 /*