From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF50BC4708F for ; Wed, 2 Jun 2021 10:53:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3B6D613B8 for ; Wed, 2 Jun 2021 10:53:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230314AbhFBKyo (ORCPT ); Wed, 2 Jun 2021 06:54:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbhFBKyn (ORCPT ); Wed, 2 Jun 2021 06:54:43 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B674C061574 for ; Wed, 2 Jun 2021 03:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=iDBIURM5kgTiq51sI9dk7wb4eYi3ZtbjT3fobwqaHD8=; b=mEbMc+afiLjvbvFTvm5AJVuDQ m75xu+nPbDxutrccK4S2pxs/ZuN46QWGfbtyDx3EAmQJXIs9rZ1sXxFKkR9bOcAIeMJLT4zwa4YYQ 87xhr6kEYu9Sk+xpJvSOSu8s7gVGy6z+WHpS0iSxbkT+ZSAriegQPS483tdb/w+8r+gOUNCaV43QG QinDhaYp660YazDb6rcWQ/WPXE9dZZIXne2QpjMw7F/d1APUsUa4oDH2eO4vbQiy/BzmOXakKA6t5 DaQj6kjqM0iKqvvDupYSpBYXJZzP2TrCa8lZrM9maZSoJ3KxYHl7VcgXQ6T+6RVa4jLsMQKMAwB0x k0FyWYwFA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:44622) by pandora.armlinux.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1loOUa-00013y-NV; Wed, 02 Jun 2021 11:52:56 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1loOUa-00014f-17; Wed, 02 Jun 2021 11:52:56 +0100 Date: Wed, 2 Jun 2021 11:52:56 +0100 From: "Russell King (Oracle)" To: Kefeng Wang Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , linux-kernel@vger.kernel.org, Andrew Morton , Jungseung Lee Subject: Re: [PATCH v2 7/7] ARM: mm: Fix PXN process with LPAE feature Message-ID: <20210602105255.GK30436@shell.armlinux.org.uk> References: <20210602070246.83990-1-wangkefeng.wang@huawei.com> <20210602070246.83990-8-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210602070246.83990-8-wangkefeng.wang@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: Russell King (Oracle) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Wed, Jun 02, 2021 at 03:02:46PM +0800, Kefeng Wang wrote: > When user code execution with privilege mode, it will lead to > infinite loop in the page fault handler if ARM_LPAE enabled, > > The issue could be reproduced with > "echo EXEC_USERSPACE > /sys/kernel/debug/provoke-crash/DIRECT" > > Lets' fix it by adding the check in do_page_fault() and panic > when ARM_LPAE enabled. > > Fixes: 1d4d37159d01 ("ARM: 8235/1: Support for the PXN CPU feature on ARMv7") > Signed-off-by: Kefeng Wang > --- > arch/arm/mm/fault.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c > index 7cfa9a59d3ec..279bbeb33b48 100644 > --- a/arch/arm/mm/fault.c > +++ b/arch/arm/mm/fault.c > @@ -257,8 +257,14 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) > vm_flags = VM_WRITE; > } > > - if (fsr & FSR_LNX_PF) > + if (fsr & FSR_LNX_PF) { > vm_flags = VM_EXEC; > +#ifdef CONFIG_ARM_LPAE > + if (addr && addr < TASK_SIZE && !user_mode(regs)) > + die_kernel_fault("execution of user memory", > + addr, fsr, regs); > +#endif > + } Do we need to do this test here? Also, is this really LPAE specific? We have similar protection on 32-bit ARM using domains to disable access to userspace except when the user accessors are being used, so I would expect kernel-mode execution to also cause a fault there. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD7AEC47083 for ; Wed, 2 Jun 2021 10:55:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ACD29613D2 for ; Wed, 2 Jun 2021 10:55:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ACD29613D2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=U+0PVhXmIcLYKXfYbkCrxTCDmbILxiv41QwhAZbM9J0=; b=bekAty+KgKqmMh EJlZkMz+ZgYYBH2BgryKCXNlMYeGAMhYbTvjoNlUS34U2sgWxim80SY8LrAhA2ySFeaQET66d0qW6 35HSYFUpoCFAS5ZObpAYOTz6DUu1TrSA/NRwW5XFz1BfDmy9U5RQ9wShOvfAg03gyOmJys0UXklo/ lRipBWD6nPEvr7Wies0yBbCXafDe5akPMlO1ha0HTFXOgKRpQUIiDPLd2aKvGcr4Vzq430k/8LMCT Trl+tPvM1cmecCesIgqnEfLxLNg4+yy+57vABRVloB80IP/PfhyA52zbOub8kLF5l4XMMyzwwwNO+ Ffdu0oI3K+JH8J+6vapg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1loOVG-003Tuy-6k; Wed, 02 Jun 2021 10:53:38 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1loOUc-003Th9-T3 for linux-arm-kernel@lists.infradead.org; Wed, 02 Jun 2021 10:53:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=iDBIURM5kgTiq51sI9dk7wb4eYi3ZtbjT3fobwqaHD8=; b=mEbMc+afiLjvbvFTvm5AJVuDQ m75xu+nPbDxutrccK4S2pxs/ZuN46QWGfbtyDx3EAmQJXIs9rZ1sXxFKkR9bOcAIeMJLT4zwa4YYQ 87xhr6kEYu9Sk+xpJvSOSu8s7gVGy6z+WHpS0iSxbkT+ZSAriegQPS483tdb/w+8r+gOUNCaV43QG QinDhaYp660YazDb6rcWQ/WPXE9dZZIXne2QpjMw7F/d1APUsUa4oDH2eO4vbQiy/BzmOXakKA6t5 DaQj6kjqM0iKqvvDupYSpBYXJZzP2TrCa8lZrM9maZSoJ3KxYHl7VcgXQ6T+6RVa4jLsMQKMAwB0x k0FyWYwFA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:44622) by pandora.armlinux.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1loOUa-00013y-NV; Wed, 02 Jun 2021 11:52:56 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1loOUa-00014f-17; Wed, 02 Jun 2021 11:52:56 +0100 Date: Wed, 2 Jun 2021 11:52:56 +0100 From: "Russell King (Oracle)" To: Kefeng Wang Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , linux-kernel@vger.kernel.org, Andrew Morton , Jungseung Lee Subject: Re: [PATCH v2 7/7] ARM: mm: Fix PXN process with LPAE feature Message-ID: <20210602105255.GK30436@shell.armlinux.org.uk> References: <20210602070246.83990-1-wangkefeng.wang@huawei.com> <20210602070246.83990-8-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210602070246.83990-8-wangkefeng.wang@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210602_035258_985470_FE81577A X-CRM114-Status: GOOD ( 22.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, On Wed, Jun 02, 2021 at 03:02:46PM +0800, Kefeng Wang wrote: > When user code execution with privilege mode, it will lead to > infinite loop in the page fault handler if ARM_LPAE enabled, > > The issue could be reproduced with > "echo EXEC_USERSPACE > /sys/kernel/debug/provoke-crash/DIRECT" > > Lets' fix it by adding the check in do_page_fault() and panic > when ARM_LPAE enabled. > > Fixes: 1d4d37159d01 ("ARM: 8235/1: Support for the PXN CPU feature on ARMv7") > Signed-off-by: Kefeng Wang > --- > arch/arm/mm/fault.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c > index 7cfa9a59d3ec..279bbeb33b48 100644 > --- a/arch/arm/mm/fault.c > +++ b/arch/arm/mm/fault.c > @@ -257,8 +257,14 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) > vm_flags = VM_WRITE; > } > > - if (fsr & FSR_LNX_PF) > + if (fsr & FSR_LNX_PF) { > vm_flags = VM_EXEC; > +#ifdef CONFIG_ARM_LPAE > + if (addr && addr < TASK_SIZE && !user_mode(regs)) > + die_kernel_fault("execution of user memory", > + addr, fsr, regs); > +#endif > + } Do we need to do this test here? Also, is this really LPAE specific? We have similar protection on 32-bit ARM using domains to disable access to userspace except when the user accessors are being used, so I would expect kernel-mode execution to also cause a fault there. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel