From patchwork Fri Jun 1 08:09:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Yao X-Patchwork-Id: 10442665 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 EFCA8602BC for ; Fri, 1 Jun 2018 08:09:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E226D28D2E for ; Fri, 1 Jun 2018 08:09:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D410728FE0; Fri, 1 Jun 2018 08:09:25 +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=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 1110528D2E for ; Fri, 1 Jun 2018 08:09:24 +0000 (UTC) Received: (qmail 19627 invoked by uid 550); 1 Jun 2018 08:09:23 -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 19558 invoked from network); 1 Jun 2018 08:09:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Unvuq+6XOT4mr9xApK6X+O7VnjqOv6nO5OjVlp61ihI=; b=HlOy+C7JOFMfN9hHPeW2SC53okBVZ5TfJnLP9qAGV2AdpJV41IFEZw2ECVEjLzOGCq U/kCp04x8dZDuIRjuWPktOkTrpm+fmmASIJ/NqDw//8q8jI8TCxQbDOOMHP6doo/YG8J nN6+h+G0aT0ChcyWqOWaWcgYPxCmAGiLLfpQR44NigtxN4tx8RfXeG8nR80u0C75SJbN vToEP4gil/RHBZaKv8cWHqMYXPR45U8FiIw87qZGcyhvu4DznQhp0SSuypt2zvNiipkQ hUT7gh2Zy97mSq1bxaIfi0/XIj1BByjZmrWn6lzqgGUb1bqBLQNVCX4fPNpAD4waFdni mmzA== 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; bh=Unvuq+6XOT4mr9xApK6X+O7VnjqOv6nO5OjVlp61ihI=; b=jRUK+k+Z+hTUrXdpLTtcZqHYtJZBmGLw9cSYspPMyN0v6gLTn+PNUxW5xyUC4B1+16 7NOoM3Z9C/kvJo7Lk+A3V93NLA90Qlm/MeiRkyFQ2y7z5rOOuVJL30e57p/EIHuclGR1 rrveXQdCTw8VNMW1uV1mn2zscBnlnNPTyx6qmAWU/wn1mZ/hPBKKqJqvkMLtlMV9mtHz Fa3RVK+jEL4g3MeupGrKsBPcf4G9r3z157/+ltmlebnIouGVMiNyqKeJCznfsz/FqNW7 nS4WXpKwIqayrWGXcwajUmC4wun480cyf0lbOV93HbZDIGBCXydahR24AZFhOPn8Svvn xabw== X-Gm-Message-State: ALKqPwfVy8RINzOoL3gOlm4akoKstpUTZm5CI0rxNXTLulxPyjijkN5m 3fiVsa1DZ/5w+fXNkMaUrdQ= X-Google-Smtp-Source: ADUXVKIEDLKVaGPnXNt+ceO98EeWvINAmeEX1w1sM9fCrj9aRpL0MhrVdc/gV1UMQBsb7BolCHSEPA== X-Received: by 2002:a62:a6dd:: with SMTP id r90-v6mr4899858pfl.60.1527840550976; Fri, 01 Jun 2018 01:09:10 -0700 (PDT) From: Jun Yao To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, greg@kroah.com Subject: [PATCH 3/4] arm64/mm: make tramp_pg_dir and swapper_pg_dir adjacent Date: Fri, 1 Jun 2018 16:09:03 +0800 Message-Id: <20180601080903.11868-1-yaojun8558363@gmail.com> X-Mailer: git-send-email 2.17.0 X-Virus-Scanned: ClamAV using ClamSMTP To defense KSMA, we need to migrate tramp_pg_dir and swapper_pg_dir together. Make them adjacent to avoid modifying tramp_(un)map_kernel. Signed-off-by: Jun Yao --- arch/arm64/kernel/entry.S | 4 ++-- arch/arm64/kernel/vmlinux.lds.S | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index ec2ee720e33e..b35425feaf56 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -1004,7 +1004,7 @@ __ni_sys_trace: .macro tramp_map_kernel, tmp mrs \tmp, ttbr1_el1 - add \tmp, \tmp, #(PAGE_SIZE + RESERVED_TTBR0_SIZE) + add \tmp, \tmp, #(PAGE_SIZE) bic \tmp, \tmp, #USER_ASID_FLAG msr ttbr1_el1, \tmp #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 @@ -1023,7 +1023,7 @@ alternative_else_nop_endif .macro tramp_unmap_kernel, tmp mrs \tmp, ttbr1_el1 - sub \tmp, \tmp, #(PAGE_SIZE + RESERVED_TTBR0_SIZE) + sub \tmp, \tmp, #(PAGE_SIZE) orr \tmp, \tmp, #USER_ASID_FLAG msr ttbr1_el1, \tmp /* diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 605d1b60469c..3c72e6dec890 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -219,15 +219,16 @@ SECTIONS idmap_pg_dir = .; . += IDMAP_DIR_SIZE; +#ifdef CONFIG_ARM64_SW_TTBR0_PAN + reserved_ttbr0 = .; + . += RESERVED_TTBR0_SIZE; +#endif + #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 tramp_pg_dir = .; . += PAGE_SIZE; #endif -#ifdef CONFIG_ARM64_SW_TTBR0_PAN - reserved_ttbr0 = .; - . += RESERVED_TTBR0_SIZE; -#endif swapper_pg_dir = .; . += SWAPPER_DIR_SIZE; swapper_pg_end = .;