From patchwork Fri Oct 24 09:57:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jungseung Lee X-Patchwork-Id: 5145311 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5FC72C11AC for ; Fri, 24 Oct 2014 10:00:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8418320268 for ; Fri, 24 Oct 2014 10:00:34 +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 B5FB120251 for ; Fri, 24 Oct 2014 10:00:33 +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 1Xhbdd-0006Hl-Si; Fri, 24 Oct 2014 09:58:29 +0000 Received: from mail-pa0-x232.google.com ([2607:f8b0:400e:c03::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XhbdS-00065Y-MF for linux-arm-kernel@lists.infradead.org; Fri, 24 Oct 2014 09:58:19 +0000 Received: by mail-pa0-f50.google.com with SMTP id eu11so855879pac.23 for ; Fri, 24 Oct 2014 02:57:57 -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=prCQJWrX94a+eHGVjmdTccTjvfXNPFKQU5GPdp6oCXU=; b=l1gLsEEazyxJxxFo3LDObXbnb3grUZ8oJ1hmFWg+mF4uB0ckucTaA4al4YY1r2RTX9 XmZmPxArLKg++n3ckL+0wXWwr6WB2Nm3KUSYGi6rVhQQfwSPKFVap2EYO4DiJDbIO9kV 9QSfvhbZQA6RD1GiizdOOt1kKL/BKf17KmXLuilEA2839yCp7Cd7EupspGbXiU4KGg39 kAv8CnoydabTDSsBfA1vs+tV3TWgMU2Vk2DD4Av7uR56WzMjewAm2+GS2ZHs6xZl8Fl6 OkiRyuV5n6mvt2gHzZiPfqL5URtbpHtnYM+ksBmsWMg+PkZW2Ywpv9BUwvC3gxNq+sRq zq/w== X-Received: by 10.70.26.35 with SMTP id i3mr1361387pdg.84.1414144677457; Fri, 24 Oct 2014 02:57:57 -0700 (PDT) Received: from localhost.localdomain ([165.132.120.48]) by mx.google.com with ESMTPSA id jy14sm3489661pbb.71.2014.10.24.02.57.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Oct 2014 02:57:56 -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 2/2] arm: Support for the PXN CPU feature on ARMv7. Date: Fri, 24 Oct 2014 18:57:35 +0900 Message-Id: <1414144655-25204-2-git-send-email-js07.lee@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1414144655-25204-1-git-send-email-js07.lee@gmail.com> References: <1414144655-25204-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_025818_814341_A08FA6A6 X-CRM114-Status: GOOD ( 13.94 ) 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 - PXN: Privileged execute-never(PXN) is a security feature. PXN bits determines whether the processor can execute software from the region. This is effective solution against ret2usr attack. This patch set PXN bit on user page table for preventing user code execution with privilege mode. 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..89a620f 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 (optional) */ #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 (optional) */ #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 */