From patchwork Mon Sep 19 05:11:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 12979684 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 5EEB8ECAAD3 for ; Mon, 19 Sep 2022 05:09:26 +0000 (UTC) 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:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=wr/FxhWP+VgmiHTI4POA54X1q8QVMOzhE0qZFvDebWE=; b=P5DGQrJG/pYg5f yNDykEk2irLCNmt0XtILmQs+i+MZWIHQT2cDCZlGPv1TKBWQSCXNS/U73pxvBbCG7tOSu/mqMHyyw UFKyA8bPuDIcGD9atJtRQa4Ck2SYsghO4a4Utnr8wh4nWOKMx03ZVGPfWknxjbalGleikf39KAUlr TB2OyyY0jb31OnIj7kx7wwyXUA2WG5fLJ7O6eVz/XPJycXULfk/lwBpHOwBys7AQgKrOSuDFHW05C eDeMGeRn4RkdbkAOc9mar+9WQF2BIy5HOoYu03AL/9qHInsK8KG1QJdnRC48CxBYcafABlmDC4+s1 qQ0obRQqn3IaiDpocoPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oa90u-007xJW-Si; Mon, 19 Sep 2022 05:08:12 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oa90q-007x14-Vd for linux-arm-kernel@lists.infradead.org; Mon, 19 Sep 2022 05:08:11 +0000 Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MWCHH4QbKzMn0h; Mon, 19 Sep 2022 13:03:07 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 19 Sep 2022 13:07:47 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 19 Sep 2022 13:07:47 +0800 From: Kefeng Wang To: Russell King CC: , , Kefeng Wang Subject: [PATCH] ARM: mm: Provide better fault message for permission fault Date: Mon, 19 Sep 2022 13:11:30 +0800 Message-ID: <20220919051130.1339-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220918_220809_206369_70FDE6AD X-CRM114-Status: GOOD ( 12.55 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If there is a permission fault in __do_kernel_fault(), we only print the generic "paging request" message which don't show read, write or execute information, let's provide better fault message for them. Signed-off-by: Kefeng Wang --- arch/arm/mm/fault.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 46cccd6bf705..d1b848f0f7ed 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -95,6 +95,19 @@ void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr) pr_cont("\n"); } + +static inline bool is_permission_fault(unsigned int fsr) +{ + int fs = fsr_fs(fsr); +#ifdef CONFIG_ARM_LPAE + if ((fs & FS_PERM_NOLL_MASK) == FS_PERM_NOLL) + return true; +#else + if (fs == FS_L1_PERM || fs == FS_L2_PERM) + return true; +#endif + return false; +} #else /* CONFIG_MMU */ void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr) { } @@ -137,7 +150,14 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, /* * No handler, we'll have to terminate things with extreme prejudice. */ - if (addr < PAGE_SIZE) { + if (is_permission_fault(fsr)) { + if (fsr & FSR_WRITE) + msg = "write to read-only memory"; + else if (fsr & FSR_LNX_PF) + msg = "execute from non-executable memory"; + else + msg = "read from unreadable memory"; + } else if (addr < PAGE_SIZE) { msg = "NULL pointer dereference"; } else { if (kfence_handle_page_fault(addr, is_write_fault(fsr), regs)) @@ -204,19 +224,6 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs) #define VM_FAULT_BADMAP ((__force vm_fault_t)0x010000) #define VM_FAULT_BADACCESS ((__force vm_fault_t)0x020000) -static inline bool is_permission_fault(unsigned int fsr) -{ - int fs = fsr_fs(fsr); -#ifdef CONFIG_ARM_LPAE - if ((fs & FS_PERM_NOLL_MASK) == FS_PERM_NOLL) - return true; -#else - if (fs == FS_L1_PERM || fs == FS_L2_PERM) - return true; -#endif - return false; -} - static vm_fault_t __kprobes __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int flags, unsigned long vma_flags, struct pt_regs *regs)