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: 9819975 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 830E360224 for ; Fri, 30 Jun 2017 16:05:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BF1628338 for ; Fri, 30 Jun 2017 16:05:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E7C528699; Fri, 30 Jun 2017 16:05:38 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C0B628338 for ; Fri, 30 Jun 2017 16:05:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=ySEXwM8vZ+DTreoJlku2mzYotYaVVXTXKMmveX22Bec=; b=qkN tL/ibvOF0a9f4Ywx3zi7lJABQKedMavSDggxeU6vyZr7mKRZnCeWgTb+SiwiERL41SGekUxEptSEv tWLIxUl09dkINmdOGIsenqURpEALUbVf+sq5KdTKTJoXiIcPmUnl42Ou2GY0sDd9YocJlP1PNg/Ut bbyh53unNcRvarArUt/zPQiXzcGOJFZ3Q51l30FN9lNOhaU5F8mnoeR9QuZYE+QwAQ2zYBNC6Qlw7 OpABiVikkJBKisONyJASzNQwrxB9JV2e896FUL09hizYOTvC5nrGu9SQBGdBj+Kz8ub3XWcv5L0kP jv3bg6Ptmz8n2299xWsFNffzZap/OXQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dQyQI-0001p4-TN; Fri, 30 Jun 2017 16:05:34 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dQyQE-0001kX-Rl for linux-arm-kernel@lists.infradead.org; Fri, 30 Jun 2017 16:05:32 +0000 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.145]) with ESMTPA (Nemesis) id 0M4Hw3-1diMfg30zL-00rpU0; Fri, 30 Jun 2017 18:04:51 +0200 From: Arnd Bergmann To: Kees Cook Subject: [PATCH v2] ARM: fix randomized task_struct 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= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170630_090531_247234_A4E50AAD X-CRM114-Status: GOOD ( 10.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , kernel-hardening@lists.openwall.com, Will Deacon , linux-kernel@vger.kernel.org, Russell King , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 /*