linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] powerpc/mm: make NULL pointer deferences explicit on bad page faults.
@ 2018-12-14 15:23 Christophe Leroy
  2018-12-17 12:28 ` Michael Ellerman
  2018-12-22  9:54 ` [v2] " Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe Leroy @ 2018-12-14 15:23 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: linux-kernel, linuxppc-dev

As several other arches including x86, this patch makes it explicit
that a bad page fault is a NULL pointer dereference when the fault
address is lower than PAGE_SIZE

In the mean time, this page makes all bad_page_fault() messages shorter
so that they remain on one single line. And it prefixes them by "BUG: "
so that they get easily greped.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 v2: Taking into account comments from Michael

 arch/powerpc/mm/fault.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 01b9bcc7fa85..3398291f4785 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -636,21 +636,24 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
 	switch (TRAP(regs)) {
 	case 0x300:
 	case 0x380:
-		printk(KERN_ALERT "Unable to handle kernel paging request for "
-			"data at address 0x%08lx\n", regs->dar);
+		if (regs->dar < PAGE_SIZE)
+			pr_alert("BUG: Kernel NULL pointer dereference");
+		else
+			pr_alert("BUG: Unable to handle kernel data access");
+		pr_cont(" at 0x%08lx\n", regs->dar);
 		break;
 	case 0x400:
 	case 0x480:
-		printk(KERN_ALERT "Unable to handle kernel paging request for "
-			"instruction fetch\n");
+		pr_alert("BUG: Unable to handle kernel instruction fetch%s",
+			 regs->nip < PAGE_SIZE ? " (NULL pointer ?)\n" : "\n");
 		break;
 	case 0x600:
-		printk(KERN_ALERT "Unable to handle kernel paging request for "
-			"unaligned access at address 0x%08lx\n", regs->dar);
+		pr_alert("BUG: Unable to handle kernel unaligned access at 0x%08lx\n",
+			 regs->dar);
 		break;
 	default:
-		printk(KERN_ALERT "Unable to handle kernel paging request for "
-			"unknown fault\n");
+		pr_alert("BUG: Unable to handle unknown paging fault at 0x%08lx\n",
+			 regs->dar);
 		break;
 	}
 	printk(KERN_ALERT "Faulting instruction address: 0x%08lx\n",
-- 
2.13.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] powerpc/mm: make NULL pointer deferences explicit on bad page faults.
  2018-12-14 15:23 [PATCH v2] powerpc/mm: make NULL pointer deferences explicit on bad page faults Christophe Leroy
@ 2018-12-17 12:28 ` Michael Ellerman
  2018-12-22  9:54 ` [v2] " Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2018-12-17 12:28 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linux-kernel, linuxppc-dev

Christophe Leroy <christophe.leroy@c-s.fr> writes:

> diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
> index 01b9bcc7fa85..3398291f4785 100644
> --- a/arch/powerpc/mm/fault.c
> +++ b/arch/powerpc/mm/fault.c
> @@ -636,21 +636,24 @@ void bad_page_fault(struct pt_regs *regs, unsigned long address, int sig)
>  	switch (TRAP(regs)) {
>  	case 0x300:
>  	case 0x380:
> -		printk(KERN_ALERT "Unable to handle kernel paging request for "
> -			"data at address 0x%08lx\n", regs->dar);
> +		if (regs->dar < PAGE_SIZE)
> +			pr_alert("BUG: Kernel NULL pointer dereference");
> +		else
> +			pr_alert("BUG: Unable to handle kernel data access");
> +		pr_cont(" at 0x%08lx\n", regs->dar);

It's best to avoid pr_cont() as it can lead to interleaving, so I
rewrote this as:

		pr_alert("BUG: %s at 0x%08lx\n",
			 regs->dar < PAGE_SIZE ? "Kernel NULL pointer dereference" :
			 "Unable to handle kernel data access", regs->dar);


>  		break;
>  	case 0x400:
>  	case 0x480:
> -		printk(KERN_ALERT "Unable to handle kernel paging request for "
> -			"instruction fetch\n");
> +		pr_alert("BUG: Unable to handle kernel instruction fetch%s",
> +			 regs->nip < PAGE_SIZE ? " (NULL pointer ?)\n" : "\n");
                                       I dropped the space here ^


cheers

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [v2] powerpc/mm: make NULL pointer deferences explicit on bad page faults.
  2018-12-14 15:23 [PATCH v2] powerpc/mm: make NULL pointer deferences explicit on bad page faults Christophe Leroy
  2018-12-17 12:28 ` Michael Ellerman
@ 2018-12-22  9:54 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2018-12-22  9:54 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel

On Fri, 2018-12-14 at 15:23:33 UTC, Christophe Leroy wrote:
> As several other arches including x86, this patch makes it explicit
> that a bad page fault is a NULL pointer dereference when the fault
> address is lower than PAGE_SIZE
> 
> In the mean time, this page makes all bad_page_fault() messages shorter
> so that they remain on one single line. And it prefixes them by "BUG: "
> so that they get easily greped.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/49a502ea23bf9dec47f8f3c3960909

cheers

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-22 17:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-14 15:23 [PATCH v2] powerpc/mm: make NULL pointer deferences explicit on bad page faults Christophe Leroy
2018-12-17 12:28 ` Michael Ellerman
2018-12-22  9:54 ` [v2] " Michael Ellerman

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).