From patchwork Sun Sep 3 12:07:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 9936169 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 44E0D6037D for ; Sun, 3 Sep 2017 12:13:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37219286B3 for ; Sun, 3 Sep 2017 12:13:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BAF7286B8; Sun, 3 Sep 2017 12:13:41 +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 243EA286B3 for ; Sun, 3 Sep 2017 12:13:39 +0000 (UTC) Received: (qmail 19760 invoked by uid 550); 3 Sep 2017 12:09:49 -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 19608 invoked from network); 3 Sep 2017 12:09:47 -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=Hm8prTksgb4hi6FQfX0jzzPYJDeptcTrjNQLZwywGa0=; b=ZlscELprgmdtOYx+KN1tYy17q2b6pmyh5RJoo/JlTjBCXEQDuJE3XMjVkMfqT8OqL1 vmfSzsgjobkmb/R8JN7H9pF1zCXE0+bqj9YrlU/oWQWTHq72Oqx0uNy/rxWK8jokt0cO CLwPATRkBF5XM8Cn/iDjcBq5e33bS6WWnFNeU= 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=Hm8prTksgb4hi6FQfX0jzzPYJDeptcTrjNQLZwywGa0=; b=LpDho+R5Ejme+BKh5nAmO/Stci6m1KiyPct540AqUaPjI5n+NY2XiqM+0Q7J/QnZLz N4Gm89ivB9hFHScHZ8XPsILTkdEVehQa4vndDuV0pHv36VnOxpW1CD5g6cubrigmbI1T Cbwp5YaMCNyguPCPID9mxxQpQz1m5njPHrDAWxHDcn8QAqzGFApP6VclkHYeLzQu7PHi 5cByTI/PMJPcYS4lYjb1XIF7M1mMWZyhtgbhCMH5eK+VCbCNVzJY1QpUX1aFYhIYQGrd XSUPwDFm9tUlGMBf1PmRJzjq7rcmNNMmZn4e/O4hz1/letWdNEK+iamsk8Th6+GrQu1a +aHQ== X-Gm-Message-State: AHPjjUiVmPFXNklib3UN8pV5EpYfH/HOrIOWTU4yeYamWwK42IdCmFSH JXODqzq3XxsImoYlEhfhtw== X-Google-Smtp-Source: ADKCNb6VBEvTPtcoJUFrFkvZSgBXBS38T0E0G/IahpRDckkqbPndC6P41zcJo6PqDYLJn950zlziIg== X-Received: by 10.223.195.140 with SMTP id p12mr4624416wrf.299.1504440575835; Sun, 03 Sep 2017 05:09:35 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com Cc: Ard Biesheuvel , Arnd Bergmann , Nicolas Pitre , Russell King , Kees Cook , Thomas Garnier , Marc Zyngier , Mark Rutland , Tony Lindgren , Matt Fleming , Dave Martin Date: Sun, 3 Sep 2017 13:07:53 +0100 Message-Id: <20170903120757.14968-26-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170903120757.14968-1-ard.biesheuvel@linaro.org> References: <20170903120757.14968-1-ard.biesheuvel@linaro.org> Subject: [kernel-hardening] [PATCH v2 25/29] ARM: decompressor: explicitly map decompressor binary cacheable X-Virus-Scanned: ClamAV using ClamSMTP When randomizing the kernel load address, there may be a large distance in memory between the decompressor binary and its payload and the destination area in memory. Ensure that the decompressor itself is mapped cacheable in this case, by tweaking the existing routine that takes care of this for XIP decompressors. Cc: Russell King Signed-off-by: Ard Biesheuvel Acked-by: Nicolas Pitre --- arch/arm/boot/compressed/head.S | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 5884e8151376..583cc6899d98 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -706,20 +706,24 @@ __setup_mmu: sub r3, r4, #16384 @ Page directory size teq r0, r2 bne 1b /* - * If ever we are running from Flash, then we surely want the cache - * to be enabled also for our execution instance... We map 2MB of it - * so there is no map overlap problem for up to 1 MB compressed kernel. - * If the execution is in RAM then we would only be duplicating the above. + * Make sure our entire executable image (including payload) is mapped + * cacheable, in case it is located outside the region we covered above. + * (This may be the case if running from flash or with randomization enabled) + * If the regions happen to overlap, we just duplicate some of the above. */ orr r1, r6, #0x04 @ ensure B is set for this orr r1, r1, #3 << 10 mov r2, pc + adr_l r9, _end mov r2, r2, lsr #20 + mov r9, r9, lsr #20 orr r1, r1, r2, lsl #20 add r0, r3, r2, lsl #2 - str r1, [r0], #4 + add r9, r3, r9, lsl #2 +0: str r1, [r0], #4 add r1, r1, #1048576 - str r1, [r0] + cmp r0, r9 + bls 0b mov pc, lr ENDPROC(__setup_mmu)