From patchwork Mon Feb 27 20:43:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9594187 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 8FE2F60471 for ; Mon, 27 Feb 2017 20:44:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82A3D27F9F for ; Mon, 27 Feb 2017 20:44:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 777632832D; Mon, 27 Feb 2017 20:44:17 +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 AD60C282E8 for ; Mon, 27 Feb 2017 20:44:16 +0000 (UTC) Received: (qmail 7892 invoked by uid 550); 27 Feb 2017 20:43:56 -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 6100 invoked from network); 27 Feb 2017 20:43:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dDao1jbU2eFN2kTx9/My8+QJfwCyjt/kUDMBaf53WAg=; b=GAQUAWh17J/6dQdJMoIXAXVSjHNiDm5V20+uivhBkXYsRPiSdbbKrMntRuwVus24PX vmgCbOuF2RhnzcNUQPHRLG826OGt7HqmZ1Jm5RibVxMx/Hq54ouHVaa2KxHogNKxDtl1 59kpjoJqrxvjVMAySiWyKbAV3SY8bFLp52P9g= 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=dDao1jbU2eFN2kTx9/My8+QJfwCyjt/kUDMBaf53WAg=; b=QS//T+Cu/rsQJwNFaZwTA46CguDKLZOv7tfrftBizb75Kd9GK/w4UgXLPsg+PmQmIw NjoLpLEC77paZ4oRFZDkfLJq50k3jMTkBTsDmGka4IUlVG6CkumB090LhpysfkBVAUv5 RBhZn3BK/ojIK+SnpJavoCgsSj2NjE+zuNhr1LhVQ3EJiJZKdQMhdHA1yuXA9dvLAOcn VcYed3qQT/NcfACFyDw86AZlVFTWbhuGrzO8WQz3pFMwmvVa+HMq16kY6tU8CmZeQPw6 G55HcYKuKuEdsRGoxnKNAsbA2atTkorhKfVFu2G90RW/I/xoKV8JH5SC4wU8uG1ycW4E 8ZhQ== X-Gm-Message-State: AMke39kWvvqGkEVKgy+eTJAj/sbirbHGkM4zrt9Ey80/TrIETFFLJmF9FV0Mww94YgfzivSR X-Received: by 10.99.151.18 with SMTP id n18mr19977057pge.183.1488228213570; Mon, 27 Feb 2017 12:43:33 -0800 (PST) From: Kees Cook To: kernel-hardening@lists.openwall.com Cc: Kees Cook , Mark Rutland , Andy Lutomirski , Hoeun Ryu , PaX Team , Emese Revfy , Russell King , x86@kernel.org Date: Mon, 27 Feb 2017 12:43:03 -0800 Message-Id: <1488228186-110679-6-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488228186-110679-1-git-send-email-keescook@chromium.org> References: <1488228186-110679-1-git-send-email-keescook@chromium.org> Subject: [kernel-hardening] [RFC][PATCH 5/8] ARM: Implement __arch_rare_write_map/unmap() X-Virus-Scanned: ClamAV using ClamSMTP Based on grsecurity's ARM pax_{open,close}_kernel() implementation, this allows HAVE_ARCH_RARE_WRITE to work on ARM. Signed-off-by: Kees Cook --- arch/arm/Kconfig | 1 + arch/arm/include/asm/domain.h | 3 ++- arch/arm/include/asm/pgtable.h | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 186c4c214e0a..c3e1369e7429 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -39,6 +39,7 @@ config ARM select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU select HAVE_ARCH_MMAP_RND_BITS if MMU + select HAVE_ARCH_RARE_WRITE if MMU && !ARM_LPAE && !CPU_USE_DOMAINS select HAVE_ARCH_SECCOMP_FILTER if (AEABI && !OABI_COMPAT) select HAVE_ARCH_TRACEHOOK select HAVE_ARM_SMCCC if CPU_V7 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h index 99d9f630d6b6..6c72f533382c 100644 --- a/arch/arm/include/asm/domain.h +++ b/arch/arm/include/asm/domain.h @@ -53,6 +53,7 @@ #define DOMAIN_MANAGER 3 #else #define DOMAIN_MANAGER 1 +#define DOMAIN_RARE_WRITE 3 #endif #define domain_mask(dom) ((3) << (2 * (dom))) @@ -115,7 +116,7 @@ static inline void set_domain(unsigned val) } #endif -#ifdef CONFIG_CPU_USE_DOMAINS +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_HAVE_ARCH_RARE_WRITE) #define modify_domain(dom,type) \ do { \ unsigned int domain = get_domain(); \ diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index a8d656d9aec7..c9492f3e9581 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -56,6 +56,33 @@ extern void __pgd_error(const char *file, int line, pgd_t); #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd) #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd) +#ifdef CONFIG_HAVE_ARCH_RARE_WRITE +#include +#include + +static inline int test_domain(int domain, int domaintype) +{ + return (get_domain() & domain_val(domain, 3)) == + domain_val(domain, domaintype); +} + +static inline unsigned long __arch_rare_write_map(void) +{ + preempt_disable(); + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_RARE_WRITE)); + modify_domain(DOMAIN_KERNEL, DOMAIN_RARE_WRITE); + return 0; +} + +static inline unsigned long __arch_rare_write_unmap(void) +{ + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER)); + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER); + preempt_enable_no_resched(); + return 0; +} +#endif + /* * This is the lowest virtual address we can permit any user space * mapping to be mapped at. This is particularly important for