From patchwork Mon Aug 14 12:53:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9898797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6027A602BA for ; Mon, 14 Aug 2017 12:55:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54FA2285E3 for ; Mon, 14 Aug 2017 12:55:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4972D2860E; Mon, 14 Aug 2017 12:55:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id C533D285E3 for ; Mon, 14 Aug 2017 12:55:33 +0000 (UTC) Received: (qmail 21710 invoked by uid 550); 14 Aug 2017 12:55:06 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 19710 invoked from network); 14 Aug 2017 12:54:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=88tZ6egx/O6JGUgLOiZbqgolAmvZ/+EHRw6MBkyd2po=; b=SW5zse7hMOt4TxmdKN7GdZOOIaz/2fJM+1EWwVOYc19Qx9bLZVTWIFs2IcwExPBLnw hsqQOxi8/W21esWZgRBT/DGvzbVvml06UbltjANZN2mPU2iOjM9bEsRGOuTagwe4J0wM 8XgaTWn361I4ItQ1Q5ZwmM0HsqCaXOrAFCvao= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=88tZ6egx/O6JGUgLOiZbqgolAmvZ/+EHRw6MBkyd2po=; b=VSU2sy3wZ7avjgNnFoOdm8Pq4fcueEMnwUVxVFfGrEN9O8+Uq0wV5pvRB7Qr5+yyc3 iwtvPGsQ2LJ9WBFKuL1sLXbhbTbJ1DyHqEQBQQ41FdrKfOL8zu7w7+86VtQEgmJxlkoV DUUathbpnR/fqsFnr3dCsK0pnEYvkPAk8zsJ+rSlmAEWFtpWJ1MvjVz8lDwW0TSwgVrn hIvnFO9jWmJn78rzpxPNJMaC6gFh5ZSzS2uzj27LQPaw04fsDAfSK6LGSadI7iykJYv1 JdUVYxYCbn/tIrZPzbrUjZJMdzO3M1qb0nfjQ+UTniiCA9jNRbkBNdLBZivKr1nBF0pE WUMg== X-Gm-Message-State: AHYfb5iIZ7WRjOIUJXkhaMsjK1E/eUBM0bacgNJ350+WUd1fi/JHj9hq ni16fqn95T3VPRkroL1wlQ== X-Received: by 10.28.223.85 with SMTP id w82mr5006959wmg.110.1502715285587; Mon, 14 Aug 2017 05:54:45 -0700 (PDT) From: Ard Biesheuvel To: kernel-hardening@lists.openwall.com Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Arnd Bergmann , Nicolas Pitre , Russell King , Kees Cook , Thomas Garnier , Marc Zyngier , Mark Rutland , Tony Lindgren , Matt Fleming , Dave Martin Date: Mon, 14 Aug 2017 13:53:47 +0100 Message-Id: <20170814125411.22604-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170814125411.22604-1-ard.biesheuvel@linaro.org> References: <20170814125411.22604-1-ard.biesheuvel@linaro.org> Subject: [kernel-hardening] [PATCH 06/30] ARM: kernel: use relative references for UP/SMP alternatives X-Virus-Scanned: ClamAV using ClamSMTP To avoid absolute references that are subject to runtime relocation when running a kernel built with CONFIG_RELOCATABLE=y, use relative references in the smp.alt entries. Cc: Russell King Signed-off-by: Ard Biesheuvel --- arch/arm/include/asm/assembler.h | 4 ++-- arch/arm/include/asm/processor.h | 2 +- arch/arm/kernel/head.S | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index 516ebaf4ff38..3176bf7dcbd9 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -260,7 +260,7 @@ */ #define ALT_UP(instr...) \ .pushsection ".alt.smp.init", "a" ;\ - .long 9998b ;\ + .long 9998b - . ;\ 9997: instr ;\ .if . - 9997b == 2 ;\ nop ;\ @@ -272,7 +272,7 @@ #define ALT_UP_B(label) \ .equ up_b_offset, label - 9998b ;\ .pushsection ".alt.smp.init", "a" ;\ - .long 9998b ;\ + .long 9998b - . ;\ W(b) . + up_b_offset ;\ .popsection #else diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h index c3d5fc124a05..3667b395bb17 100644 --- a/arch/arm/include/asm/processor.h +++ b/arch/arm/include/asm/processor.h @@ -92,7 +92,7 @@ unsigned long get_wchan(struct task_struct *p); #define __ALT_SMP_ASM(smp, up) \ "9998: " smp "\n" \ " .pushsection \".alt.smp.init\", \"a\"\n" \ - " .long 9998b\n" \ + " .long 9998b - .\n" \ " " up "\n" \ " .popsection\n" #else diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S index 6e9df3663a57..ec22f42fd8bb 100644 --- a/arch/arm/kernel/head.S +++ b/arch/arm/kernel/head.S @@ -548,14 +548,15 @@ smp_on_up: __do_fixup_smp_on_up: cmp r4, r5 reths lr - ldmia r4!, {r0, r6} - ARM( str r6, [r0, r3] ) - THUMB( add r0, r0, r3 ) + ldmia r4, {r0, r6} + ARM( str r6, [r0, r4] ) + THUMB( add r0, r0, r4 ) + add r4, r4, #8 #ifdef __ARMEB__ THUMB( mov r6, r6, ror #16 ) @ Convert word order for big-endian. #endif THUMB( strh r6, [r0], #2 ) @ For Thumb-2, store as two halfwords - THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r3. + THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r0. THUMB( strh r6, [r0] ) b __do_fixup_smp_on_up ENDPROC(__do_fixup_smp_on_up) @@ -564,7 +565,6 @@ ENTRY(fixup_smp) stmfd sp!, {r4 - r6, lr} mov r4, r0 add r5, r0, r1 - mov r3, #0 bl __do_fixup_smp_on_up ldmfd sp!, {r4 - r6, pc} ENDPROC(fixup_smp)