From patchwork Fri Oct 24 11:45:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jungseung Lee X-Patchwork-Id: 5146531 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2895E9F349 for ; Fri, 24 Oct 2014 11:49:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 51E7920256 for ; Fri, 24 Oct 2014 11:49:04 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7CC8E201F5 for ; Fri, 24 Oct 2014 11:49:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XhdKj-0002ot-Fk; Fri, 24 Oct 2014 11:47:05 +0000 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XhdKH-0002SX-JV for linux-arm-kernel@lists.infradead.org; Fri, 24 Oct 2014 11:46:38 +0000 Received: by mail-pa0-f46.google.com with SMTP id fa1so1009170pad.5 for ; Fri, 24 Oct 2014 04:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EGjTTcpl24E9F6kxQApjgqS+6E4fQ+qMCsuIIyKBt24=; b=kjsbfRF+yWTyRcbAIwvd+ogLDpgkf6nDkP+ak2LXbsKX3jmGZ4w+B1bJiuDMoeWQUO Nme8pctLTAGxs4QVFmJ1lWtA4CbbTU26BkpGAyiJweuVG9kiX7Hj+TCbo5qTyKl5NF9o yoRngZ4IEx5wxAH9rSYttOJovAxU/z8lHhNZYzTW3FLR48wkaMImozviOYUARsVMqjTn bpJ9Z1L1kzJs7dBHP/Y32Bbr2VJOYP0fEfBWgeD2xtcnwwx26LpkzRa7JBJuXdXKOCMy 6MbaabAYZn7xrsPiTPHylkwwZxMcszMAgx0miJ5MopHiVQwdi9CL1N/tdx5xwtvnbQZQ /w1Q== X-Received: by 10.70.127.199 with SMTP id ni7mr4106258pdb.39.1414151176767; Fri, 24 Oct 2014 04:46:16 -0700 (PDT) Received: from localhost.localdomain ([165.132.120.48]) by mx.google.com with ESMTPSA id qx4sm3751851pbc.14.2014.10.24.04.46.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Oct 2014 04:46:15 -0700 (PDT) From: Jungseung Lee To: Russell King , Catalin Marinas , Ard Biesheuvel , Santosh Shilimkar , Magnus Damm , Laura Abbott , linux-arm-kernel@lists.infradead.org, Will Deacon Subject: [PATCH RESEND 2/2] arm: Support for the PXN CPU feature on ARMv7. Date: Fri, 24 Oct 2014 20:45:55 +0900 Message-Id: <1414151155-26890-2-git-send-email-js07.lee@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1414151155-26890-1-git-send-email-js07.lee@gmail.com> References: <1414151155-26890-1-git-send-email-js07.lee@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141024_044637_723784_9BA68D28 X-CRM114-Status: GOOD ( 13.59 ) X-Spam-Score: -0.8 (/) Cc: Jungseung Lee X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch set PXN bit on user page table for preventing user code execution with privilege mode. This is effective solution against ret2usr attack. Signed-off-by: Jungseung Lee --- arch/arm/include/asm/pgalloc.h | 8 +++++++- arch/arm/include/asm/pgtable-2level-hwdef.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h index 78a7793..f4f4fd3 100644 --- a/arch/arm/include/asm/pgalloc.h +++ b/arch/arm/include/asm/pgalloc.h @@ -157,7 +157,13 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep) static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep) { - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE); +#ifdef CONFIG_CPU_V7 + if (elf_hwcap & HWCAP_PXN) + __pmd_populate(pmdp, page_to_phys(ptep), + _PAGE_USER_TABLE | PMD_PXNTABLE); + else +#endif + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE); } #define pmd_pgtable(pmd) pmd_page(pmd) diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h index 5cfba15..5e68278 100644 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h @@ -20,12 +20,14 @@ #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0) #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0) #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0) +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */ #define PMD_BIT4 (_AT(pmdval_t, 1) << 4) #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5) #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */ /* * - section */ +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */ #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2) #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3) #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */