From nobody Fri Apr 3 00:52:09 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AB08C54EE9 for ; Mon, 19 Sep 2022 05:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229772AbiISFHz (ORCPT ); Mon, 19 Sep 2022 01:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbiISFHw (ORCPT ); Mon, 19 Sep 2022 01:07:52 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 555411ADAE for ; Sun, 18 Sep 2022 22:07:49 -0700 (PDT) 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 Content-Transfer-Encoding: quoted-printable 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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, uns= igned long addr) =20 pr_cont("\n"); } + +static inline bool is_permission_fault(unsigned int fsr) +{ + int fs =3D fsr_fs(fsr); +#ifdef CONFIG_ARM_LPAE + if ((fs & FS_PERM_NOLL_MASK) =3D=3D FS_PERM_NOLL) + return true; +#else + if (fs =3D=3D FS_L1_PERM || fs =3D=3D 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 =3D "write to read-only memory"; + else if (fsr & FSR_LNX_PF) + msg =3D "execute from non-executable memory"; + else + msg =3D "read from unreadable memory"; + } else if (addr < PAGE_SIZE) { msg =3D "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) =20 -static inline bool is_permission_fault(unsigned int fsr) -{ - int fs =3D fsr_fs(fsr); -#ifdef CONFIG_ARM_LPAE - if ((fs & FS_PERM_NOLL_MASK) =3D=3D FS_PERM_NOLL) - return true; -#else - if (fs =3D=3D FS_L1_PERM || fs =3D=3D 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 fla= gs, unsigned long vma_flags, struct pt_regs *regs) --=20 2.35.3