* [PATCH] ARM: mm: Provide better fault message for permission fault
@ 2022-09-19 5:11 Kefeng Wang
2022-09-19 10:29 ` Kefeng Wang
0 siblings, 1 reply; 2+ messages in thread
From: Kefeng Wang @ 2022-09-19 5:11 UTC (permalink / raw)
To: Russell King; +Cc: linux-arm-kernel, linux-kernel, Kefeng Wang
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 <wangkefeng.wang@huawei.com>
---
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)
--
2.35.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ARM: mm: Provide better fault message for permission fault
2022-09-19 5:11 [PATCH] ARM: mm: Provide better fault message for permission fault Kefeng Wang
@ 2022-09-19 10:29 ` Kefeng Wang
0 siblings, 0 replies; 2+ messages in thread
From: Kefeng Wang @ 2022-09-19 10:29 UTC (permalink / raw)
To: Russell King; +Cc: linux-arm-kernel, linux-kernel
Sorry, is_permission_fault() could be used if CONFIG_MMU disabled, will
resend.
On 2022/9/19 13:11, Kefeng Wang wrote:
> 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 <wangkefeng.wang@huawei.com>
> ---
> 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)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-19 10:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-19 5:11 [PATCH] ARM: mm: Provide better fault message for permission fault Kefeng Wang
2022-09-19 10:29 ` Kefeng Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).