From patchwork Fri Jun 30 16:03:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 9819973 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 AEE3A60224 for ; Fri, 30 Jun 2017 16:05:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9EAE28338 for ; Fri, 30 Jun 2017 16:05:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C9E728699; Fri, 30 Jun 2017 16:05:09 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 ADC3228338 for ; Fri, 30 Jun 2017 16:05:08 +0000 (UTC) Received: (qmail 28081 invoked by uid 550); 30 Jun 2017 16:05: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 28046 invoked from network); 30 Jun 2017 16:05:04 -0000 From: Arnd Bergmann To: Kees Cook Cc: kernel-hardening@lists.openwall.com, Arnd Bergmann , Russell King , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Fri, 30 Jun 2017 18:03:59 +0200 Message-Id: <20170630160450.4093529-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:JDfu+TmyaAGQyqXf61UjVXmCXhUmwCMDWdglORA1cynLDqpBoxk kyUQ/kQmQAVHJENgOGyLVgfJ/BWHQAkpaFyZs7l4YakJ8NFtRH1uM5ZJugZIt7KE7MbOK3b ZU13KNbFw75oVMnbIoOXAsz2vwCh7PmVnqG3S3AdJ6RrWE3vWGQsKu90Gi2VXnZQct4B1YM PAQ9aSUXTLHRWCQwQT2NQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:O/8zRvQFBVg=:jc7MGFed5YhJyrif87qW1s sFcPmFHaW9H7bZhDIIzq0fNZoqJlSOJsGisVWKeh8D/3IC/rowu7klC+inTBTeiZPr2Ouofqn 7kBwnvs2dT5gHhUkdrQ016Z7muWLLmC4LvfI8r0lyGsEhcEG/vZVFNyQCqSHb+7YFoTKQ2v9N F2m2A2SlmOIXb7PaRczra/vqV91MOu97E/u1QNGf44UxO5NLl5zJMiJffovYFFwSO1pCirZ39 vMEP0cfXSkMt/bd3YNaWijGkBzB1M6193afnUw70yKN2ZTDwYiuGntE9C2jonjsSWim4zjKom hW+8DmzsJsZ6yTluC4k3qquNOlJrmwNU866k6o3WQFRG+2p8ZhSu7s4pBUapZTOu4CHqRB1Ai nZSjy+y4ypjKKiglX1hskHwurNTwBgp4+eN28sgw+Ek6NLoBBvchb+C9+nlyszkm+s7ZLoeF+ Ed8Hlrn0qed+D1TPVbG7sGqMi5kI7SEzxSlaN7a7n2f1riRdXHbLXbuxtLaIcr1G5k9K6tInP qz69mJGzFxmrBKe/jciwvS9PEyzumfzwCdF6OgwPCslLNC+0fRcRhzkf4xBhC5e7XG7QDUxug gd1JtiJbQSR3y4ZnIuN2MG1xE1ndlAqrmfAkUjFdNT/abNifBb7coyiqxDDzXE0bcV+CFeVap 25qSX6pLeVx8oAXow8k3lAbJ+jsl1IGnn6OCMROfXFYFzmOlWdrpnggeAj1ESYrCrMjg= Subject: [kernel-hardening] [PATCH v2] ARM: fix randomized task_struct X-Virus-Scanned: ClamAV using ClamSMTP With the new task struct randomization, we can run into a build failure for certain random seeds: 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 Fixes: c33d8b12fbbd ("task_struct: Allow randomized layout") Signed-off-by: Arnd Bergmann Reviewed-by: Kees Cook Tested-by: Kees Cook --- v2: define a more appropriate macro instead of PAGE_MASK, fix always-true comparison to test the right thing --- arch/arm/include/asm/assembler.h | 2 ++ arch/arm/kernel/entry-armv.S | 5 ++++- arch/arm/mm/proc-macros.S | 10 ++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h index 68b06f9c65de..ad301f107dd2 100644 --- a/arch/arm/include/asm/assembler.h +++ b/arch/arm/include/asm/assembler.h @@ -87,6 +87,8 @@ #define CALGN(code...) #endif +#define IMM12_MASK 0xfff + /* * Enable and disable interrupts */ diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 9f157e7c51e7..c731f0d2b2af 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -797,7 +797,10 @@ ENTRY(__switch_to) #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP) ldr r7, [r2, #TI_TASK] ldr r8, =__stack_chk_guard - ldr r7, [r7, #TSK_STACK_CANARY] + .if (TSK_STACK_CANARY > IMM12_MASK) + add r7, r7, #TSK_STACK_CANARY & ~IMM12_MASK + .endif + ldr r7, [r7, #TSK_STACK_CANARY & IMM12_MASK] #endif #ifdef CONFIG_CPU_USE_DOMAINS mcr p15, 0, r6, c3, c0, 0 @ Set domain register diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S index 0d40c285bd86..f944836da8a2 100644 --- a/arch/arm/mm/proc-macros.S +++ b/arch/arm/mm/proc-macros.S @@ -25,11 +25,6 @@ ldr \rd, [\rn, #VMA_VM_FLAGS] .endm - .macro tsk_mm, rd, rn - ldr \rd, [\rn, #TI_TASK] - ldr \rd, [\rd, #TSK_ACTIVE_MM] - .endm - /* * act_mm - get current->active_mm */ @@ -37,7 +32,10 @@ bic \rd, sp, #8128 bic \rd, \rd, #63 ldr \rd, [\rd, #TI_TASK] - ldr \rd, [\rd, #TSK_ACTIVE_MM] + .if (TSK_ACTIVE_MM > IMM12_MASK) + add \rd, \rd, #TSK_ACTIVE_MM & ~IMM12_MASK + .endif + ldr \rd, [\rd, #TSK_ACTIVE_MM & IMM12_MASK] .endm /*